如何设置纸浆约束的优先级

时间:2019-04-20 08:00:11

标签: python pulp

in_source[(i,k,m)] = 1, If job i is assigned to truck k as
the mth job, , otherwise 0.

out_source[i]. If job i is outsourced to companies (subscript 0 represents other transportation companies), otherwise, 0


Xikm = [(i, k, m) for i in all_job for k in all_vehicles for m in all_job_vehicle]

in_source = LpVariable.dicts("InSource", Xikm, 0, 1, LpBinary)

Xi0 = [i for i in all_job]

out_source = LpVariable.dicts("OutSource", Xi0, 0, 1, LpBinary)

# Objective Function
prob += lpSum(In_source_cost[i] * in_source[(i, k, m)] for i in all_job for k in all_vehicles for m in all_job_vehicle) 
\
        + lpSum(Out_source_cost[i] * out_source[i] for i in all_job)

约束1:

for i in all_job:
    prob += lpSum(in_source[(i, k, m)] for k in all_vehicles for m in all_job_vehicle) + out_source[i] == 1

约束2:

for m in all_job_vehicle:
    for k in all_vehicles:
        prob += lpSum(in_source[(i, k, m + 1)] for i in all_job) <= lpSum(in_source[(i, k, m)] for i in all_job) <= 1

when i run, the result is
Traceback (most recent call last):
  File "D:/code_thu_ntn/trial.py", line 131, in <module>
    prob += lpSum(in_source[(i, k, m + 1)] for i in all_job) <= lpSum(in_source[(i, k, m)] for i in all_job) <= 1
  File "C:\Users\Asus\AppData\Roaming\Python\Python37\site-packages\pulp\pulp.py", line 1998, in lpSum
    return LpAffineExpression().addInPlace(vector)
  File "C:\Users\Asus\AppData\Roaming\Python\Python37\site-packages\pulp\pulp.py", line 715, in addInPlace
    for e in other:
  File "D:/code_thu_ntn/trial.py", line 131, in <genexpr>
    prob += lpSum(in_source[(i, k, m + 1)] for i in all_job) <= lpSum(in_source[(i, k, m)] for i in all_job) <= 1
KeyError: (0, 0, 3)

你能帮我吗?

0 个答案:

没有答案