You should always start with a very simple (and wrong) implementation just to get a better understanding of your use-case and a feeling how everything works, e.g.:
import simpy
def paint_walls(env, interval):
while True:
yield env.timeout(interval)
print('yr %2d: paint walls' % env.now)
def replace_dry_lining(env, interval):
while True:
yield env.timeout(interval)
print('yr %d: replace dry-lining' % env.now)
env = simpy.Environment()
env.process(paint_walls(env, interval=5))
env.process(replace_dry_lining(env, interval=14))
env.run(until=20)
Output:
yr 5: paint walls
yr 10: paint walls
yr 14: replace dry-lining
yr 15: paint walls
Then you can start extending/modifying your simulation. Here are two possibilities how your problem can be modeled:
Variant A
We keep using two separate processes but need a way to exchange the event "dry-lining replaced" between them, so that we can also paint the wall:
import simpy
class Maintenance:
PAINT_WALL_INTERVAL = 5
REPLACE_DRY_LINING_INTERVAL= 14
def __init__(self, env):
self.env = env
self.dry_lining_replaced = env.event()
self.p_paint_walls = env.process(self.paint_walls())
self.p_replace_dry_lining = env.process(self.replace_dry_lining())
def paint_walls(self):
timeout = self.PAINT_WALL_INTERVAL
while True:
yield self.env.timeout(timeout) | self.dry_lining_replaced
print('yr %2d: paint walls' % self.env.now)
def replace_dry_lining(self):
timeout = self.REPLACE_DRY_LINING_INTERVAL
while True:
yield self.env.timeout(timeout)
print('yr %2d: replace dry-lining' % self.env.now)
self.dry_lining_replaced.succeed()
self.dry_lining_replaced = self.env.event()
env = simpy.Environment()
m = Maintenance(env)
env.run(until=20)
Output:
yr 5: paint walls
yr 10: paint walls
yr 14: replace dry-lining
yr 14: paint walls
yr 19: paint walls
Variant B
We can also model it with just one process that waits for either a "paint walls" or a "replace dry-lining" event:
import simpy
def maintenance(env):
PAINT_WALL_INTERVAL = 5
REPLACE_DRY_LINING_INTERVAL = 14
paint_wall = env.timeout(PAINT_WALL_INTERVAL)
replace_dry_lining = env.timeout(REPLACE_DRY_LINING_INTERVAL)
while True:
results = yield paint_wall | replace_dry_lining
do_paint = paint_wall in results
do_replace = replace_dry_lining in results
if do_replace:
print('yr %2d: replace dry-lining' % env.now)
replace_dry_lining = env.timeout(REPLACE_DRY_LINING_INTERVAL)
if do_paint or do_replace:
print('yr %2d: paint walls' % env.now)
paint_wall = env.timeout(PAINT_WALL_INTERVAL)
env = simpy.Environment()
env.process(maintenance(env))
env.run(until=20)
Output:
yr 5: paint walls
yr 10: paint walls
yr 14: replace dry-lining
yr 14: paint walls
yr 19: paint walls