Decision Optimization

Decision Optimization

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

 View Only
  • 1.  diffn_column Global Constraint

    Posted Mon May 31, 2021 10:13 AM
    Hi,

    I am interested in modelling a 2D packing problem with 2 staged cuts via CP Optimizer. As per the gccat catalogue, the problem can be efficiently represented by the global constraint "diffn_column" [1]. Knowing that "diffn" is essentially the "no_overlap" global constraint in CP Optimizer, I was wondering if there exists a native implementation of the "diffn_column" global constraint and if not, what would be the best way to implement it in terms of performance and scalability. 

    [1] https://web.imt-atlantique.fr/x-info/sdemasse/gccatold/pdf/diffn_column.pdf

    Best,
    Louis

    ------------------------------
    Louis Luo
    ------------------------------

    #DecisionOptimization


  • 2.  RE: diffn_column Global Constraint

    Posted Tue June 01, 2021 11:21 AM

    Hi Louis,

    The diffn column constraints can be implemented in CP Optimizer by combining resource constraints and state functions.
    Assume you have n task modelled by n interval variables. The resource constraint is expressed with a cumul expression (sum of pulse expressions over the interval variables) that must be less or equal to the capacity of the resource. To ensure that interval variables that overlaps have the same start and end, one use a single state function (see here) and an "AlwaysEqual" constraint (see here) for each interval variable.

    Here is an example in C++ to see the details. Note the 2 IloTrue arguments passed to the IloAlwaysEqual(env, f, iv[i], 0, IloTrue, IloTrue) function to ensure that start and end must be equal. The state function is arbitrarily set to 0. You can have different values if need to specify that some types of interval variables cannot overlap other types of interval variable. This is quite powerful.

    Regards,

    Philippe


    #include <ilcp/cp.h>
    
    ILOSTLBEGIN
    
    int main() {
      IloEnv env;
    
      IloModel model(env);
    
      IloIntervalVarArray iv(env);
      IloIntArray cons(env);
    
      iv.add(IloIntervalVar(env, 5, "x")); cons.add(2);
      iv.add(IloIntervalVar(env, 5, "y")); cons.add(2);
      iv.add(IloIntervalVar(env, 3, "z")); cons.add(1);
      iv.add(IloIntervalVar(env, 1, "u")); cons.add(1);
    
      IloStateFunction f(env);
    
      // Resource constraint 
      IloCumulFunctionExpr r(env);
      for (IlcInt i = 0; i < iv.getSize(); i++) {
        r += IloPulse(iv[i], cons[i]);
      }
      model.add(r <= 4);
    
      IloIntExprArray ends(env);
      for (IloInt i = 0; i < iv.getSize(); i++) {
        ends.add(IloEndOf(iv[i]));
        model.add(IloAlwaysEqual(env, f, iv[i], 0, IloTrue, IloTrue));
      }
    
      // Minimize makespan 
      model.add(IloMinimize(env, IloMax(ends)));
    
      IloCP cp(model);
    
      cp.solve();
    
      for (IloInt i = 0; i < iv.getSize(); i++) {
        cout << cp.domain(iv[i]) << endl;
      }
    
      return 0;
    }


    ------------------------------
    Philippe Refalo
    IBM ILOG CP Optimizer
    ------------------------------



  • 3.  RE: diffn_column Global Constraint

    Posted Tue June 01, 2021 06:15 PM
    Hi Philippe,

    Perfect! Thanks a bunch, especially for the example!

    Best,
    Louis

    ------------------------------
    Louis Luo
    ------------------------------