Hi,
I have set up 10 machines as resources. Each machine has slightly different processing times. Each machine has 4 load ports, which can be loaded with material at the same time or any time as long as a port is free.
Boxes of material (we call them 'lots') can queue for the machines and should get loaded onto a free load port. When material is finished on a load port, it can be removed, independently of the other load ports on that machine.
I was trying the AnyOf functionality to determine if any machine has a free port, so I can then load material onto it, but I've been struggling with the code for a day at this stage and I'm thinking maybe I should try some other method of doing this.
Here's some of the code I've been playing with:
import sys
import os
import random
from random import expovariate, uniform, randint
import simpy
from simpy.events import AnyOf, AllOf
class Machine(object):
def __init__(self, env, name, load_ports):
self.env = env
self.name = name
self.machine = simpy.Resource(env, load_ports)
def lot(env, idnumber, tools):
requests = [tool.machine.request() for tool in tools]
request = AnyOf(env, requests)
yield request
# I only need 1 load port. Do I need to release all the other load ports?
env.timeout(expovariate(1/45.0)
# How do I figure out which machine had the free load port so I can record metrics on it?
# How do I release the resource now that I am finished with it?
def setup(env):
step64 = Machine(env, '64LGROUP', 4)
step65 = Machine(env, '65LGROUP', 4)
step66 = Machine(env, '66LGROUP', 4)
step67 = Machine(env, '67LGROUP', 4)
step68 = Machine(env, '68LGROUP', 4)
step69 = Machine(env, '69LGROUP', 4)
step610 = Machine(env, '610LGRP', 4)
step611 = Machine(env, '611LGRP', 4)
step612 = Machine(env, '612LGRP', 4)
step613 = Machine(env, '613LGRP', 4)
tools = [step64, step65, step66, step67, step68, step69, step610, step611, step612, step613]
lots = []
for i in range(100):
lots.append(env.process(lot(env, idnumber=i, tools=tools)))
yield env.timeout(5.0)
if __name__ == '__main__':
env = simpy.Environment()
env.process(setup(env))
env.run(until=1440 * 1)
My questions are:
1. How do I know which machines (resources) I have gotten hold of?
2. Is it possible that I could get hold of all 10 resources, even though I only want one?
3. If I have hold of multiple resources, how do I release them?
Thanks,
Adrian.