Skip to content Skip to sidebar Skip to footer

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:

  1. Debug by print(model)
  2. Start with a small data set
  3. 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
    1. The model will be infeasible if n*p <> c
    2. Detail: we should probably rewrite constraints 1 and 2. Repeating long summations will create a large number of nonzero elements.

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"