Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Beginner Question

    Posted 04/04/17 03:49 PM

    Originally posted by: cpgt


    I have two decision variables; (using c#)

     

    IIntVar[] A = cp.IntVarArray(2, 0, 10);
    IIntVar[] B = cp.IntVarArray(2, 0, 10);

     

    I want to constraint the value B[0] to be equal to A[0] or A[1], like so;

     

    cp.Add(cp.Eq(cp.Count(A, B[0]), 1));

     

    Which I can't do, and get a compile error of "'cannot convert from ILOG.Concert.IIntVar' to 'int'"

    How do I get the value of B[0], to use in constraining to values of A?. Or is there a better way to do what I'm trying to do? Thanks.

     


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: Beginner Question

    Posted 04/04/17 05:05 PM

    Originally posted by: JorisK


    cp.add(cp.or(cp.eq(b[0],a[0]), cp.eq(b[0],a[1])));

     

    see documentation of the IloModeler interface for details.


    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: Beginner Question

    Posted 04/04/17 06:13 PM

    Originally posted by: cpgt


    Thanks for the answer, but is there is no way for me to count the number of instances the value of one decision variable is contained within another? There has to be a better way than to do a boolean comparison against each value.


    #CPOptimizer
    #DecisionOptimization


  • 4.  Re: Beginner Question

    Posted 04/06/17 04:35 AM

    Originally posted by: Paul Shaw


    Count can only be used to count the number of times a known value is taken by a vector of variables.

    So, indeed, the way to do this is to compare against each variable.  For example:

       E = sum_{i=1}^n (x == y_i)

    and then use constraint E >= 1 (if x must be equal to at least 1 of y)
    or E == 1 (if x must be equal to exactly one of y)


    #CPOptimizer
    #DecisionOptimization


  • 5.  Re: Beginner Question

    Posted 04/04/17 06:39 PM

    Originally posted by: JorisK


    Try: cp.Add(cp.Eq(cp.Count(A, B[0]), cp.constant(1)));

     

    cp.constant(int c) creates an IloIntExpr


    #CPOptimizer
    #DecisionOptimization


  • 6.  Re: Beginner Question

    Posted 04/04/17 06:58 PM

    Originally posted by: cpgt


    No difference, the count function still throws a compile error.

    The Count function in C# is defined as follows; public virtual IIntExpr Count(IIntExpr[] exprs, int v). So I need to retrieve the value of B[0], which simply plugging it in is not working. Plugging in cp.GetValue(B[0]) into cp.Couunt() gives a runtime error, since I'm guessing it requires the problem to be solved first.


    #CPOptimizer
    #DecisionOptimization