Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  Decision variable indexing by a Set of type Tuple

    Posted Wed November 25, 2020 11:53 AM
    Edited by System Admin Fri January 20, 2023 04:25 PM
    HELLO Every body

    i am a new in Cplex , so i want to know how to declare a subset included in a set . i have a S_i : the set of flight i's Feasible start time tuples. this solution gives by Sir Alex Fleischer , but i don't know how to use the second set S2 with the decision variable !!! that mean the index of that Set , i have a decision variable x (i)(c) (w)(t2) in which i , c , w , t2  the index of flights , carousels, workingstations , and the set S2 that  declared by Sir Alex ,so i declare the decision variable x like that : 'dvar boolean x[flights][carousels][workingstations][t2 in S2[i][w]]; but it show me an error "The Start Time [flights] [workingstations] type cannot be used with "in". 

    Second question  :how to declare it on the sum ??? i writed like this : sum( t2 in S2) x[i][c][w][t2]== 1; but also the same error
    Any help please 

    {string} flights={"A1","A2"};
    {string} workingstations={"W1","W2"};
    
    tuple tup {
    
    
    int sd ; //start time of bagage handling
      int sh ; // start time of storage depletion
    
    }
    {tup} ttt = {};
    tuple Starttime {
      int elt; //earlist_starttime
      int lst; //lastest_starttime
      int  ed; //end time of baggage handling
      tup tt;
      
      }
      
      tup myt1=<3,4>;
      tup myt2=<4,5>;
      
      
      
    Starttime S[flights]=[<1,2,3,myt1>,<1,2,9,myt2>];
    Starttime S2[flights][workingstations]=[[<1,2,3,myt1>,<1,2,9,myt2>],[<1,2,3,myt1>,<1,2,9,myt2>]];
    
    execute PREPROCESSING {
    //initialize tup
      var t1 = ttt.add(1,11);
      var t2 = ttt.add(2,22);
      
      writeln(ttt);
      writeln(S);
      writeln(S2);
      }
    //variables
    dvar int+ sd ;
    dvar int+ sh;
    
    subject to
    {
      
    }


    ------------------------------
    Siwar Moumni
    ------------------------------
    #DecisionOptimization


  • 2.  RE: Decision variable indexing by a Set of type Tuple

    Posted Thu November 26, 2020 03:21 AM
    Hi,

    as I wrote in stackoverflow

    all dimensions should be set in an array so

    {string} flights={"A1","A2"};
    {string} workingstations={"W1","W2"};
    
    tuple tup {
    
    
    int sd ; //start time of bagage handling
      int sh ; // start time of storage depletion
    
    }
    {tup} ttt = {};
    tuple Starttime {
      int elt; //earlist_starttime
      int lst; //lastest_starttime
      int  ed; //end time of baggage handling
      tup tt;
      
      }
      
      tup myt1=<3,4>;
      tup myt2=<4,5>;
      
      
      
    Starttime S[flights]=[<1,2,3,myt1>,<1,2,9,myt2>];
    Starttime S2[flights][workingstations]=[[<1,2,3,myt1>,<1,2,9,myt2>],[<1,2,3,myt1>,<1,2,9,myt2>]];
    
    execute PREPROCESSING {
    //initialize tup
      var t1 = ttt.add(1,11);
      var t2 = ttt.add(2,22);
      
      writeln(ttt);
      writeln(S);
      writeln(S2);
      }
    //variables
    dvar int+ sd ;
    dvar int+ sh;
    
    {Starttime} unionS2=union(i in flights,w in workingstations) {S2[i][w]};
    
    dvar boolean x[flights][workingstations][t2 in unionS2];
    
    subject to
    {
      forall(i in flights,w in workingstations) sum( t2 in unionS2) x[i][w][t2]== 1;
    }


    works fine


    regards



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



  • 3.  RE: Decision variable indexing by a Set of type Tuple

    Posted Thu November 26, 2020 07:19 AM
    Edited by System Admin Fri January 20, 2023 04:27 PM
    Thanks Dear Sir @ALEX FLEISCHER
    yes it works alone but when i tried it in my code  it gives me an error : Type int cannot be used for string.
    So when i changed the type of all  the Sets ( flights , working stations, carousels) from string to int , it works

    ------------------------------
    Siw
    ------------------------------



  • 4.  RE: Decision variable indexing by a Set of type Tuple

    Posted Fri November 27, 2020 08:31 AM
    In

    https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/

    I added a line for you

    array variable indexer size - 3 ways : union , tuple set, decision expression

    regards

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



  • 5.  RE: Decision variable indexing by a Set of type Tuple

    Posted Tue March 16, 2021 05:40 AM
    Edited by System Admin Fri January 20, 2023 04:49 PM
    Hello Dear Sir  @ALEX FLEISCHER

    what i noticed that the t2 here in the decision variable x is not an index , because you initialized it before as a variable in the execute preprocessing , and me i want to use an index referred to the subset of feasible start time , so if i change it with another like : [ ti in unionS2] it will be correct !!!
    dvar boolean x[flights][workingstations][t2 in unionS2];​
    execute PREPROCESSING {
    //initialize tup
      var t1 = ttt.add(1,11);
      var t2 = ttt.add(2,22);​


    ------------------------------
    Siwar
    ------------------------------