Unlucky_faust
Unlucky_faust

Reputation: 33

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

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

Upvotes: 3

Views: 7185

Answers (2)

Ram Narasimhan
Ram Narasimhan

Reputation: 22506

Multi-dimensional modeling is very routine.

Here's an example, provided by IBM.

Also, IBM's "Modeling with IBM ILOG CPLEX CP Optimizer – Practical Scheduling Examples" is actually a very good place to start. It has many multi-dimensional examples, though most as in OPL, which you don't have to use.

And, Here's a full example that uses 2 dimensions. Specifically, the variable nutrPerFood has both i and j as dimensions.

 // nutrPerFood[i][j]   nutrition amount of nutrient i in food j

 double[][] nutrPerFood; 

and you use that when calling IloMPModeler

This tutorial is also helpful, to get familiar with the various Ilog calls.

Hope that helps.

Upvotes: 1

user327301
user327301

Reputation: 2641

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); 
    }
  }

Upvotes: 4

Related Questions