如何在CPLEX中的元组中声明动态数组? [英] How to declare a dynamic array inside tuple in CPLEX?

查看:126
本文介绍了如何在CPLEX中的元组中声明动态数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在CPLEX中声明一个元组数组.元组内部声明了一个2D数组,并且该数组的长度对于元组数组的每个元素都是不同的.但是CPLEX显示错误.我附上了代码片段.谁能帮我这个?

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]=...;

推荐答案

元组集中的所有数组都具有相同的大小.因此,我将为此使用元组集.

All arrays a in a tuple set have the same size. So I would use tuple sets for that.

让我给你举个例子:

.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>,]; 

这篇关于如何在CPLEX中的元组中声明动态数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆