问题
I'm declaring an array of tuples in CPLEX. The tuple have a 2D array declared inside them and the length of those arrays would be different for each element of the array of tuples. But the CPLEX is showing errors. I'm attaching the snippet of the code. Can anyone help me with this?
int n=...;
range N=1..n;
tuple info{
int a;
int b;
int box[1..b];
float d;
}
info tuplearray[N]=...;
回答1:
All arrays a in a tuple set have the same size. So I would use tuple sets for that.
Let me give you an example:
.mod
int n=4;
range N=1..n;
int m=2;
tuple info{
int a;
int b;
int box[1..m];
float d;
}
info tuplearray[i in N]=...;
execute
{
writeln(tuplearray);
}
tuple boxitem
{
int i;
int j;
int v;
}
{boxitem} boxitems={<1,1,1>,<2,1,3>,<2,2,4>,<3,1,2>,<4,1,2>};
int sizes[i in 1..n]=card({t | t in boxitems : t.i==i});
execute
{
writeln(sizes);
writeln(boxitems);
}
.dat
tuplearray=[<1,2,[1,2],1.5>,<3,4,[3,2],1.5>,<1,2,[4,2],1.5>,<7,8,[6,2],1.5>,];
来源:https://stackoverflow.com/questions/50987132/how-to-declare-a-dynamic-array-inside-tuple-in-cplex