Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  SolveAnyway in OPL

    Posted 01/04/17 12:15 PM

    Hi,

    within Decision Optimization Center  , solveAnyway  is a very powerful algorithm

    SolveAnyway is the default algorithm run by Decision Optimization Center when CPLEX® is the solving engine, and enables it to handle infeasible problems. The solution found by this algorithm is the optimal solution that maximizes the objective while minimizing the relaxation of constraints. To do this, SolveAnyway uses a CPLEX algorithm named feasopt.

    Some want to use that even without Decision Optimization Center so let me give an example:

    int prefsolveanyway1[1..1]=[0];
    int prefsolveanyway2[1..1]=[0];
    int prefsolveanyway3[1..1]=[0];


    int priority[1..3]=[1,2,3];


    dvar int x;
    dvar int y;
    dvar int z;

    subject to
    {
    0<=x<=20;
    0<=y<=20;
    0<=z<=20;

    forall(i in 1..1) ct1:y-x>=7;
    forall(i in 1..1) ct2:z-y>=9;
    forall(i in 1..1) ct3:z-x<=10;


    }

     

    main {

    function writeRelaxation(opl)
    {
        var iter = opl.relaxationIterator;  
       for(var c in iter)
       {
         var constraint=c.ct;
         writeln(constraint.name);
         writeln("LB             = ",c.LB);
         writeln("UB             = ",c.UB);
         writeln("relaxedLB      = ",c.relaxedLB);
         writeln("relaxedUB      = ",c.relaxedUB);
         
       }
    }

     

       thisOplModel.generate();
       var def = thisOplModel.modelDefinition;   
       // Default behavior
       writeln("Default Behavior");
       writeln();
       
       var cplex1 = new IloCplex();
       var opl1 = new IloOplModel(def, cplex1);
       opl1.settings.relaxationLevel=1;
       opl1.generate();
       writeln(opl1.printRelaxation());   
       writeln("cplex status = ",cplex1.getCplexStatus());  
       
       writeln("Solve Anyway");
          

     // Priority 1 : ct1
     // Priority 2 : ct2
     // Priority 3 : ct3
     
     
      var currentPriority = 1;
      var noSolution=1;
      while (noSolution==1)
      {
       writeln();
       var cplex2 = new IloCplex();
       var opl2 = new IloOplModel(def, cplex2);
       opl2.generate();  
     
         writeln("relaxing priority less than ",currentPriority)  ;
        
         if (opl2.priority[1]<=currentPriority) opl2.prefsolveanyway1[1]=1; else opl2.prefsolveanyway1[1]=0;
         if (opl2.priority[2]<=currentPriority) opl2.prefsolveanyway2[1]=1; else opl2.prefsolveanyway2[1]=0;
         if (opl2.priority[3]<=currentPriority) opl2.prefsolveanyway3[1]=1; else opl2.prefsolveanyway3[1]=0;
         
         opl2.relaxationIterator.attach(opl2.ct1, opl2.prefsolveanyway1);
            opl2.relaxationIterator.attach(opl2.ct2, opl2.prefsolveanyway2);
            opl2.relaxationIterator.attach(opl2.ct3, opl2.prefsolveanyway3);
     
            writeRelaxation(opl2);
           
           writeln("cplex status = ",cplex2.getCplexStatus());
           if (cplex2.getCplexStatus()==14)
           {
            noSolution=0;
            writeln("x,y,z = ",opl2.x," ",opl2.y," ",opl2.z);
        }       
           
           currentPriority++;
      }
              
       opl2.end();
       cplex2.end();
    }

    which gives

    Default Behavior

    ct2[1] at 20:1-30 C:\poc\solveanyway\solveanyway.mod
        relax [9,Infinity] to [3,Infinity] value is 3

    cplex status = 14
    Solve Anyway

    relaxing priority less than 1
    ct1[1]
    LB             = 7
    UB             = Infinity
    relaxedLB      = 1
    relaxedUB      = 1
    cplex status = 14
    x,y,z = 0 1 10

     

    This shows that with default relaxation ct2 is relaxed whereas with solveanyway where we say first relax ct1 then ct2 then ct3, ct1 is relaxed

    regards

     

    Alex Fleischer

    PS:

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

    Many examples from a very good book : https://www.linkedin.com/pulse/model-building-oplcplex-alex-fleischer/

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


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: SolveAnyway in OPL

    Posted 01/05/17 01:18 AM

    Originally posted by: ShaCplex


    Hi sir,

    what are these variables in this example?

     

    int prefsolveanyway1[1..1]=[0]; 
    int prefsolveanyway2[1..1]=[0];
    int prefsolveanyway3[1..1]=[0];

    whats the meaning if they are 0 and 1 ?
     

     

    Thank you,

    shahul


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: SolveAnyway in OPL

    Posted 01/05/17 03:08 AM

    Hi,

    0 means not allowed for relaxation

    1 means allowed for relaxation

    This will make sure relaxations are hierarchical. Which is not the case with feasopt alone.

    You want to first relax constraints with priority 1 and then constraints with priority 2 but NEVER constraints with priority 2 if relaxing constraints with priority 1 was enough.

    With feasopt alone you would use preferences http://www.ibm.com/support/knowledgecenter/SSSA5P_12.7.0/ilog.odms.cplex.help/CPLEX/UsrMan/topics/infeas_unbd/feasopt/04_prefs.html  but you would not have the hierarchical property you get with solveanyway

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: SolveAnyway in OPL

    Posted 05/11/17 04:18 PM

    Originally posted by: BLAIS


    Is this possible to recall the relaxation iterator without regenerating the problem?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: SolveAnyway in OPL



  • 6.  Re: SolveAnyway in OPL

    Posted 05/15/17 10:02 AM

    Originally posted by: BLAIS


    We can incrementally change a problem and solve again without regenerate. I think this work with the solve but not with the relaxationIterator. I'm I wrong?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: SolveAnyway in OPL

    Posted 05/15/17 10:05 AM