Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  weak constraints

    Posted 10/03/16 09:11 AM

    Originally posted by: Treee


    hi,

    is it possible to declare a constraint to be a weak constraint? 

    For example i have to constraints "a" and "b". "b" is a hard constraint, which has to be considered,  and "a" a weak constraint. Can i say, that there is a penatly of for example 5 each time this weak constraint can not be considered?

    I googled this problem and searched in this forum, but i could not find anything useful.

    kind regards 


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: weak constraints

    Posted 10/03/16 01:09 PM

    Originally posted by: GGR


    Hi

     

    In IBM Ilog CP Optimizer you have the notion of meta constraint or constraint on constraint. That is constraint are basically boolean variable that can be used as a [0,1] range in a numerical expression.

     

    For example

     

    in Integer CP

    dvar int x;

    /* The other variables */

    minimize (x < 1);

    subject to {

     /* the constraints */

    };

     

    In this example the objective is 1 in a solution for which x is fixed t0 0 and 0 in a solution for which x is fixed to 1.

    By default all constraint support this mechanism in Ilog CP Optimizer. the documentation informs about each constraint in the language that can not be used in meta-constraints.

     

    Hope that helps

     

     

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: weak constraints

    Posted 10/05/16 03:01 PM

    Originally posted by: Treee


    hmm i dont know if i get you right.... Let me show you what i mean ( with the warehouse example):

     


    minimize
      sum( w in Warehouses ) 
        Fixed * Open[w] +
      sum( w in Warehouses , s in Stores ) 
        SupplyCost[s][w] * Supply[s][w];
        

    subject to{


      forall( s in Stores )
        ctEachStoreHasOneWarehouse:
          sum( w in  Warehouses ) 
            Supply[s][w] == 1;


      forall( w in Warehouses, s in Stores )

        ctUseOpenWarehouses:
          Supply[s][w] <= Open[w];

     

    Is there a way to weaken the second constraint? So it has not to be fulfilled. And if it is not fulfilled, give a penalty of 5.

     

    kind regards


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: weak constraints

    Posted 10/06/16 02:50 AM

    Originally posted by: Philippe_Refalo


    A way to do this is to introduce a binary variable (x in [0, 1]) that relaxes the constraint. This constraint


     Supply[s][w] <= Open[w];


    becomes then


     Supply[s][w] <= Open[w] + largeValue * x;


    where largeValue is sufficiently large so that when x == 1, the constraint is relaxed. This value can also be made sufficiently small so that we do not go to far in the relaxation. Then the objective function will have 5*x as additional term.


    The more general way to go, as GGR suggested, is to relax the constraint by adding

     

    x == (Supply[s][w] <= Open[w])

     

    with the same change in the objective to introduce x. Supply[s][w] <= Open[w] is often named a constraint as expression and x == (Supply[s][w] <= Open[w]) is a meta-constraint, i.e. a constraint over other constraints. However some constraints cannot appear as expressions, mostly global ones but any arithmetical or logical constraints can. 

     

    Regards,

    Philippe


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 5.  Re: weak constraints

    Posted 10/06/16 10:06 AM

    Originally posted by: GGR


    Hi

    Following the remark of Philippe, your model becomes:

     

    minimize
      sum( w in Warehouses ) 
        Fixed * Open[w] +
      sum( w in Warehouses , s in Stores ) 
        SupplyCost[s][w] * Supply[s][w] + 5*(Supply[s][w] > Open[w]);
        

    subject to{


      forall( s in Stores )
        ctEachStoreHasOneWarehouse:
          sum( w in  Warehouses ) 
            Supply[s][w] == 1;

    }

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 6.  Re: weak constraints

    Posted 10/09/16 11:32 AM

    Originally posted by: Treee


    ok thanks!

    But how do i write such a binary variable? I mean, i just need the relaxion when i get conflicts. So when there are no conflicts, i dont need the relaxion and x can be 0.

     

    I tried it with :

    dvar int+ weakConstraint in 0..1;

    execute {
            if (cplex.getCplexStatus() ==1){
            weakConstraint =0;
            writeln("no relaxion");}
            else {
            weakConstraint=1;        
            writeln("relaxion");
            }
    }

    But this does not work for obvious reasins, but i do not know how to make it work.

     

    I hope you can help me,

     

    kind regards


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 7.  Re: weak constraints

    Posted 10/09/16 03:45 PM

    Originally posted by: Petr Vilím


    Hello,

    the 'weakConstraint" variable (or 'x' as it was called before) is a decision variable. Therefore CP Optimizer must assign it some value (0 or 1). In other words, in every solution this variable has a value. And you can ask for this value in exactly the same way as you can query other variables.

    The whole trick is that the variable appears in the objective expression (the minimize part). As solutions are getting better and better during the search you will probably get more and more times zero assigned to the variable because it is one of the way how to improve the solution.

    Petr


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 8.  Re: weak constraints

    Posted 10/10/16 02:42 PM

    Originally posted by: Treee


    Hi,

    it sill does not work in my model. Maybe you can have a look at this part of my model (which works good, but has no relaxion in it)

    in the comment i wrote, what i tried to write

     

    dvar boolean placedTypes[List1][Block][Tier][Row][Column];
    dvar int+ weakConstraintin 0..1;

     

    minimize
          sum( t in Tier,r in Row, c in Column, a in Containerliste1, b in Block )
              placedTypes[a][b][t][r][c]*Distance[b][t][r][c];  // + weakContstraint*5?

     

    and my constraint that should be relaxed is :

       HigherWeightOverLower:
               forall(a1 in List1, t in Tier, r in Row, c in Column,b in Block)

    (0!=sum(a2 in List1 )placedTypes[a2][b][2][r][c])   => (placedTypes[a1][b][1][r][c] * a1.weight <= sum(a2 in List1)placedTypes[a2][b][2][r][c] * a2.weight ;  // + sum(a2 in List1)placedTypes[a2][b][2][r][c]*weakConstraint*a2.weight*3?

     

    kind regards
      


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 9.  Re: weak constraints

    Posted 10/10/16 03:42 PM

    Originally posted by: Petr Vilím


    Each forall creates a number of constraints. I guess that you want to penalize each broken constraint by 5 so we will need multiple indicator variables. What about something like this:

    dvar boolean placedTypes[List1][Block][Tier][Row][Column];
    dvar boolean isTrue[List1][Tier][Row][Column][Block];
     
    minimize
        sum(t in Tier,r in Row, c in Column, a in Containerliste1, b in Block)
          placedTypes[a][b][t][r][c]*Distance[b][t][r][c]
      + 5*sum(a1 in List1, t in Tier, r in Row, c in Column,b in Block)
          (1 - isTrue[a1][t][r][c][b]);
    
    HigherWeightOverLower:
      forall(a1 in List1, t in Tier, r in Row, c in Column,b in Block)
        isTrue[a1][t][r][c][b] == (
          (0!=sum(a2 in List1 )placedTypes[a2][b][2][r][c]) => (placedTypes[a1][b][1][r][c] * a1.weight <= sum(a2 in List1)placedTypes[a2][b][2][r][c] * a2.weight)
        );
    

    Petr


    #DecisionOptimization
    #OPLusingCPOptimizer