0

I want assign tasks to workers in a way that cost is minimized given a time constraint.

Suppose:

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

How can I solve this problem using Python? Are there any libraries to solve such problems?

Edit: Objective:

Minimize:

Cost = 20 * ith_labor_time + 30 * jth_Machine_time + 15 * kth_Machine_Operator_time

Now the constraints:

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)

Practical Example:

Suppose we have total_labor = 3, total_machines = 3 and 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

Next each labor can work for 8 hours similarly each machinery can work for 8 hours and same for the machine operator they can work for 8 hours.

Task needs to be completed in 8 hours and 1000kg load needs to be processed.

My formulation:

    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)

Code

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')
Lopez
  • 461
  • 5
  • 19
  • This is just linear programming, and you can solve it by supplying your data to [`scipy.optimize.linprog`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linprog.html). – Stef Sep 16 '21 at 09:55
  • Will it be solved by simplex method? I am having trouble defining constraints. Any source where such problem has been solved using Python? – Lopez Sep 16 '21 at 10:03
  • 1
    What are you having trouble with specifically? Introduce a variable for used labor time, a variable for used machine time, then write the equations and inequations, for instance 0 <= labor_time <= 10, 0 <= machine_time <= 5, 0 <= machine_time <= 3, etc – Stef Sep 16 '21 at 10:12
  • 1
    Make sure you have the linear problem well described with pen and paper before you start writing python code. – Stef Sep 16 '21 at 10:13
  • I've made an edit containing objective function and constraints. There are 2 constraints I can't make can you help with that? Also is there any constraint I am missing? – Lopez Sep 16 '21 at 10:33
  • I think you should edit your questions to explain more clearly what the constraints mean. I think your constraints 1,2,3 are not consistent with contraint 4, but I don't fully understand the constraints you've listed at the beginning of your question (and I suspect that you are slightly confused about those constraints too). For instance, what does "Total Labor: 10" mean? What does "Total Hours: 8" mean? Does that mean you have 10 workers, who can work 8 hours each? It's not very clear. You need to clarify this before you can write inequations. – Stef Sep 16 '21 at 10:38
  • I've made edits. yes, it means I have 10 workers who can work 8 hours each. – Lopez Sep 16 '21 at 11:01
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/237175/discussion-between-lopez-and-stef). – Lopez Sep 16 '21 at 11:30

0 Answers0