How to create a multidimensional variable in ilog with Java interface?

Unlucky_faust picture Unlucky_faust · Nov 26, 2012 · Viewed 7k times · Source

I want to model a problem with a variable x[i][j][k].

No where in the reference manual is there mention of how to create a variable with size greater than 1 dimension.

http://pic.dhe.ibm.com/infocenter/cosinfoc/v12r4/index.jsp?topic=%2Filog.odms.cplex.help%2Frefjavacplex%2Fhtml%2Filog%2Fcplex%2FIloCplex.html

Answer

user327301 picture user327301 · Nov 28, 2012

This snippet shows an example of creating three indexed continuous variable x, x[i][j][t] in [0,1]:

  IloNumVar[][][] x = new IloNumVar[numNodes][numNodes][numDays];
  for(int i = 0; i < numNodes; i++) 
  {
    for(int j = 0; j < numNodes; j++)
    {
      //cplex is an instance of class IloCplex
      x[i][j] = cplex.numVarArray(numDays, 0, 1); 
    }
  }