我想用分配给dvar的值来引用一个数组,但CPLEX却给出了一个错误信息--"CP不能提取表达式"。但是,CPLEX却给出了一个错误信息--"CP无法提取表达式"。我该怎么做才能克服这个错误?
下面是我的问题的代码--一个基于员工可用时间的工作分配。
using CP;
{string} Employee = ...;
{string} Jobs = ...;
range EmpIDs = 0..card(Employee)-1;
{int} AvailSlot[EmpIDs] = ...;
range Slots = 1...10
dvar int Time[Jobs] in Slots;
dvar int Emp[Jobs] in EmpIDs;
subject to{
forall (x in Jobs) {
Time[x] in AvailSlot[Emp[x]];} //this constraints the assigned time slot for the job x to be one of the available time slots of the employee that is assigned with the same job x.
}
先谢谢你。
使用CP.P.A.C.A.C.A.C.C.A.C.A.C.A.C.A.C.A.C.A.C.A.C.A.C.A.C.A.A.C.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A;
{string} Employee = {"A","B"};
{string} Jobs = {"K","L"};
range EmpIDs = 0..card(Employee)-1;
{int} AvailSlot[EmpIDs] = [{1,2},{2,3}];
range Slots = 1..10;
dvar int Time[Jobs] in Slots;
dvar int Emp[Jobs] in EmpIDs;
subject to{
forall (x in Jobs) {
//Time[x] in AvailSlot[Emp[x]];
or (j in EmpIDs) (j==Emp[x] && Time[x] in AvailSlot[j]);
}
}
assert forall (x in Jobs)
Time[x] in AvailSlot[Emp[x]];
可以正常工作