CPLEX 中的逻辑约束
Logical constraints in CPLEX
我是使用 CPLEX 的初学者,我遇到了创建逻辑约束的问题(如果……那么……)。我使用 IBM ILOG CPLEX Optimization Studio 版本 12.7。根据the manual,它应该能够通过使用“=>”来处理逻辑约束(例如,"if x>0 then y>=2" 应该变成x>0 => y>=2
)。
问题包括为员工分配轮班的开始和结束时间(如果他们今天不工作,则为 0)。我正在尝试创建一个变量,该变量的功能类似于指示它们是否在工作的指标,以便以后使用它来分配成本。
我已将我的代码归结为以下内容:
using CP;
tuple TimeSlot {
key int day;
key int slotNo;
}
{TimeSlot} TimeSlots = ...;
{int} mondays = {t.slotNo|t in TimeSlots:t.day==1};
int monMax = max(t in mondays) t;
range monRange = 0..monMax;
range allEmployees = 1..10;
dvar int monStart[allEmployees] in monRange; //Start of monday shift
dvar int monEnd[allEmployees] in monRange; //End of monday shift
dvar int monAtWork[allEmployees] in 0..1; //Binary
//minimize ...
subject to{
forall(t in allEmployees)
{monStart[t] > 0 && monEnd[t]>0} => monAtWork[t] = 1; //Get error here
}
我得到的错误是 syntax error, unexpected =
。我尝试了拆分和翻转约束(例如 monStart[t] == 0 => monAtWork[t] = 0;
),但均无济于事。我错过了什么吗?
查看提供的 OPL 示例(例如 BasketballScheduling\acc.mod)我认为定义约束的 'then' 部分应该有“==”而不是“=”。不是赋值,而是声明两者必须相等
using CP;
tuple TimeSlot {
key int day;
key int slotNo;
}
{TimeSlot} TimeSlots = {<1,1>,<2,2>};;
{int} mondays = {t.slotNo|t in TimeSlots:t.day==1};
int monMax = max(t in mondays) t;
range monRange = 0..monMax;
range allEmployees = 1..10;
dvar int monStart[allEmployees] in monRange; //Start of monday shift
dvar int monEnd[allEmployees] in monRange; //End of monday shift
dvar int monAtWork[allEmployees] in 0..1; //Binary
//minimize ...
subject to{
forall(t in allEmployees)
(monStart[t] > 0 && monEnd[t]>0) => monAtWork[t] == 1; //Get error here
}
工作正常
我是使用 CPLEX 的初学者,我遇到了创建逻辑约束的问题(如果……那么……)。我使用 IBM ILOG CPLEX Optimization Studio 版本 12.7。根据the manual,它应该能够通过使用“=>”来处理逻辑约束(例如,"if x>0 then y>=2" 应该变成x>0 => y>=2
)。
问题包括为员工分配轮班的开始和结束时间(如果他们今天不工作,则为 0)。我正在尝试创建一个变量,该变量的功能类似于指示它们是否在工作的指标,以便以后使用它来分配成本。
我已将我的代码归结为以下内容:
using CP;
tuple TimeSlot {
key int day;
key int slotNo;
}
{TimeSlot} TimeSlots = ...;
{int} mondays = {t.slotNo|t in TimeSlots:t.day==1};
int monMax = max(t in mondays) t;
range monRange = 0..monMax;
range allEmployees = 1..10;
dvar int monStart[allEmployees] in monRange; //Start of monday shift
dvar int monEnd[allEmployees] in monRange; //End of monday shift
dvar int monAtWork[allEmployees] in 0..1; //Binary
//minimize ...
subject to{
forall(t in allEmployees)
{monStart[t] > 0 && monEnd[t]>0} => monAtWork[t] = 1; //Get error here
}
我得到的错误是 syntax error, unexpected =
。我尝试了拆分和翻转约束(例如 monStart[t] == 0 => monAtWork[t] = 0;
),但均无济于事。我错过了什么吗?
查看提供的 OPL 示例(例如 BasketballScheduling\acc.mod)我认为定义约束的 'then' 部分应该有“==”而不是“=”。不是赋值,而是声明两者必须相等
using CP;
tuple TimeSlot {
key int day;
key int slotNo;
}
{TimeSlot} TimeSlots = {<1,1>,<2,2>};;
{int} mondays = {t.slotNo|t in TimeSlots:t.day==1};
int monMax = max(t in mondays) t;
range monRange = 0..monMax;
range allEmployees = 1..10;
dvar int monStart[allEmployees] in monRange; //Start of monday shift
dvar int monEnd[allEmployees] in monRange; //End of monday shift
dvar int monAtWork[allEmployees] in 0..1; //Binary
//minimize ...
subject to{
forall(t in allEmployees)
(monStart[t] > 0 && monEnd[t]>0) => monAtWork[t] == 1; //Get error here
}
工作正常