Decision Optimization

 View Only
  • 1.  allDifferent for IloIntVar array

    Posted Wed June 03, 2015 11:56 AM

    Originally posted by: gxkendall


    Hi

    I am trying to develop my first CPLEX model in Java (so I apologise if this is an easy question).

     

    I am declaring a decision variable as follows (n is declared (n=20)).

     

    IloIntVar[] x = cplex.intVarArray(n, 1, n);

     

    So, I am trying to declare an array of 20 integers, where each elemnet can take a value between 1 and 20.

     

    BUT, each integer can only appear once so (I think) I need to specify an allDifferent constraint, but no amount of searching shows me how to do this.

     

    Is it possible, or am I gettng LP/MIP etc. confused with Constraint Programming and it is not possible?

     

    Thanks in advance.

     

    G


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: allDifferent for IloIntVar array

    Posted Thu June 04, 2015 03:53 AM

    You are right, there is no explicit IloAllDiff() for LP/MIP. I see two options:

    1. Instead of using the MIP/LP solver IloCplex, use the CP solver IloCP. This has a method IloCP.allDiff() that creates an all-diff constraint.
    2. Linearize the all-diff constraint or handle it by a callback. There is a very old post that discusses some aspects of this.

    Another option would be to try to come up with a model that does not require all-diff constraints.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: allDifferent for IloIntVar array

    Posted Thu June 04, 2015 08:19 AM

    Originally posted by: gxkendall


    Many thansk - that is very useful. Not the answer I wanted :-), but at least I know.

     

    G


    #CPLEXOptimizers
    #DecisionOptimization