Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Iterative Relaxations without OPL Model Regeneration

  • 1.  Iterative Relaxations without OPL Model Regeneration

    Posted 11/17/16 11:46 PM

    Originally posted by: mathygirl


    I have an OPL main script that generates an OPL model and performs feasopt on that model. I'd like to iteratively modify which binary decision variable values are fixed to 1, calling feasopt on each iteration. Between each call of feasopt, I need to reset the previous iteration's decision variables back to the original bounds and then modify the bounds for another set of variables. I'd like to do this without regenerating the OPL model.

    I've isolated an example of what I am doing, but which is not working:

    myModel.mod:

    {string} mySet = {"dog", "cat", "pig", "raccoon", "iguana"};
    dvar boolean D[mySet];
    minimize 0;
    subject to {
      forall(o in mySet) fixToZero:
        D[o] == 0;
    }

    main {

      thisOplModel.generate();
      var source = new IloOplModelSource("myModel.mod");
      var def = new IloOplModelDefinition(source);
      var opl = new IloOplModel(def, cplex);
      opl.settings.relaxationLevel=1;
      opl.generate();

      for(var a in opl.mySet) { 
        opl.D[a].LB = 1; 
        var relaxIter = opl.relaxationIterator;
        for(var c in relaxIter) {
          var constr=c.ct;
          writeln("Constraint name is ", constr.name);
        } 
        opl.D[a].LB = 0;
      }
    }

    I get the following error message:

    *** ERROR[ENGINE_002] at 23:0 .\relaxationIterationExampleMain.mod: Exception from IBM ILOG CPLEX: CPLEX Error  1217: No
     solution exists.

    ~ Anna


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Iterative Relaxations without OPL Model Regeneration



  • 3.  Re: Iterative Relaxations without OPL Model Regeneration

    Posted 01/05/17 10:18 AM

    Originally posted by: mathygirl


    Yes, but notice I am not running the solve() method. I'm using the relaxation iterator.

    Could you try to reproduce the error?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Iterative Relaxations without OPL Model Regeneration

    Posted 01/05/17 11:06 AM

    Hi,

    {string} mySet = {"dog", "cat", "pig", "raccoon", "iguana"};
    dvar boolean D[mySet];
    minimize 0;
    subject to {
      forall(o in mySet) fixToZero:
        D[o] == 0;
    }

    main {

      thisOplModel.generate();
      var source = new IloOplModelSource("mathygirl.mod");
      var def = new IloOplModelDefinition(source);
     

      for(var a in thisOplModel.mySet) {
        var opl = new IloOplModel(def, cplex);
        opl.settings.relaxationLevel=1;
        opl.generate();
        
        opl.D[a].LB = 1;
        
        var relaxIter = opl.relaxationIterator;
        for(var c in relaxIter) {
          var constr=c.ct;
          writeln("Constraint name is ", constr.name);
        }
        opl.D[a].LB = 0;
      }
    }

    gives

    Constraint name is fixToZero["dog"]
    Constraint name is fixToZero["cat"]
    Constraint name is fixToZero["pig"]
    Constraint name is fixToZero["raccoon"]
    Constraint name is fixToZero["iguana"]

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Iterative Relaxations without OPL Model Regeneration

    Posted 01/05/17 12:07 PM

    Originally posted by: mathygirl


    Then the model is regenerated every time the for loop is run. I'm trying to avoid regeneration.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Iterative Relaxations without OPL Model Regeneration

    Posted 01/05/17 02:17 PM

    If you do not want any regeneration, then you should do incremental matrix changes:

    {string} mySet = {"dog", "cat", "pig", "raccoon", "iguana"};
    dvar boolean D[mySet];
    minimize 0;
    subject to {
      forall(o in mySet) fixToZero:
        D[o] == 0;
    }

    execute
    {
    for(var i in mySet) if (D[i]!=0)  writeln("FixToZero[",i,"] is relaxed");
    }

    main {

      thisOplModel.generate();
      var source = new IloOplModelSource("mathygirl.mod");
      var def = new IloOplModelDefinition(source);
      var opl = new IloOplModel(def, cplex);
        opl.settings.relaxationLevel=1;
        opl.generate();
        
      // Change obj so that the obj is minimize relaxation
     
      for(var a in thisOplModel.mySet) cplex.setObjCoef(opl.D[a], 1)  ;

      for(var a in thisOplModel.mySet) {
        
        
        opl.D[a].LB = 1;
        
        // relaxation
        
        for(b in opl.mySet)
        {
          opl.fixToZero[b].UB=1;
          opl.fixToZero[b].LB=0;  
        }
        
        cplex.solve();
        opl.postProcess();
        
        
    //    var relaxIter = opl.relaxationIterator;
    //    for(var c in relaxIter) {
    //      var constr=c.ct;
    //      writeln("Constraint name is ", constr.name);
    //    }
        opl.D[a].LB = 0;
      }
    }

    which gives

    FixToZero[dog] is relaxed
    FixToZero[cat] is relaxed
    FixToZero[pig] is relaxed
    FixToZero[raccoon] is relaxed
    FixToZero[iguana] is relaxed

    This is what I suggested in How to change the model without regeneration, incremental cplex matrix modification

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Iterative Relaxations without OPL Model Regeneration

    Posted 05/11/17 11:59 AM

    Originally posted by: BLAIS


    I have the same problem. The relaxationIterator crash with the status 1217 (which is the reason why we call the relaxation iterator). Did you found a solution to your problem?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Iterative Relaxations without OPL Model Regeneration

    Posted 05/11/17 02:47 PM

    Hi,

    do you confirm that you have labeled your constraints so that the relaxation could work ?

    Do yo get a relaxation if you solve the model in the IDE without the main block ?

    And do you confirm that you use 12.7.1 ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: Iterative Relaxations without OPL Model Regeneration

    Posted 05/11/17 04:13 PM

    Originally posted by: BLAIS


    My constraints have labels

    I can solve it in the IDE but all constraint can be relaxed in this setup. In the problem I try to relax, only attach constraint can be relax.

    I use 12.6.3.0.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: Iterative Relaxations without OPL Model Regeneration

    Posted 05/12/17 12:01 PM

    Originally posted by: BLAIS


    OK. I realize that I was changing cplex constraint UB and calling the relaxIterator for a second time on the same model. I understand that we need to regenerate the model for each relaxIterator call. Is it right?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: Iterative Relaxations without OPL Model Regeneration

    Posted 05/12/17 01:25 PM

    I think so. If you do not want to call generate many times, you may use the incremental changes but without relaxation.

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 12.  Re: Iterative Relaxations without OPL Model Regeneration

    Posted 05/15/17 10:05 AM

    Originally posted by: BLAIS


    Thank you for your answer.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer