Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  nvalues global constraint

    Posted 04/25/12 07:48 AM

    Originally posted by: elec


    Hi,

    Does there exist a nvalues global constraint (http://www.emn.fr/z-info/sdemasse/gccat/Cnvalues.html) in cp optimizer? I can't seem to find one in the documentation, but maybe i am overlooking something.

    Best regards,

    E.
    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: nvalues global constraint

    Posted 04/25/12 08:46 AM

    Originally posted by: SystemAdmin


    Hello,
    The nvalues global constraint does not exists in CP Optimizer. You can model it either with a sum of positive count expressions or a sum of or constraints as illustrated in the OPL model below:

    
    range Values = 0..10; 
    
    int n = 20;   dvar 
    
    int x[i in 1..n] in Values; dvar 
    
    int y in 1..n;   constraints 
    { y == sum(v in Values) (0<count(x,v)); 
    // alternative model: 
    // y == sum(v in Values) ( or(i in 1..n) x[i]==v ); 
    }
    


    Philippe
    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: nvalues global constraint

    Posted 04/26/12 03:36 AM

    Originally posted by: elec


    Hi Phillipe,

    Thanks for the fast response. However, i'm not sure i fully understand the alternatives you provided. I could be mistaken, but i don't think that those constraints do the same thing as the nvalues (i.e. count the number of distinct values assigned to a set of variables.) I believe the posted constraints do something like count how many times in total each distinct value is assigned.

    For example, consider the following assignment:
    x0 = 1;
    x1 = 1;
    x2 = 2;
    x3 = 3;

    The proposed constraints will have y=4, but nvalues will have y=3.

    Am i correct to think this?
    #CPOptimizer
    #DecisionOptimization


  • 4.  Re: nvalues global constraint

    Posted 04/26/12 04:21 AM

    Originally posted by: SystemAdmin


    Hello,
    The formulation I gave is correct, it just computes for each value a boolean expression saying whether or not this value is taken by at least one variable. And then it sums up these boolean expressions.

    On your example:

    
    x0 = 1; x1 = 1; x2 = 2; x3 = 3;   Values = 
    {1, 2, 3
    } x = [x0,x1,x2,x3]
    


    With first formulation:

    
    v     count(x,v)    (0<count(x,v)); 1     2              1 2     1              1 3     1              1 ------------------------------------ y=3
    


    With second formulation:

    
    v     (x0==v)  (x1==v)  (x2==v)  (x3==v)   (or(i in 0..3) xi==v) 1      1        1        0        0         1 2      0        0        1        0         1 3      0        0        0        1         1 ---------------------------------------------------------------- y=3
    

    #CPOptimizer
    #DecisionOptimization