在 post 中创建一个元组-处理 OPL 的执行命令
Creating a tuple in post-process execute command of OPL
我有一个工人分配问题,其中工作包含三个组成部分
(子技能)识别它们:
{job} 职位 = { < c1, c2, c3 > | Cat1 中的 c1,Cat2 中的 c2,Cat3 中的 c3 };
我现在从工人池中创建可能性元组
如果工人符合条件,则将其分配给工作:
{possibleTuple} = 可能 = { < n, c1, c2, c3 > | < c1,c2,c3> 在工作中,n 在工人中 };
二进制数组 onTeam[Possibles] 指示工人 n 是否已分配给团队。
我的模型运行良好,并且得到了合理的结果。然而,我是
无法在 post-processing "execute" 中很好地打印这些
命令。我想为每项工作输出工人团队
类似于:
for (var j in Jobs)
{
for (var n in Workers)
{
if onTeam[<n,c1,c2,c3>] == 1, output n
}
}
正是这种内在逻辑让我感到困难。我不能够
重新创建元组以索引 onTeam 集。
有人可以帮忙吗?
非常感谢,
帕特里克希利
举个小例子:
{string} Cat1={"A","B"};
{string} Cat2={"C","D"};
{string} Cat3={"E","F"};
tuple job
{
string j1;
string j2;
string j3;
}
{job} Jobs = { < c1, c2, c3 > | c1 in Cat1, c2 in Cat2, c3 in Cat3 };
{string} Workers={"Albert","Bob","Charles"};
tuple possibleTuple
{
string n;
string j1;
string j2;
string j3;
}
{possibleTuple} Possibles = { < n, c1, c2, c3 > | < c1,c2,c3> in Jobs, n in Workers };
dvar boolean onTeam[Possibles];
subject to
{
onTeam[<"Albert","A","C","E">]==1;
onTeam[<"Bob","A","C","E">]==1;
onTeam[<"Charles","A","C","F">]==1;
}
{string} workersPerJob[j in Jobs]=
{w | w in Workers : onTeam[<w,j.j1,j.j2,j.j3>]==1};
execute
{
for(var j in Jobs) if ( workersPerJob[j].size!=0)
{
writeln("for job ",j," workers : ", workersPerJob[j]);
}
}
这给出了
for job <"A" "C" "E"> workers : {"Albert" "Bob"}
for job <"A" "C" "F"> workers : {"Charles"}
我有一个工人分配问题,其中工作包含三个组成部分 (子技能)识别它们:
{job} 职位 = { < c1, c2, c3 > | Cat1 中的 c1,Cat2 中的 c2,Cat3 中的 c3 };
我现在从工人池中创建可能性元组 如果工人符合条件,则将其分配给工作:
{possibleTuple} = 可能 = { < n, c1, c2, c3 > | < c1,c2,c3> 在工作中,n 在工人中 };
二进制数组 onTeam[Possibles] 指示工人 n 是否已分配给团队。
我的模型运行良好,并且得到了合理的结果。然而,我是 无法在 post-processing "execute" 中很好地打印这些 命令。我想为每项工作输出工人团队 类似于:
for (var j in Jobs)
{
for (var n in Workers)
{
if onTeam[<n,c1,c2,c3>] == 1, output n
}
}
正是这种内在逻辑让我感到困难。我不能够 重新创建元组以索引 onTeam 集。
有人可以帮忙吗?
非常感谢, 帕特里克希利
举个小例子:
{string} Cat1={"A","B"};
{string} Cat2={"C","D"};
{string} Cat3={"E","F"};
tuple job
{
string j1;
string j2;
string j3;
}
{job} Jobs = { < c1, c2, c3 > | c1 in Cat1, c2 in Cat2, c3 in Cat3 };
{string} Workers={"Albert","Bob","Charles"};
tuple possibleTuple
{
string n;
string j1;
string j2;
string j3;
}
{possibleTuple} Possibles = { < n, c1, c2, c3 > | < c1,c2,c3> in Jobs, n in Workers };
dvar boolean onTeam[Possibles];
subject to
{
onTeam[<"Albert","A","C","E">]==1;
onTeam[<"Bob","A","C","E">]==1;
onTeam[<"Charles","A","C","F">]==1;
}
{string} workersPerJob[j in Jobs]=
{w | w in Workers : onTeam[<w,j.j1,j.j2,j.j3>]==1};
execute
{
for(var j in Jobs) if ( workersPerJob[j].size!=0)
{
writeln("for job ",j," workers : ", workersPerJob[j]);
}
}
这给出了
for job <"A" "C" "E"> workers : {"Albert" "Bob"}
for job <"A" "C" "F"> workers : {"Charles"}