0

I have a set partitioning problem that requires each available period to be used only once.

def solve (slots, reqs, periods):
    # binary variable to id if combination is used
    x = pulp.LpVariable.dicts('slot', slots, lowBound=0, upBound=1, cat=pulp.LpInteger)

    # linear program problem
    sked_model = pulp.LpProblem("NLE Specials Scheduling Model", pulp.LpMaximize)

    # objective function
    sked_model += sum([x[slot] for slot in slots]), "Slot selection" # all combinations considered equal

    # Supply maximum number of slots
    sked_model += sum([x[slot] for slot in slots]) == len(reqs), "Number_of_slots to sked"

ERROR OCCURS HERE

    # A period can only be used once
    for period in periods:
        sked_model += sum([x[slot] for slot in slots if period == slot[0:2]]) <= 1, "Period_used_no_more_than_once" 

    # The problem is solved using PuLP’s choice of Solver
    sked_model.solve()

The error received is "pulp.constants.PulpError: overlapping constraint names:" on the # period can only be used once constraint.

1
  • 2
    The problem is that you give the same name to different constraints. Try "Period_used_no_more_than_once_{}".format(period) instead of "Period_used_no_more_than_once". Also, see this Commented Apr 16, 2018 at 20:56

1 Answer 1

0

Solved this.

The error came from the constraint name, "Period_used_no_more_than_once", being used more than once when the constraints were built. By replacing that name with "", the constraint worked as desired.

New constraint:

for period in periods: sked_model += sum([x[slot] for slot in slots if period == slot[0:2]]) <= 1, ""

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.