I am trying to solve an assignment problem: A supervisor can be assigned to multiple consultants according to the number of languages a supervisor and a consultant speak (the more languages they have in common the better). The constraints are:
- each supervisor has a fixed number of hours that it can use to supervise, namely: 14, 11, 7, or 0 hour/s
- each consultant has a fixed number of hours that it can use to be supervised, namely: 6, 3, 2, 1, or 0 hour/s
- a supervisor can have multiple consultants to supervise according to the number of hours the supervisor is available (e.g. a supervisor with 14 hours can have 2 consultants with 6 hours and 2 with 1 hour, or just 1 with 6 hours, and so on. Not all the available hours of the supervisor have to be covered, while the hours of the consultant have to be all covered.)
- a supervisor, to be chosen, needs to have a seniority >= of the seniority of the consultant
supervisor_h = ... # number of hours of the availability per each supervisor
consultant_h = ... # number of hours needed per each consultant
y = pulp.LpVariable.dicts("pairs", [(i,j) for i in supervisors for j in consultants] ,cat='Binary')
prob = pulp.LpProblem("matching", pulp.LpMaximize)
prob += pulp.lpSum([costs[i][m] * y[(i,j)] for i in supervisors for m, j in enumerate(consultants)])
# each supervisor can have a number of consultants >= 1
for i in supervisors:
prob += pulp.lpSum(y[(i,j)] for j in consultants) >= 1
# each consultant can have only one supervisor
for j in consultants:
prob += pulp.lpSum(y[(i,j)] for i in supervisors) <= 1
# a supervisor can accept a consultant if the number of hours the supervisor still has available is >= than the number of hours requested by the consultant
# Here I have a problem in defining the constraint
for n, i in enumerate(supervisors):
prob += supervisor_h[n] - pulp.lpSum(qcee_h[m] for m, j in enumerate(consultants)) <= consultant_h[n]
# I have the same problem in defining the constraint for the seniority
It is the first time I use pulp, so if you can help me I appreciate it.
Use
matrixinstead ofdicts; use morelpDot; something like: