Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  forAll CP Constraint

    Posted 02/05/16 03:20 AM

    Originally posted by: Shadi


    hello,

    i want TripClass of my trips to be either ALL  {0,1} either ALL {0,2}...

     

    the following constraint give me solution with  TripClass of All Trips to be {0,1}  

    forall (i in tripRng) TripClass[tripSeq[i]] in {0,1} ;

     

     

    So i tried the following:

    1. forall (i in tripRng) TripClass[tripSeq[i]] in {0,1}  || forall (i in tripRng) TripClass[tripSeq[i]] in {0,2} ;
    2. forall (i in tripRng) TripClass[tripSeq[i]] in {0,1}  || TripClass[tripSeq[i]] in {0,2} ;

    but it donesnt work.

     

    thanks in advanced

    Shadi

     

     


    #ConstraintProgramming-General
    #DecisionOptimization


  • 2.  Re: forAll CP Constraint

    Posted 02/05/16 08:24 AM

    Originally posted by: rdumeur


    Dear Shadi,

    I suggest you try to count number of time the constraint tripClass[tripSeq[i]] < 2 is true.

    using CP;
    range ClassRange = 1..10;
    dvar int tripClass[ClassRange] in 0..2;
    range TripRange = 1..4;
    dvar int tripSeq[TripRange] in ClassRange;
    dvar int allIn01;
    
    subject to {
      allIn01 == sum(t in TripRange) (tripClass[tripSeq[t]] < 2); // test in 0..1
      allIn01 in {0,card(TripRange)};
    }
    

    This is sufficient if the range of tripClass is 0..2. I hope this helps,

    Cheers,

     

    Edit: forall is not a constraint, it is an OPL syntactic forms that allows to produce multiple constraints.

     


    #ConstraintProgramming-General
    #DecisionOptimization


  • 3.  Re: forAll CP Constraint

    Posted 02/05/16 09:26 AM

    Originally posted by: Shadi


    The tripClass[] is already known, is not dvar...
    ​ to ake it more easier, lets say that i have 3 kind of trips,
    ​city (1)
    ​interCity(2)
    undefined trip (0)

    ​TripClass[2]=1 means that trip 2 is city trip. and i know before create the model, i mean is not dvar variable.... i want each duty to be all (city & undefined) OR (interCity & undefined)


    #ConstraintProgramming-General
    #DecisionOptimization


  • 4.  Re: forAll CP Constraint

    Posted 02/05/16 09:58 AM

    Originally posted by: rdumeur


    Dear Shadi,

    If you want to be sure that all variables in tripClass are either in {0,1} or in {0,2}

    You can write:

    using CP;
    int nClasses = 10;
    range ClassRange = 1..nClasses;
    dvar int tripClass[ClassRange] in 0..2;
    dvar int allIn01;
    dvar int allIn02;
    int tripSeq[ClassRange] = [1,10,2,9,3,8,4,7,5,6];
    
    subject to {
      allIn01 == sum(c in ClassRange) (tripClass[tripSeq[c]] in {0,1});
      allIn02 == sum(c in ClassRange) (tripClass[tripSeq[c]] in {0,2});
      allIn01 == nClasses|| allIn02 == nClasses;
    }
    

    I hope this helps.

     


    #ConstraintProgramming-General
    #DecisionOptimization