Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Search strategy by Index value.

    Posted 07/30/13 12:07 PM

    Originally posted by: EBKN_Eduardo_Aime


    Are there any way to use phases, in Opl Script,  to order all variables in a model by index value?
    First all varibles by index value 1, next all variables by index value 2, and so on.
    Thanks for your help


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: Search strategy by Index value.

    Posted 07/31/13 08:30 AM

    Originally posted by: Philippe_Refalo


    Using search phases, you can branch on variables following the index (i.e. the position) they have in a given array. For this purpose you need to use cp.factory.varIndex(dvar int[]).

    You can also use cp.factory.explicitVarEval(dvar int[], int[]) to define explicitely the evaluation of some variables. In your case, you can define the evaluation as the index value of the variables (I assume they are in several different arrays). Then choosing with cp.factory.selectSmallest will branch on the variables having the smallest index first.

    Regards

    Philippe


    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: Search strategy by Index value.

    Posted 07/31/13 08:44 PM

    Originally posted by: EBKN_Eduardo_Aime


    Philippe 

    Thank you for your advice

    I will thank you a lot if you tell me the sintax for the following case:

    Several (3 in this example) variables  with the following indexes (2 each)

    Var1[n][t]  ,   Var2[n][t] ,   Var3[k][t]

    n=1..3,    t = 1…4,    k = 1..2

    I need to order the variables on index t,  all varibles with t=1 first, next all variables with t=2, and so on:

     

    All t= 1

    Var1[1]][1], Var2[1][1] , Var3[1][1] ,

    Var1[2][1] , Var2[2][1] , Var3[2][1] ,

    Var1[3]][1], Var2[3][1] ,

    Next all t=2

    Var1[1]][2], Var2[1][2] , Var3[1][2] ,

    Var1[2][2] , Var2[2][2] , Var3[2][2] ,

    Var1[3]][2], Var2[3][2] ,

    And so on…

     

    Thank you in advance,

    Eduardo.


    #CPOptimizer
    #DecisionOptimization


  • 4.  Re: Search strategy by Index value.

    Posted 08/01/13 03:15 AM

    Originally posted by: Philippe_Refalo


    For using search phases, you need to pass flat arrays, so there are two possibilities:

    - either you create a flat array and a search phase for each group of variables t=1, t=2 and so on...

    - either you flatten all these variables into one array and use the explicitVarEval evaluator to give the evaluation 1 for variables in t = 1, 2 for variables in t = 2 and so on...

    Note that you can still use another criteria for selecting variables one grouped, for instance you can further filter variables with cp.factory.selectLargest(cp.factory.varImpact()) this branch first on the variables having the largest impact on search among those that have been selected at the previous stage using their index. 

    Regards 

    Philippe


    #CPOptimizer
    #DecisionOptimization


  • 5.  Re: Search strategy by Index value.

    Posted 08/01/13 12:30 PM

    Originally posted by: EBKN_Eduardo_Aime


     Philippe:

    Trying to flattening the bidimensional decision variables, the function "searchPhase" give me the following error: (using the example "car")
    Execution of "SearchPhases" failed: "C:...Application Data\IBM\ILOG\CPLEX_Studio125\workspace\car\car.mod", line 67: Wrong argument type. The first argument contains an unsupported element. Expected: "dvar", found "object".: null.

     I'm doing something wrong?

    /***************************************************/

    using CP;

     

    int nbCars= ...; // # of cars

    int nbOptions= ...;// # of options

    int nbSlots= ...;// # of slots

     

    range Cars= 1..nbCars;

    range Options= 1..nbOptions;

    range Slots= 1..nbSlots;

     

    int demand[Cars] = ...;

    int option[Options,Cars] = ...; 

    tuple Tcapacity{

    int l;

    int u;

    };

    Tcapacity capacity[Options] = ...;

    int optionDemand[i in Options] = sum(j in Cars) demand[j] * option[i,j];

     

    dvar int slot[Slots] in Cars;

    dvar int setup[Options,Slots] in 0..1;

     

    /* ::::::::::: Phase def for bi-dim dvars ::::::::::::::::::::*/

    execute SearchPhases{

    var vPhase= cp.factory;

    var elements= (nbOptions* nbSlots) - 1

     

    var phaseArray= new Array(elements);

    var j= 0;

    for(var iOpt= 1; iOpt==nbOptions; iOpt++)

    for(var iSlot= 1; iSlot==nbSlots; iSlot++)

    phaseArray[j]=setup[iOpt][iSlot]; j++;

    /* This approach give me the error: Wrong argument type. Expected "dvar", found "object", "null" */

    cp.setSearchPhases(vPhase.searchPhase(phaseArray));

    }

    /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

     

    subject to{

    // # of cars = demand

    forall(c in Cars)

    sum(s in Slots) (slot[s] == c) == demand[c];

     

    forall(o in Options, s in 1..(nbSlots- capacity[o].u+ 1) )

    sum(j in s..(s+ capacity[o].u- 1)) setup[o,j] <= capacity[o].l;

    forall(o in Options, s in Slots)

    setup[o,s] == option[o][slot[s]];

    forall(o in Options, i in 1..optionDemand[o])

    sum(s in 1.. (nbSlots- i* capacity[o].u)) setup[o,s] >=

    optionDemand[o] - i* capacity[o].l;

    };


    #CPOptimizer
    #DecisionOptimization


  • 6.  Re: Search strategy by Index value.

    Posted 08/02/13 03:52 AM

    Originally posted by: Philippe_Refalo


    There are several mistakes in the loops you wrote, the continuation test must be  iOpt <nbOptions and j++ is not inside the loop. If you rewrite it to:

      for(var iOpt = 1; iOpt <= nbOptions; iOpt++){
        for(var iSlot = 1; iSlot <= nbSlots; iSlot++){
          phaseArray[j]=setup[iOpt][iSlot]; 
          j++;
        }
      }          
     

    then you have you want.

    Please use displays (write, writeln) to check the structures that you compute in order to debug your code before posting.

    Regards

    Philippe

     


    #CPOptimizer
    #DecisionOptimization


  • 7.  Re: Search strategy by Index value.

    Posted 08/02/13 10:35 AM

    Originally posted by: EBKN_Eduardo_Aime


    Thanks Philippe,

    I corrected the mistakes and now it works fine


    #CPOptimizer
    #DecisionOptimization