Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Starting solution in OPL Script

    Posted 07/28/13 01:00 PM

    Originally posted by: EBKN_Eduardo_Aime


     Hello,

    Actually (v12.5.1),  can I set a starting solution for a CP model in OPL Script?

    In other words, can be made a CP version of the WarmStart.mod example?

    Thank you very much for your help


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: Starting solution in OPL Script

    Posted 07/29/13 04:20 AM

    Originally posted by: Philippe_Refalo


    With CP Optimizer providing a starting point will look like this:

      var sp = new IloOplCPSolution(); 
      // fill solution 
      cp.setStartingPoint(sp);
      cp.solve();  

    You do not need to provide a value for every variables, in this case the assignments will be used as an indication for finding a first feasible solution. 

    Regards

    Philippe


    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: Starting solution in OPL Script

    Posted 07/29/13 11:23 AM

    Originally posted by: EBKN_Eduardo_Aime


    Thanks a lot Philippe.

     

    I tried the following:

    The model is syntactically correct.

    Runs well the first solution, but in the second run indefinitely.

    I'm not sure how to do the step: "fill solution".

     

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

     * OPL 12.5.1.0 Model

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

    using CP;

     

    ranger = 1..10;

    dvar int+x[r];

    dvar int+y[r];

    // The following array of values (defined as data) will be used as

    // a starting solution to warm-start the CP search.

    int RestartValues[iin r] = (i==5)? 10 : 0;

     

    minimize

      sum(i in r ) x[i] + sum( j in r ) y[j];

    subject to{

      ctSum:   

        sum( i in r ) x[i] >= 10;

      forall( j in r )

        ctEqual:

          y[j] ==j;

    }

     

    main{

      thisOplModel.generate();

      var ThisModelDef = thisOplModel.modelDefinition;

      /* Default behaviour */

      writeln("Default Behaviour");

      var cp1 = new IloCP();

      var opl1 = new IloOplModel(ThisModelDef, cp1);

      opl1.generate();

      cp1.solve();    

      writeln(opl1.printSolution());  /* Solution OK */

     

     /* Setting initial solution  */

      writeln("Setting Initial Solution ");

      var cp2 = new IloCP();

      var opl2 = new IloOplModel(ThisModelDef, cp2);

      opl2.generate();

     

      var RestartValues = thisOplModel.RestartValues ;

      var x = thisOplModel.x;

      var cpSolution = new IloOplCPSolution();

      for(var i = 1; i=10; i++)  

          cpSolution.setValue(x[i], RestartValues[i]);  /* Is this the right form to assign values ?? */

      cp2.SetStartingPoint(cpSolution);

     

      cp2.solve();  /* non-stop running !! */

      writeln(opl2.printSolution());

     

      opl1.end();

      cp1.end();

      opl2.end();

      cp2.end();

    }

     

    //OUTPUT:

    //Default Behaviour

    //// solution with objective 65

    //x = [0 0 0 10 0 0 0 0 0 0];

    //y = [1 2 3 4 5 6 7 8 9 10];

    //

    //Setting Initial Solution


    #CPOptimizer
    #DecisionOptimization


  • 4.  Re: Starting solution in OPL Script

    Posted 07/30/13 06:05 AM

    Originally posted by: Philippe_Refalo


    There is no "non stop run" in CP Optimizer : the loop that populates the solution must contain i == 10 and not i = 0 and you need to use cp2.setStartingPoint(cpSolution); with a lower case s. 

    In this simple case, CP Optimizer finds a solution quickly by itself and does not make use of the starting point. This happens sometimes when the model is simple. 

    Philippe


    #CPOptimizer
    #DecisionOptimization


  • 5.  Re: Starting solution in OPL Script

    Posted 07/30/13 10:33 AM

    Originally posted by: EBKN_Eduardo_Aime


    You are right Philippe
    thank you very much

    Eduardo.


    #CPOptimizer
    #DecisionOptimization