为元组编写约束

时间:2017-07-16 10:33:20

标签: c cplex

我定义了以下元组:

tuple capacity3 {
    int sup; // varies from 1 to 5
    int comp; // varies from 1 to 3
    int peri; // varies from 1 to 6
    int val3; // values corresponding to sup, comp, peri
}
{ capacity3 } aa = ...;

我把我的元组写成

aa={<1,1,1,620>,<1,1,2,610>,<1,1,3,630>,<1,1,4,620>,<1,1,5,640>,<1,1,6,630>, ...  //and so on.

现在我有以下约束条件;

forall(i in I, c in C, p in P)
      sum(j in J)X[i][j][c][p]<= RHS 

在RHS,我需要在元组中编写定义为val3 (620, 610 ....)的值,该元素对应于在我的元组中定义为i,c and p的特定sup, comp and peri

我如何写出我的约束,即RHS的速度值?或者我其他地方也出错了?

我是CPLEX的新手。

1 个答案:

答案 0 :(得分:1)

同样的问题

https://developer.ibm.com/answers/questions/387005/writing-constraint-for-a-tuple.html

你可以写

的.mod

tuple capacity3 { 
key int sup; // varies from 1 to 5 
key int comp; // varies from 1 to 3 
key int peri; // varies from 1 to 6 
int val3; // values corresponding to sup, comp, peri 
} 

range I=1..1;
range J=1..1;
range C=1..1;
range P=1..6;

{capacity3} aa=...;

dvar float X[I][J][C][P];

subject to
{

forall(i in I, c in C, p in P) sum(j in J)X[i][j][c][p]<= item(aa,<i,c,p>).val3;

}

的.dat

aa={
<1,1,1,620>,<1,1,2,610>,
<1,1,3,630>,<1,1,4,620>,<1,1,5,640>,<1,1,6,630>
};

问候