我想编写一个约束,为此,我需要定义一个参数,称为车辆 s' 从节点“m”到“n”的行驶时间。
我以元组形式定义了旅行时间,如下所示:
int num_road = 6;
range Roadno = 1..num_road;
tuple Road {
int Road_num;
int from_node;
int to_node;
int travel_time;
}
Road Roaddata [Roadno] = [
<1, 15, 21, 2>,
<2, 21, 15, 2>,
<3, 21, 30, 2>,
<4, 30, 21, 2>,
<5, 15, 30, 1>,
<6, 30, 15, 1>
];
现在我必须使用这个元组数据来写下约束,即下面给出的。
NT =24;
forall (s in M,m in B, n in B:m!=n, tau in 1..Tm_ij[n][i][j],t in 1..NT-tau){
pos[s][m][t+tau] + pos[s][n][t] <= 1;
}
而不是
Tm_ij[n][i][j]
矩阵,我想使用元组中的旅行时间数据。请向我建议如何使用元组数据在 OPL CPLEX 中编写此约束。
使用“item”,您可以从元组集中读取您的旅行时间。
int num_road = 6;
range Roadno = 1..num_road;
tuple Road {
key int Road_num;
key int from_node;
key int to_node;
int travel_time;
}
{Road} Roaddata = {
<1, 15, 21, 2>,
<2, 21, 15, 2>,
<3, 21, 30, 2>,
<4, 30, 21, 2>,
<5, 15, 30, 1>,
<6, 30, 15, 1>
};
int NT =24;
range M=1..2;
range B=1..3;
dvar boolean pos[-1000..1000][M][-1000..1000];
subject to
{
forall (s in M,m in B, n in B:m!=n, tau in 1..item(Roaddata,<n,s,n>).travel_time,t in 1..NT-tau){
pos[s][m][t+tau] + pos[s][m][t] <= 1;
}
}