Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Flow Control: hard and soft solutions

    Posted 01/05/18 12:06 PM

    Originally posted by: AndyHam


    Dear IBM,

    I have a need of calling two CP models (slightly different) consecutively so that the part of CP1 solution can be used for CP2. In particular, some of CP1 interval variables must be copied to CP2 and other must be used as initial solutions. In the following illustration, I would like to force to copy CP1 itvJ2V to CP2 itvJ2V when a certain condition is met. If the condition is not met, the solution of CP1 itvJ2V should be used as an initial solution for a warmstart.

    ===========================

    var sol=new IloOplCPSolution();
    if(startOf(opl1.itvJ2V[j][v]) <=NewArrivalTime) {
        sol.setValue(opl1.itvJ2V[j][v],opl2.itvJ2V[j][v]); //hard constraint
        cp.setPoint(sol);  //any way to make the solution as hard constraint?

    }

    else  {
       sol.setValue(opl1.itvJ2V[j][v],opl2.itvJ2V[j][v]); //soft constraint for warm-start

       cp.setStartingPoint(sol);

    }

    ===========================
    Thanks,
    Andy


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: Flow Control: hard and soft solutions



  • 3.  Re: Flow Control: hard and soft solutions

    Posted 01/06/18 11:15 AM

    Originally posted by: AndyHam


    Thanks for the helpful tip.

    I tried to apply the lesson to constraints related to CP interval variables.

    However, I hit the road block. Please see the following code.

     

    //model file

    ctPost1: presenceOf(itvJ2V[j][v])) >=0;

    ctPost2: presenceOf(itvJ2V[j][v])) <=1;

    ctPost3: startOf(itvJ2V[j][v])) >=0;

    ctPost4: startOf(itvJ2V[j][v])) <=99999;


    //flow control file
    if(startOf(opl1.itvJ2V[j][v])) <=NewArrivalTime) {
    // to make the solution as hard constraint.
    // the presence status and start time of the selected jobs from CP1 must match to the ones at CP2.
           opl2.ctPost1.UB=1;   //
    how to specify this constraint is active for the job selected.
           opl2.ctPost2.UB=1;   //how to specify this constraint is active for the job selected.
           opl2.ctPost3.UB= startOf(opl1.itvJ2V[j][v]); //how to specify this constraint is active for the job selected.
           opl2.ctPost4.UB= startOf(opl1.itvJ2V[j][v]); //how to specify this constraint is active for the job selected.

    } else  {
          sol.setValue(opl1.itvJ2V[j][v],opl2.itvJ2V[j][v]); //soft constraint for warm-start
          cp.setStartingPoint(sol);

    }

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: Flow Control: hard and soft solutions

    Posted 01/06/18 05:36 PM

    Hi

    instead of

    ctPost1: presenceOf(itvJ2V[j][v])) >=0;

    you could write

    ctPost1a: V1==(presenceOf(itvJ2V[j][v])) >=0);

    ctPost1b: V1>=1;

    and then in scripting to disactivate you simply change ctPost1b bounds

    regards

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 5.  Re: Flow Control: hard and soft solutions

    Posted 01/08/18 03:56 AM

    Originally posted by: AndyHam


    Thanks for helping me out, but I think I was not clear about my concern.

    I made a short code for illustration purpose.

    In the flowControl, there are few issues:
    (1) the variables used in CP code are not accessible in the flowControl

         In the illustration, how to access Jobs and Trucks from the flowControl?

    (2) suppose we would like to inherit the interval values (itvJ2V) to the next CP run when a certain condition is met. The following code has syntax errors. How to make it work?   

          if(startOf(thisOplModel.itvJ2V[j][t])<=2)) sol.setValue(thisOplModel.itvJ2V[j][t],thisOplModel.itvJ2V[j][t]);

     

    using CP;

    range Trucks = 1..2;

    range Jobs = 1..10; 

    dvar interval itvJob[j in Jobs] size 1 ;

    dvar interval itvJ2T[j in Jobs][Trucks] optional;

    dvar sequence seqTrk[t in Trucks] 

      in   all(j in Jobs) itvJ2T[j][t];     

     

    minimize max(j in Jobs) endOf(itvJob[j]);    

    constraints {    

     

    forall(j in Jobs)

        alternative(itvJob[j], all(t in Trucks) itvJ2T[j][t]);

    forall(t in Trucks)

        noOverlap(seqTrk[t]);    

    }

     

    main {

    thisOplModel.generate();

       cp.solve(); 

       var sol=new IloOplCPSolution();

       for ( var j in Jobs)

          for (t in Trucks) 

              if(startOf(thisOplModel.itvJ2V[j][t])<=2)) sol.setValue(thisOplModel.itvJ2V[j][t],thisOplModel.itvJ2V[j][t]);

        cp.setStartingPoint(sol);

        thisOplModel.generate();

        cp.solve();

     }

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 6.  Re: Flow Control: hard and soft solutions

    Posted 01/08/18 06:16 AM

    Hi,

    I would rather write

     using CP;

    range Trucks = 1..2;

    range Jobs = 1..10;

    dvar interval itvJob[j in Jobs] size 1 ;

    dvar interval itvJ2T[j in Jobs][Trucks] optional;

    dvar sequence seqTrk[t in Trucks]

      in   all(j in Jobs) itvJ2T[j][t];     

     

    minimize max(j in Jobs) endOf(itvJob[j]);    

    constraints {    

     

    forall(j in Jobs)

        alternative(itvJob[j], all(t in Trucks) itvJ2T[j][t]);

    forall(t in Trucks)

        noOverlap(seqTrk[t]);    

    }

     

    main {

    thisOplModel.generate();

       cp.solve();

       var sol=new IloOplCPSolution();

       for ( var j in thisOplModel.Jobs)

          for (t in thisOplModel.Trucks)

              if((thisOplModel.itvJ2T[j][t].start)<=2) sol.setValue(thisOplModel.itvJ2T[j][t],thisOplModel.itvJ2T[j][t]);

        cp.setStartingPoint(sol);

        thisOplModel.generate();

        cp.solve();

     }

    regards


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 7.  Re: Flow Control: hard and soft solutions

    Posted 01/08/18 06:53 AM

    Originally posted by: AndyHam


    That makes sense.
    How I could not figure it out by myself ^^
    Thanks a lot!


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 8.  Re: Flow Control: hard and soft solutions

    Posted 01/08/18 07:06 AM

    You re welcome and congrats for http://ieeexplore.ieee.org/document/8010885/

    Constraint Programming Approach for Scheduling Jobs With Release Times, Non-Identical Sizes, and Incompatible Families on Parallel Batching Machines


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 9.  Re: Flow Control: hard and soft solutions

    Posted 01/08/18 05:27 PM

    Originally posted by: AndyHam


    Thanks for your note on my paper!
    With your help, I have figured out how to setup the warmstart between CP1 and CP2 for interval variables.


    Now, I still could not figure out how to setup the hard constraint between CP1 and CP2 for interval variable.

    I have two questions about the following code.
    1. The code generates an error, Scripting runtime error: cannot add properties to this value, "[a IloMap]".

            thisOplModel.ctPost1.UB =thisOplModel.itvJ2T[j][t].start;

            thisOplModel.ctPost2.UB= thisOplModel.itvJ2T[j][t].start;


    2. How to make this constraint is to be active only for the jobs selected?
    There is a if-condition in flowControl so it will list up UB only for j and t which meet the condition.
    But, I am not sure how to transfer this information from flowControl to model file. 

    (model)

    ctPost1: startOf(itvJ2T[j][t]) >=0;
    ctPost2: startOf(itvJ2T[j][t]) <=99999;


    (flowControl)

      if((thisOplModel.itvJ2T[j][t].start)>=2) 

            thisOplModel.ctPost1.UB =thisOplModel.itvJ2T[j][t].start;


    using CP;

    range Trucks = 1..2;
    range Jobs = 1..10;
    dvar interval itvJob[j in Jobs] size 1 ;
    dvar interval itvJ2T[j in Jobs][Trucks] optional;
    dvar sequence seqTrk[t in Trucks]
      in   all(j in Jobs) itvJ2T[j][t];     
     
    minimize max(j in Jobs) endOf(itvJob[j]);    
    constraints {    
    forall(j in Jobs)
        alternative(itvJob[j], all(t in Trucks) itvJ2T[j][t]);
    forall(t in Trucks)
        noOverlap(seqTrk[t]);    
    forall(j in Jobs,t in Trucks){
    ctPost1: startOf(itvJ2T[j][t]) >=0;
    ctPost2: startOf(itvJ2T[j][t]) <=99999;
    }
    }
     
    main {
    thisOplModel.generate();
    cp.solve();
    var sol=new IloOplCPSolution();
    for (var j in thisOplModel.Jobs)
    for (var t in thisOplModel.Trucks)
          if((thisOplModel.itvJ2T[j][t].start)>=2) {
             thisOplModel.ctPost1.UB =thisOplModel.itvJ2T[j][t].start;
             thisOplModel.ctPost2.UB= thisOplModel.itvJ2T[j][t].start;
         }       
    thisOplModel.generate();
    cp.solve();
     }

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 10.  Re: Flow Control: hard and soft solutions

    Posted 01/09/18 02:59 AM

    Hi,

    using CP;
    range Trucks = 1..2;
    range Jobs = 1..10;

    dvar int v1[j in Jobs][Trucks];
    dvar int v2[j in Jobs][Trucks];

    dvar interval itvJob[j in Jobs] size 1 ;
    dvar interval itvJ2T[j in Jobs][Trucks] optional;
    dvar sequence seqTrk[t in Trucks]
      in   all(j in Jobs) itvJ2T[j][t];     
     
    minimize max(j in Jobs) endOf(itvJob[j]);    
    constraints {    
    forall(j in Jobs)
        alternative(itvJob[j], all(t in Trucks) itvJ2T[j][t]);
    forall(t in Trucks)
        noOverlap(seqTrk[t]);    
    forall(j in Jobs,t in Trucks){
    ctPost1: v1[j][t] >=0;
    ctPost2: v2[j][t] <=99999;
    }

    forall(j in Jobs,t in Trucks){
    v1[j][t]==startOf(itvJ2T[j][t]);
    v2[j][t]==startOf(itvJ2T[j][t]);
    }

    }

    execute
    {
    writeln("obj=",cp.getObjValue());
    }
     
    main {
    thisOplModel.generate();
    cp.solve();
    thisOplModel.postProcess();

    var sol=new IloOplCPSolution();
    for (var j in thisOplModel.Jobs)
    for (var t in thisOplModel.Trucks)

          if((thisOplModel.itvJ2T[j][t].start)>=2) {
             thisOplModel.v1[j][t].UB =thisOplModel.itvJ2T[j][t].start;
             thisOplModel.v2[j][t].UB= thisOplModel.itvJ2T[j][t].start;
         }           
    //thisOplModel.generate();
    cp.solve();
    thisOplModel.postProcess();
     }

    works fine

    regards


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 11.  Re: Flow Control: hard and soft solutions

    Posted 01/09/18 04:07 PM

    Originally posted by: AndyHam


    I was able to remove few codes. And, this is the final version. It worked like a magic ^^

    startOf(itvJ2V[j][v]) ==v1[j][v];


    if((opl.itvJ2V[j][v].start)<=opl.newArrTime)  opl2.v1[j][v].UB = opl.itvJ2V[j][v].start;

    else        sol.setValue(opl2.itvJ2V[j][v],opl.itvJ2V[j][v]);    

     

    I sincerely appreciate all your help. I believe I have all pieces of puzzle.

    I am currently working on autonomous taxi scheduling problem. In particular, I am testing CP model for a dynamic job arrival. CP initially generates a full schedule for a give job. Then, during the day, new jobs arrive, which require a new schedule. We can solve a full model with new jobs, but it would be time-consuming. In order to reduce a run-time, I am using those hard & soft initial solutions: hard for the ones already executed and soft for the other not yet executed. Then, add new jobs into the job list and generate a new solution. At the end, I hope I can claim CP can be used for real-time tax scheduling purpose.

    As soon as we fix the cumul function that I reported, I will run a computational study. Thanks again for all your advice!

     


    #DecisionOptimization
    #OPLusingCPOptimizer