Group: sci.op-research
From: Irv Lustig
Date: Tuesday, February 26, 2008 1:34 AM
Subject: Re: define decision variable in OPL-CPLEX

On Feb 25, 10:29=A0pm, Min wrote:
> Hello -
> I have a basic question about defining decision variables in OPL-
> CPLEX. I want to define the variable in a nested format like the
> following
>
> =A0for ( var i=3D0; i<=3D4; i++) {
> =A0 =A0 =A0 =A0 for ( var j=3D0; j<=3DP(i); j++){
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dvar boolean a[i][j=
]}}
>
> But the system thinks it is an error. How can I do this?
>
> Many thanks.

Use tuples as follows:
tuple IndexSetTuple {
int i;
int j;
};
setof(IndexSetTuple) indexset =3D { | i in 0..4, j in 0..P[i] };
dvar boolean a[indexset];

When you refer to the variables in the model, use the expression
a[];

Tuples are a very important feature to make scalable models with OPL.

-Irv Lustig, PhD
ilustig@ilog.com
ILOG Direct Channel Director
http://www.ilog.com/