Decision Optimization

 View Only
  • 1.  Script to concatenate members into a set

    Posted Thu February 18, 2021 11:23 AM

    I would like to generate an output like this:
         {<"A" {1,2,3} 84>
          <"B" {4,5}, 117>}
    by using the following script.
    We can sum up values, but I don't know how to concatenate values. Can you please help me? Also, it will be very appreciated if I can hear any advice on overlap and non-overlap at the same sequence. Thanks,


    tuple t_job {
    string grp;
    int id;
    int sz;
    };
    {t_job} Jobs = {
    <"A", 1, 60>,
    <"A", 2, 10>,
    <"A", 3, 14>,
    <"B", 4, 39>,
    <"B", 5, 78>
    };

    tuple t_batch {
    string grp;
    // {int} id_list;
    int sz;
    }; {t_batch} batch =
    { <j.grp, sum(j2 in Jobs: j2.grp==j.grp) j2.sz >| j in Jobs};
    execute {
    writeln(batch);
    }



    ------------------------------
    Andy Ham
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Script to concatenate members into a set
    Best Answer

    Posted Thu February 18, 2021 02:06 PM
    Hi

    tuple t_job {
    string grp;
    int id;
    int sz;
    };
    {t_job} Jobs = {
    <"A", 1, 60>,
    <"A", 2, 10>,
    <"A", 3, 14>,
    <"B", 4, 39>,
    <"B", 5, 78>
    };
    
    {string} grps={i.grp | i in Jobs};
    {int} idsPerGrp[g in grps]={i.id| i in Jobs:i.grp==g};
    
    tuple t_batch {
    string grp;
    {int} id_list;
    int sz;
    }; 
    
    {t_batch} batch =
    { <j.grp, idsPerGrp[j.grp],sum(j2 in Jobs: j2.grp==j.grp) j2.sz >| j in Jobs};
    
    execute {
    writeln(batch);
    }​


    gives

    {<"A" {1 2 3} 84> <"B" {4 5} 117>}

    regards

    PS

    Many how to with OPL in https://www.linkedin.com/pulse/how-opl-alex-fleischer/



    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------



  • 3.  RE: Script to concatenate members into a set

    Posted Tue March 23, 2021 10:50 AM
    Edited by System Fri January 20, 2023 04:35 PM
    Thanks for this Great Best Ten Rackets. I was confused but now I understand it properly. Really Thankful.

    ------------------------------
    Lisa Martin
    ------------------------------



  • 4.  RE: Script to concatenate members into a set

    Posted Tue March 23, 2021 10:50 AM
    can you guide me little bit more.. ?? i need more info.. :(

    ------------------------------
    Lisa Martin
    ------------------------------



  • 5.  RE: Script to concatenate members into a set

    Posted Tue March 23, 2021 10:59 AM
    Hi,

    about scripting I started https://www.linkedin.com/pulse/javascript-within-opl-cplex-alex-fleischer/

    Do not hesitate to start new threads in this community for new questions

    regards

    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------