Originally posted by: SystemAdmin
[philippe said:]
I've a problem with array lengths in OPL.
From the C++ API one can do something like this:
struct Container
{
std::vector<float> floats;
};
void test()
{
std::vector<Container> containers;
IloEnv env;
IloArray<IloNumVarArray> vars( env );
for ( int i = 0; i < containers.size(); ++i ) {<br /> vars.add( IloNumVarArray( env ) );
for ( int j = 0; j < containers[i].floats.size(); ++j ) {<br /> vars[i].add( IloNumVar( env ) );
}
}
}
The lengths of the inner float vectors don't have to be the same. Works fine and saves some variables.
Not so with OPL:
tuple Container
{
{float} floats;
}
{Container} containers = ...;
float vars[i in containers][j in i.floats] = 0;
The code gives the following error:
[b]
Variable indexer size not allowed for a generic array.
[/b]
Any idea how to work around this? Otherwise I've to find out the longest float set and constrain the unused variables to something reasonable...
Thanks for any hints.
#DecisionOptimization#OPLusingCPLEXOptimizer