В уравнении
def period_capacity_dept(m, e, j, t, dp):
return sum(a[e, j, dp, t]*m.y[e,j,t] for (e,j) in model.EJ)<= K[dp,t] + m.R[t,dp]
model.period_capacity_dept = Constraint(E, J, T, DP, rule=period_capacity_dept)
вы должны отбросить аргументы функции e, j.Теперь вы повторяете одно и то же ограничение много раз.Вы можете увидеть это, выполнив model.period_capacity_dept.pprint()
.Это показывает:
period_capacity_dept : Size=24, Index=period_capacity_dept_index, Active=True
Key : Lower : Body : Upper : Active
('emp0', 'train0', 0, 'dept1') : -Inf : 2*y[emp1,train0,0] + 2*y[emp0,train0,0] - (10000 + R[0,dept1]) : 0.0 : True
('emp0', 'train0', 0, 'dept2') : -Inf : y[emp0,train1,0] + y[emp1,train0,0] + y[emp1,train1,0] + 2*y[emp0,train0,0] - (10000 + R[0,dept2]) : 0.0 : True
('emp0', 'train0', 1, 'dept1') : -Inf : y[emp0,train1,1] + 2*y[emp1,train0,1] + 2*y[emp1,train1,1] + 2*y[emp0,train0,1] - (10000 + R[1,dept1]) : 0.0 : True
('emp0', 'train0', 1, 'dept2') : -Inf : y[emp1,train1,1] + y[emp0,train0,1] - (10000 + R[1,dept2]) : 0.0 : True
('emp0', 'train0', 2, 'dept1') : -Inf : y[emp1,train0,2] + 2*y[emp1,train1,2] - (10000 + R[2,dept1]) : 0.0 : True
('emp0', 'train0', 2, 'dept2') : -Inf : y[emp0,train1,2] + 2*y[emp1,train1,2] + 2*y[emp0,train0,2] - (10000 + R[2,dept2]) : 0.0 : True
('emp0', 'train1', 0, 'dept1') : -Inf : 2*y[emp1,train0,0] + 2*y[emp0,train0,0] - (10000 + R[0,dept1]) : 0.0 : True
('emp0', 'train1', 0, 'dept2') : -Inf : y[emp0,train1,0] + y[emp1,train0,0] + y[emp1,train1,0] + 2*y[emp0,train0,0] - (10000 + R[0,dept2]) : 0.0 : True
('emp0', 'train1', 1, 'dept1') : -Inf : y[emp0,train1,1] + 2*y[emp1,train0,1] + 2*y[emp1,train1,1] + 2*y[emp0,train0,1] - (10000 + R[1,dept1]) : 0.0 : True
('emp0', 'train1', 1, 'dept2') : -Inf : y[emp1,train1,1] + y[emp0,train0,1] - (10000 + R[1,dept2]) : 0.0 : True
('emp0', 'train1', 2, 'dept1') : -Inf : y[emp1,train0,2] + 2*y[emp1,train1,2] - (10000 + R[2,dept1]) : 0.0 : True
('emp0', 'train1', 2, 'dept2') : -Inf : y[emp0,train1,2] + 2*y[emp1,train1,2] + 2*y[emp0,train0,2] - (10000 + R[2,dept2]) : 0.0 : True
('emp1', 'train0', 0, 'dept1') : -Inf : 2*y[emp1,train0,0] + 2*y[emp0,train0,0] - (10000 + R[0,dept1]) : 0.0 : True
('emp1', 'train0', 0, 'dept2') : -Inf : y[emp0,train1,0] + y[emp1,train0,0] + y[emp1,train1,0] + 2*y[emp0,train0,0] - (10000 + R[0,dept2]) : 0.0 : True
('emp1', 'train0', 1, 'dept1') : -Inf : y[emp0,train1,1] + 2*y[emp1,train0,1] + 2*y[emp1,train1,1] + 2*y[emp0,train0,1] - (10000 + R[1,dept1]) : 0.0 : True
('emp1', 'train0', 1, 'dept2') : -Inf : y[emp1,train1,1] + y[emp0,train0,1] - (10000 + R[1,dept2]) : 0.0 : True
('emp1', 'train0', 2, 'dept1') : -Inf : y[emp1,train0,2] + 2*y[emp1,train1,2] - (10000 + R[2,dept1]) : 0.0 : True
('emp1', 'train0', 2, 'dept2') : -Inf : y[emp0,train1,2] + 2*y[emp1,train1,2] + 2*y[emp0,train0,2] - (10000 + R[2,dept2]) : 0.0 : True
('emp1', 'train1', 0, 'dept1') : -Inf : 2*y[emp1,train0,0] + 2*y[emp0,train0,0] - (10000 + R[0,dept1]) : 0.0 : True
('emp1', 'train1', 0, 'dept2') : -Inf : y[emp0,train1,0] + y[emp1,train0,0] + y[emp1,train1,0] + 2*y[emp0,train0,0] - (10000 + R[0,dept2]) : 0.0 : True
('emp1', 'train1', 1, 'dept1') : -Inf : y[emp0,train1,1] + 2*y[emp1,train0,1] + 2*y[emp1,train1,1] + 2*y[emp0,train0,1] - (10000 + R[1,dept1]) : 0.0 : True
('emp1', 'train1', 1, 'dept2') : -Inf : y[emp1,train1,1] + y[emp0,train0,1] - (10000 + R[1,dept2]) : 0.0 : True
('emp1', 'train1', 2, 'dept1') : -Inf : y[emp1,train0,2] + 2*y[emp1,train1,2] - (10000 + R[2,dept1]) : 0.0 : True
('emp1', 'train1', 2, 'dept2') : -Inf : y[emp0,train1,2] + 2*y[emp1,train1,2] + 2*y[emp0,train0,2] - (10000 + R[2,dept2]) : 0.0 : True
Если мы используем:
def period_capacity_dept(m, t, dp):
return sum(a[e, j, dp, t]*m.y[e,j,t] for (e,j) in model.EJ)<= K[dp,t] + m.R[t,dp]
model.period_capacity_dept = Constraint(T, DP, rule=period_capacity_dept)
, вы увидите:
period_capacity_dept : Size=6, Index=period_capacity_dept_index, Active=True
Key : Lower : Body : Upper : Active
(0, 'dept1') : -Inf : 2*y[emp1,train0,0] + 2*y[emp0,train0,0] - (10000 + R[0,dept1]) : 0.0 : True
(0, 'dept2') : -Inf : y[emp1,train0,0] + y[emp0,train1,0] + 2*y[emp0,train0,0] + y[emp1,train1,0] - (10000 + R[0,dept2]) : 0.0 : True
(1, 'dept1') : -Inf : 2*y[emp1,train0,1] + y[emp0,train1,1] + 2*y[emp0,train0,1] + 2*y[emp1,train1,1] - (10000 + R[1,dept1]) : 0.0 : True
(1, 'dept2') : -Inf : y[emp0,train0,1] + y[emp1,train1,1] - (10000 + R[1,dept2]) : 0.0 : True
(2, 'dept1') : -Inf : y[emp1,train0,2] + 2*y[emp1,train1,2] - (10000 + R[2,dept1]) : 0.0 : True
(2, 'dept2') : -Inf : y[emp0,train1,2] + 2*y[emp0,train0,2] + 2*y[emp1,train1,2] - (10000 + R[2,dept2]) : 0.0 : True
Теперь все дублирующие ограничения опущены.