Reputation: 33
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.
Upvotes: 3
Views: 7185
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
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