我希望在给定时间限制的情况下以最小化成本的方式将任务分配给工人。
认为:
Labor Cost: $20/hr and handles 10Kg
Machine Cost: $30/hr and handles 20Kg and requires a Machine Operator
Machine Operator Cost: 15$/hr
Constraints:
Total Available Labor = 10
Total Available Machines = 5
Total Available Machine Operator = 3
Total Required Load to Handle = 1000Kg
Total Available Hours to complete Task = 8
如何使用 Python 解决这个问题?有没有解决此类问题的库?
编辑:目标:
最小化:
Cost = 20 * ith_labor_time + 30 * jth_Machine_time + 15 * kth_Machine_Operator_time
现在的约束:
1) 0 <= i(total_labor) <= 10
2) 0 <= j(total_machine) <= 5 (Not 5 because only 3 operators available and machine is dependent on operator)
3) 0 <= k(total_machine_operator_time) <= 3
4) sum(ith_labor_time <= 80)
5) sum(ith_machine_time <= 40)
5) sum(ith_Operator_time) - sum(ith_Machine_time) = 0
6) constraint that total weight handled is 1000kg (unable to make this constraint)
7) machine_time and operator_time are dependent on each other as 1 machine requires 1 operator (I believe this is handled in constraint 5)
实际例子:
假设我们有total_labor = 3
和total_machines = 3
total_operators = 3
Cost per labor/hr = $20
Cost per machinery/hr = $30
Cost per operator/hr = $15
Labor process rate/hr = 10 Kg
Machine process rate/hr = 20 Kg
接下来每个劳动力可以工作 8 小时,同样,每台机器可以工作 8 小时,机器操作员也可以工作 8 小时。
任务需要在8小时内完成,需要处理1000公斤的负载。
我的配方:
Min:
Cost = 20*L1 + 20*L2 + 20*L3 + 30*M1 + 30*M2 + 30*M3 + 15*O1 + 15*O2 + 15*O3
Constraints:
L1 + L2 + L3 <= 24 (if each labor work simultaneously they can total up to 24hrs)
L1 <= 8
L2 <= 8
L3 <= 8
M1 + M2 + M3 <= 24 (if each machinery works simultaneously they can total up to 24hrs)
M1 <= 8
M2 <= 8
M3 <= 8
M1 + M2 + M3 - O1 - O2 - O3 = 0 (Each machinery requires an operator)
10*L1 + 10*L2 + 10*L3 + 20*M1 + 20*M2 + 20*M3 = 1000 (Total load to be processed = 1000 Kg)
代码
from scipy.optimize import linprog
c = [20, 20, 20, 30, 30, 30, 15, 15, 15]
A = [[1, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 1, -1, -1, -1]]
A1 = [[10, 10, 10, 20, 20, 20, 0, 0, 0]]
b = [24, 24, 8, 8, 8, 8, 8, 8, 0]
b2 = [1000]
res = linprog(c, A_ub=A, A_eq=A1, b_ub=b, b_eq=b2, method='revised simplex')