I'm trying to solve a problem using Johnson's rule in GEKKO but unfortunately with no luck. It can easily be solved in excel, but I am trying to do it in python.
The problem:
there are two machines (Machine T and Machine K) that work one after the other. A product must go through machine T first and after that through Machine K. both machines can work simultaneously, but each machine cant work on more than 1 product at a time. the factory needs to minimize the time of production of all given products (i.e. minimize the idle time of machine k)
Products time for each machine:
T. K. 1. 10 20 2. 20 30 3. 15 10 4. 40 25 5. 8 18
Steps to solve:
from Gekko import GEKKO
m = GEKK()
T = { 1: 10, 2: 20, 3: 15, 4: 40, 5: 8 }
K = { 1: 20, 2: 30, 3: 10, 4: 25, 5: 18 }
x = [m.Var(lb=1,ub=5,integer=True) for i in range(5)]
Now some variables needs to be dependent on previous variables like so:
idle1 = T[x[0]]
idle2 = T[x[1]] - K[x[0]]
idle3 = T[x[2]] - idle2 + m.if2(idle2<0, idle2, 0)
...
...
This creates an issue because python is trying to hash T[x[0]] but x[0] is not a number rather a Gekko variable. How can I bypass this issue?
any ideas?