[英]Array of sets in CPLEX OPL
I am trying to implement an array of sets in CPLEX.我正在尝试在 CPLEX 中实现一组集合。
The end result should look like this:最终结果应如下所示:
{int} Z[1..6] = [{1,2,3,4,5},{1,2,3,4,5},{1,2,3,4},{2,3,4},{2,3,4},{2,3,4}]
Each array element is derrived from two other arrays.每个数组元素派生自另外两个 arrays。
int X[1..6] = [1,1,1,2,2,2]
int Y[1..6] = [5,5,5,4,4,4]
So each element of Z represents a range of ints between the elemets of arrays X and Y所以 Z 的每个元素代表 arrays X 和 Y 的元素之间的整数范围
I tried to do it with following code:我尝试使用以下代码来做到这一点:
range A = 1..6;
execute calculateZ{
for(var i in A){
for(v = X[i]; v <= Y[i]; v++){
Opl.item(W[i],v-1) = v;
}
}
}
My questions are:我的问题是:
-is an array of sets possible at all? - 一组集合可能吗?
-if so how can I fill the elements of my set? - 如果是这样,我怎样才能填充我的集合的元素? opl.item doesnt seem to work in this case. opl.item 在这种情况下似乎不起作用。
you could use OPL scripting but I d rather rely on OPL modeling part:您可以使用 OPL 脚本,但我宁愿依赖 OPL 建模部分:
int X[1..6] = [1,1,1,2,2,2];
int Y[1..6] = [5,5,5,4,4,4];
{int} Z[i in 1..6] = asSet(X[i]..Y[i]);
execute
{
writeln(Z);
}
gives给
[{1 2 3 4 5} {1 2 3 4 5} {1 2 3 4 5} {2 3 4} {2 3 4} {2 3 4}]
PS: PS:
later on you asked how to do that in scripting.后来你问如何在脚本中做到这一点。
range r=1..6;
int X[r] = [1,1,1,2,2,2];
int Y[r] = [5,5,5,4,4,4];
{int} Z[i in r] = asSet(X[i]..Y[i]);
{int} Z2[i in r];
execute
{
for(var i in r) for(var j=X[i];j<=Y[i];j++) Z2[i].add(j);
writeln(Z);
writeln(Z2);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.