How to declare a dynamic array inside tuple in CPLEX?

ⅰ亾dé卋堺 提交于 2021-01-29 13:31:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!