Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Modulate Binaries

    Posted 01/26/11 08:12 PM

    Originally posted by: SystemAdmin


    Hi all,

    There is probably a very simple solution to this but I am new to CPLEX and the Concert library so please forgive my ignorant question.

    I'm trying to solve an ILP in Java. At a certain point I'm using

    IloNumVar[] x = cplex.numVarArray( 1, 0, 1 );

    But this produces a variable within the range 0-1: 0 <= x <= 1.
    What do I do if I want x to be able to be only 0 ór 1: x \in {0,1}?

    I already tried using IloIntVar but then I get: "ilog.cplex.CpxException: CPLEX Error 1017: Not available for mixed-integer programs." so that's probably not it.

    Any pointers are much appreciated, thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Modulate Binaries

    Posted 01/27/11 02:50 AM

    Originally posted by: SystemAdmin


    Try IloCplex.boolVarArray() or IloCplex.intVarArray() to create integral variables.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Modulate Binaries

    Posted 01/27/11 05:45 AM

    Originally posted by: SystemAdmin


    Thanks Daniel,

    I already tried IloCplex.intVarArray() but I saw that I still was using a numVarArray somewhere else, and that causes problems when trying to retrieve variables with a range.

    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Modulate Binaries

    Posted 01/27/11 11:55 AM

    Originally posted by: SystemAdmin


    > 3ckhardt wrote:
    >
    > I already tried IloCplex.intVarArray() but I saw that I still was using a numVarArray somewhere else, and that causes problems when trying to retrieve variables with a range.

    It should not. This is the Java API, correct? The following sample code mixes integer variables into a numVarArray and works fine:

    IloCplex cplex = new IloCplex();
    IloNumVar[] array = cplex.numVarArray(3, 0, 100);
    array[0] = cplex.numVar(0, 100, "x");
    array[1] = cplex.boolVar("y");
    array[2] = cplex.numVar(0.0, Double.MAX_VALUE, "z");
    //...
    if (cplex.solve()) {
      double[] v = cplex.getValues(array);  // gets values for x, y and z
      //...
    }
    


    Regarding error 1017, I doubt that has to do with the array declarations; more likely you asked for something (such as reduced costs) that exist for LPs but not for MIPs.

    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization