我正在尝试编写约束但是我收到了这个错误:
Main.mod:25: operand preceding < has invalid type
Context: ...es : sum { ta in Task_Names } Time_Source [ ti , ma , ta ] <MathProg model processing error
>Exit code: 1 Time: 0.241
这是代码:
set Tasks dimen 4;
set endTimes := setof{(t,s,e,d) in Tasks}e;
set Task_Names := setof{(t,s,e,d) in Tasks}t;
set Machines dimen 2;
set Machine_Names := setof{(m,a) in Machines}m;
set Task_Machines dimen 3;
param lastTime := max{t in endTimes}(t);
set time_slots := 1..lastTime;
var Start_Time{ti in time_slots,ta in Task_Names},binary;
var Time_Source{ti in time_slots,ma in Machine_Names,ta in Task_Names},integer;
s.t. c1{ti in time_slots,ma in Machine_Names,ta in Task_Names,(ta,ma,co) in Task_Machines}:Time_Source[ti,ma,ta] = co*Start_Time[ti,ta];
s.t. c2{ti in time_slots,(t,s,e,d) in Tasks : ti>=s and ti<=e and ti<=e-d}:Start_Time[ti,t]=1;
s.t. c3{ti in time_slots,(t,s,e,d) in Tasks : ti<s or ti>e or ti>e-d}:Start_Time[ti,t]=0;
s.t. c4{ti in time_slots,ma in Machine_Names,(ma,num) in Machines: sum{ta in Task_Names} Time_Source[ti,ma,ta]<num};
solve;
display:Start_Time;
display:Time_Source;
display:Machine_Names;
display:Task_Machines;
data;
set Tasks :=
(T1,3,20,1)
(T2,3,30,5)
(T3,12,40,10);
set Machines :=
(M1,2)
(M2,3)
(M3,2)
(M4,1);
set Task_Machines :=
(T1,M1,1)
(T1,M2,1)
(T2,M1,2)
(T3,M4,5);
end;
错误是针对“C4”约束的。我的问题是在“c4”中如何在其条件中使用变量? 我该如何解决这个错误?
答案 0 :(得分:1)
在我看来,好像c4中只有两个小错别字(}
的位置,使用<=
代替<
):
s.t. c4{ ti in time_slots,
ma in Machine_Names,
(ma,num) in Machines}:
sum{ta in Task_Names} Time_Source[ti,ma,ta] <= num;
我将整个修复示例复制到浏览器中的MathProg编辑器(包含GLPK.js解算器)。