我有工人时间、班次和工资率的基本情况(如下所述)。我了解如何将其作为线性规划问题来解决,但我如何使用 SciPy Optimize 来解决/最小化支付给工人的金额?
import pandas as pd
import numpy as np
import scipy.optimize as sco
from io import StringIO
with StringIO(
'''Time Windows,Shift 1,Shift 2,Shift 3,Shift 4,Workers Required
6:00 - 9:00, 1, 0, 0, 1, 55.0
9:00 - 12:00, 1, 0, 0, 0, 46.0
12:00 - 15:00, 1, 1, 0, 0, 59.0
15:00 - 18:00, 0, 1, 0, 0, 23.0
18:00 - 21:00, 0, 1, 1, 0, 60.0
21:00 - 24:00, 0, 0, 1, 0, 38.0
24:00 - 3:00, 0, 0, 1, 1, 20.0
3:00 - 6:00, 0, 0, 0, 1, 30.0
Wage_Rate, 135, 140, 190, 188, 0.0''') as f:
df = pd.read_csv(f, skipinitialspace=True, index_col='Time Windows')
is_shift = df.columns.str.startswith('Shift')
is_wage = df.index == 'Wage_Rate'
shifts = df.loc[~is_wage, is_shift]
wage_rate = df.loc[is_wage, is_shift].squeeze()
workers_req = df.loc[~is_wage, 'Workers Required']
# create arrays
min_wages = wage_rate.values
min_workers = workers_req.values
# add constraints
constraints = (min_workers, min_wages)
# min 0 workers and increase in 10% increments up to 100%
# there is no 10% of a worker, but .1 could be multiplied by 'workers_req'
bound = (0.0,.1)
bounds = tuple(bound for item in range(min_workers))
result = sco.minimize(method='SLSQP', bounds=bounds, constraints=constraints)
一切都可以编译,直到最后两行代码。当我尝试将“边界”设置为“min_workers”时,出现此错误。