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.
"Period_used_no_more_than_once_{}".format(period)instead of"Period_used_no_more_than_once". Also, see this