I am trying to solve a shift scheduling optimisation problem in Python that is slightly different from the one outlined in this article. The only issue is I can't use the pulp
package as it is not a linear problem.
From what I understand, the best way to solve my problem is to use the scipy.optimize
package, however I am having difficulties translating the following problem formulation into actual code. The inputs are straightforward (two arrays) and the goal is to minimize a function with a constraint.
Problem formulation
- Dimensions:
i=1...T
(hours of the day),j=1...n
(total number of multi-hour shifts for the day) - Inputs:
a[i,j]
(two-dimensional array storing the shift configuration) andd[i]
(expected demand for the houri
) - Output: the script must return the optimal number of workers required for each shift
w[j]
- Minimization: we want to minimize the total cost of workers for the day. What makes the problem slightly more complicated is the cost per hour
c[i]
is a function ofw[j]
(we don't pay the same hourly wage if there are too many workers):min(sum c[i])
(i=1...T) wherec[i] = d[i]^2 / sum(a[i,j]*w[j])
(j=1...n). - Constraint: for all i,
sum a[i,j] w[j] >= d[i]
(to ensure workers can meet the level of demand for each hour)
Code
w = pulp.LpVariable.dicts("num_workers", list(range(n)), lowBound=0, cat="Integer")
pulp.lpSum([(d[i]^2 / pulp.lpSum([a[i,j] * w[j] for j in range(n)])) for i in range(T)])
TypeError: unsupported operand type(s) for /: 'int' and 'LpAffineExpression'
Could anyone give me some hints on how to turn the following problem into an actual code understandable by SciPi? Thanks!