Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Multi-criteria selection - search phases

    Posted 05/30/17 09:40 AM

    Originally posted by: AlCPLEX


    Hello,

    i am currently trying to tune my search phase.

    I have seen that there is a possibility of doing Multi-criteria selection but i do not really understand how to properly write it in OPL, and what it really does.

    Would you be kind enough to provide an example?

    In addition, im interested if there are other possibilities/ suggestions to tune the search by "complicating" the variable selectors/evaluators.

    Thank you,

    Sincerely,


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: Multi-criteria selection - search phases

    Posted 05/31/17 12:22 PM

    Hi,

    could the following example give you some idea ?

    using CP;

    int n=10;

    tuple t
    {
    int i;
    }

    {t} s={<i>  | i in 1..n};

    {t} s2={<3>,<4>};


    dvar int x[s];

    execute
    {
    var f = cp.factory;
    var phase1 = f.searchPhase(new Array(x[Opl.first(s2)],x[Opl.last(s2)]));
    cp.setSearchPhases(phase1);
    }

    maximize sum(i in s) x[i];
    subject to
    {
    forall(i in s)
     x[i]<=i.i;
     
    }

    regards


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: Multi-criteria selection - search phases

    Posted 06/01/17 04:14 AM

    Originally posted by: AlCPLEX


    Thank you for your answer.

    Nevertheless, I am not sure it really does what i want (i or maybe i did not understand it).

    On your example : it looks like it branches first on the element of S2 than the last element of S2 and then whatever seems the best.

    i would like to branch on a variable of S2 that meet some criteria, and if there are severeal variables that satisfy it, then use another criteria as differentiator.

     

    Here is a quick (and stupid)  example which has nothing to do with my problem but that might be used to illustrate :

     

    *****************************

    using CP;

    int    nTasks = 20;
    int    nPeople= 4;

    range  rTasks = 1..nTasks;
    range  rPeople = 1..nPeople;
    int    cost[i in rTasks] = i;

     

    dvar int  people[i in rPeople] in rTasks;
    dexpr int objective = sum(i in rPeople) cost[people[i]];

     

    execute{
        var f = cp.factory;

        // Variable selector : how to choose the people variable that has:
        //    - the biggest/specific value in its domain
        //    - if severeal variables have this value then take the one with the smallest domain
       
        //    var phase1 = f.searchPhase(???);
        //    cp.setSearchPhases(phase1);
    }

     

    maximize objective;

    subject to {

        allDifferent(people);
        forall (i in rPeople){
            cost[people[i]] <= maxl(3,4*i - 4);
        } 
    }

    *****************************

    Any help is welcomed.

    Thank you ,

    Sincerely


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: Multi-criteria selection - search phases

    Posted 06/01/17 04:49 AM

    Hi,

    - the biggest/specific value in its domain   ==> selectLargest(eval)
    - if several variables have this value then take the one with the smallest domain ==> cp.factory.domainMin()

    All choosers at https://www.ibm.com/support/knowledgecenter/SSSA5P_12.7.1/ilog.odms.ide.help/OPL_Studio/opllanguser/topics/opl_languser_script_in_cp_searchchoosers.html

    this is why I suggested

    Multiple search phases

    Explain how to pass several search phases to the engine.

    You can pass several search phases to an instance of the CP Optimizer engine. The order of the search phases in the array is significant. The search engine instantiates the variables phase by phase, starting with the first one. It is not necessary that the variables in the search phases cover all the variables of the problem. It can be assumed that a search phase containing all the problem variables is implicitly added to the search phases. For instance, in a model that has three arrays of variables x, y and z, the following search phases:

    
    
    execute {
       var f = cp.factory;
       cp.set
    Search
    
    Phases(f.
    search
    
    Phase(x), f.
    search
    
    Phase(y), f.
    search
    
    Phase(z));
    }
    

    mean that variables x will be instantiated before variables y; then, once x and y are instantiated, variables z will be instantiated. In some particularly well-designed models, passing such an order can have a dramatic impact on the solving time.

     

     

     

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 5.  Re: Multi-criteria selection - search phases

    Posted 06/01/17 04:59 AM

    Originally posted by: AlCPLEX


    I am probably not very clear in my explanations.

    In my my model i already do multiple search phases (like you propose), and im using different variables selector like the ones you mentioned.

     

    But i want to use multicriteria evaluators, like :

    let say i have

    dvar int x[i in 1..3]

    and that the available domains are : x1 : {3,4,5}, x2= {2,5,6}, x3 = {1,2}

     

    How do i specify :

    • take the variables with the biggest domains -> x[1] and x[2] here
    • If severeal possibilities then take the variable which has the smallest value in its domain -> x[2]

    Thank you,

    Sincerely

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 6.  Re: Multi-criteria selection - search phases

    Posted 06/01/17 05:54 AM

    Hi,

    of then I guess

    using CP;

    execute
    {
    cp.param.LogPeriod=1;
    cp.param.Workers=1;
    }

    dvar int x[i in 1..3];

    execute
    {
    var f = cp.factory;

       var selectVar = f.selectLargest(f.domainSize());
       var phase1=f.searchPhase(x,selectVar,f.selectRandomValue());


    var phase2 = f.searchPhase(x,f.selectSmallest(f.domainMin()),f.selectRandomValue());
    cp.setSearchPhases(phase1,phase2);
    }

    subject to
    {
    x[1] in {3,4,5};
    x[2] in {2,5,6};
    x[3] in {1,2};

     

    }

    is not what you need and then you could define your own evaluator

    https://www.ibm.com/support/knowledgecenter/SSSA5P_12.7.0/ilog.odms.cpo.help/CP_Optimizer/User_manual/topics/tune_order_eval.html

    regards


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 7.  Re: Multi-criteria selection - search phases

    Posted 06/01/17 07:17 AM

    Originally posted by: AlCPLEX


    Ok, i guess i will have to define my mown evaluator.

     

    As  i saw it was possible in the C++ API (see the link below), i hoped it was also possible in OPL.

    https://www.ibm.com/support/knowledgecenter/SSSA5P_12.7.0/ilog.odms.cpo.help/CP_Optimizer/User_manual/topics/tune_order_multi.html

     

    Ill look into defining my own evaluator. A stupid question : Is it possible to define an evaluator in C++ or java and then use it in OPL, or the entire model must be done in the corresponding language?

     

    Thank you,

    Sincerely


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 8.  Re: Multi-criteria selection - search phases

    Posted 06/09/17 04:19 AM

    Originally posted by: AlCPLEX


    Hello,

    I am trying to implement the above advices.

    Therefore i created a C++ project(quite new to it), which uses my .mod file (with "modelSource" function).

    Taking  integer decision variables are quite straightforward using :

    IloIntVar varXXX = opl.getElement('XXX").asIntVar();

    after that i add my only integer decision variable to an IloIntVarArray in order to use the search phases with :

    IloIntVarArray varArrayXXX;

    varArrayXXX.add(varXXX);

     

    Nevertheless arrays of decision variables seems not so straightforward.

    As no AsIntVarArray()  exist but only AsIntVarMap(), i am obliged to iterate over the  IntVarMap to assign an IntVarArray?

    Is that it (thats what i think i understood from other topics/example but as im new to it, so i am not really sure)?

    Thanks a lot,

    Sincerely,

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 9.  Re: Multi-criteria selection - search phases

    Posted 06/10/17 08:36 AM


  • 10.  Re: Multi-criteria selection - search phases

    Posted 06/13/17 10:50 AM

    Originally posted by: AlCPLEX


    Indeed it helped.

    I am now using those type of objects (IloIntVarMap, IloIntRange, IloIntMap, ...) to access my different decision variables.

    And after that creating my own variable choosers.

    So now everything works,

    Thank you everyone.


    #DecisionOptimization
    #OPLusingCPOptimizer