How To Fix Constraints For Allocation Optimisation In Pulp Python
Background: I am trying to allocate customers Ci to financial advisers Pj. Each customer has a policy value xi. I'm assuming that the number of customers (n) allocated to each advi
Solution 1:
Some hints:
- Debug by
print(model)
- Start with a small data set
The constraints are not correctly formulated. It should be something like
forjin set_J: model += 1.0e-6 * pulp.lpSum(y_vars[i,j] * x[i] foriin set_I) <= z_max # constraint 1 model += 1.0e-6 * pulp.lpSum(y_vars[i,j] * x[i] foriin set_I) >= z_min # constraint 2 model += pulp.lpSum(y_vars[i,j] foriin set_I) == n #constraint 4foriin set_I: model += pulp.lpSum(y_vars[i,j] forjin set_J) == 1 # constraint 3
- The model will be infeasible if
n*p <> c
- Detail: we should probably rewrite constraints 1 and 2. Repeating long summations will create a large number of nonzero elements.
- The model will be infeasible if
Solution 2:
I don't think you can use that format to add constraints. Try this format instead:
forjin set_J:
model += pulp.lpSum([y_vars[i,j] * x[i] foriin set_I]) <= z_max
etc.
Note also the [...]
inside the lpSum(...)
.
Finally, I don't think you can declare variables the way you did. I usually use LpVariable.dicts()
, as in:
y_vars = pulp.lpVariable.dicts('y_vars', set_I, 0, 1, pulp.LpInteger)
Post a Comment for "How To Fix Constraints For Allocation Optimisation In Pulp Python"