Home>
I would like to create a shift using pulp.
Using the following data, I would like to create an objective function that minimizes the difference between the desired number of working days for part-time jobs and the actual number of working days.
#List of dates
day = pd.date_range ("2019-12-01", "2019-12-07")
#A set of part-time jobs
n_member = 10
member = pd.Series (f "member {i + 1}" for i in range (n_member))
#List of shifts
shift = (["9: 00-14: 00", "14: 00-19: 00", "19: 00-23: 00", "rest"])
# Desired attendance date
kibou = pd.DataFrame ([[1, 1, 1, 1, 1, 0, 0],
[1, 1, 1, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 1, 1],
[0, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 0, 1, 0, 0]],
index = member,
columns = day)
I created the following program, but an error occurred.
# Create model
prob = LpProblem (sense = LpMinimize)
#variable
x = [[[LpVariable (f "x {m} {d} {t}", cat = LpBinary) for t in shift]
for d in day] for m in member]
#Objective function
obj = 0
for m in range (member.size):
# Desired attendance days
ks = kibou.sum (axis = 1)
#Actual days worked
actual = lpSum (x [m] [j] for j in range (day.size))
#Difference between the desired number of working days and the actual number of working days
obj = ks-actual
# (Restriction 1) Constraint that the actual working days do not exceed the desired number of working days
prob + = actual<= ks
prob + = obj
TypeError: Can only add LpConstraintVar, LpConstraint, LpAffineExpression or True objects
Please tell me how to create a model.
-
Answer # 1
Related articles
- i don't understand the exercises using python trigonometric functions
- python 3x - i want to get the nth array with an argument using python3 argparse
- parameter estimation using python's weighted least squares method (wls)
- parallel processing using python multiprocessingpool and multiprocessingqueue does not work well
- about external libraries when using multiple versions of python
- python - i want to separate by a specific word using the split function
- python - image recognition using cnn keras multiple inputs
- regarding programming creation using a fun function in addition to the main function
- about batch change of file name using python
- python 3x - how to rename a folder created using jupyternotebook
- python - i'm using selenium the text sent by send_keys to the input tag disappears when the text is sent by send_key to the next
- python 3x - processing to jump to the link destination using chrome driver in python
- python - error in image binarization using cv2adaptivethreshold function
- i want to adjust the execution result using the while statement in python as expected
- python - i want to put the image file path in a variable and open it using that variable
- python - aggregation processing using pandas
- specifying the range of the graph using python date
- python - about the fibonacci sequence using recursion
- about data acquisition using python from becoming a novelist
- please explain the function using the python dictionary
Trends
codeks = kibou.sum (axis = 1)
, the variableks
is a Series object, not an integer.Shouldn't we calculate the total number of working days for each member as
ks = kibou.iloc [m] .sum ()
?