Guitar4
In [1]:
import simpy
import random
In [2]:
guitars_made = 0
In [3]:
#Parameters
#working hours
hours = 8
#business days
days = 23
#total working time (hours)
total_time = hours * days
#containers
#wood
wood_capacity = 500
initial_wood = 200
#electronic
electronic_capacity = 100
initial_electronic = 60
#paint
body_pre_paint_capacity = 60
neck_pre_paint_capacity = 60
body_post_paint_capacity = 120
neck_post_paint_capacity = 120
#dispatch
dispatch_capacity = 500
In [4]:
#employees per activity
#body
num_body = 2
mean_body = 1
std_body = 0.1
#neck
num_neck = 1
mean_neck = 1
std_neck = 0.2
#paint
num_paint = 3
mean_paint = 3
std_paint = 0.3
#ensambling
num_ensam = 2
mean_ensam = 1
std_ensam = 0.2
In [5]:
#critical levels
#critical stock should be 1 business day greater than supplier take to come
wood_critial_stock = (((8/mean_body) * num_body +
(8/mean_neck) * num_neck) * 3) #2 days to deliver + 1 marging
electronic_critical_stock = (8/mean_ensam) * num_ensam * 2 #1 day to deliver + 1 marging
In [6]:
class Guitar_Factory:
def __init__(self, env):
self.wood = simpy.Container(env, capacity = wood_capacity, init = initial_wood)
self.wood_control = env.process(self.wood_stock_control(env))
self.electronic = simpy.Container(env, capacity = electronic_capacity, init = initial_electronic)
self.electronic_control = env.process(self.electronic_stock_control(env))
self.body_pre_paint = simpy.Container(env, capacity = body_pre_paint_capacity, init = 0)
self.neck_pre_paint = simpy.Container(env, capacity = neck_pre_paint_capacity, init = 0)
self.body_post_paint = simpy.Container(env, capacity = body_post_paint_capacity, init = 0)
self.neck_post_paint = simpy.Container(env, capacity = neck_post_paint_capacity, init = 0)
self.dispatch = simpy.Container(env ,capacity = dispatch_capacity, init = 0)
self.dispatch_control = env.process(self.dispatch_guitars_control(env))
def wood_stock_control(self, env):
yield env.timeout(0)
while True:
if self.wood.level <= wood_critial_stock:
print('wood stock bellow critical level ({0}) at day {1}, hour {2}'.format(
self.wood.level, int(env.now/8), env.now % 8))
print('calling wood supplier')
print('----------------------------------')
yield env.timeout(16)
print('wood supplier arrives at day {0}, hour {1}'.format(
int(env.now/8), env.now % 8))
yield self.wood.put(300)
print('new wood stock is {0}'.format(
self.wood.level))
print('----------------------------------')
yield env.timeout(8)
else:
yield env.timeout(1)
def electronic_stock_control(self, env):
yield env.timeout(0)
while True:
if self.electronic.level <= electronic_critical_stock:
print('electronic stock bellow critical level ({0}) at day {1}, hour {2}'.format(
self.electronic.level, int(env.now/8), env.now % 8))
print('calling electronic supplier')
print('----------------------------------')
yield env.timeout(9)
print('electronic supplier arrives at day {0}, hour {1}'.format(
int(env.now/8), env.now % 8))
yield self.electronic.put(30)
print('new electronic stock is {0}'.format(
self.electronic.level))
print('----------------------------------')
yield env.timeout(8)
else:
yield env.timeout(1)
def dispatch_guitars_control(self, env):
global guitars_made
yield env.timeout(0)
while True:
if self.dispatch.level >= 50:
print(‘dispach stock is {0}, calling store to pick guitars at day {1}, hour {2}’.format(
self.dispatch.level, int(env.now/8), env.now % 8))
print(‘———————————-‘)
yield env.timeout(4)
print(‘store picking {0} guitars at day {1}, hour {2}’.format(
self.dispatch.level, int(env.now/8), env.now % 8))
guitars_made += self.dispatch.level
yield self.dispatch.get(self.dispatch.level)
print(‘———————————-‘)
yield env.timeout(8)
else:
yield env.timeout(1)
In [7]:
def body_maker(env, guitar_factory):
while True:
yield guitar_factory.wood.get(1)
body_time = random.gauss(mean_body, std_body)
yield env.timeout(body_time)
yield guitar_factory.body_pre_paint.put(1)
def neck_maker(env, guitar_factory):
while True:
yield guitar_factory.wood.get(1)
neck_time = random.gauss(mean_neck, std_neck)
yield env.timeout(neck_time)
yield guitar_factory.neck_pre_paint.put(2)
def painter(env, guitar_factory):
while True:
yield guitar_factory.body_pre_paint.get(5)
yield guitar_factory.neck_pre_paint.get(5)
paint_time = random.gauss(mean_paint, std_paint)
yield env.timeout(paint_time)
yield guitar_factory.body_post_paint.put(5)
yield guitar_factory.neck_post_paint.put(5)
def assembler(env, guitar_factory):
while True:
yield guitar_factory.body_post_paint.get(1)
yield guitar_factory.neck_post_paint.get(1)
yield guitar_factory.electronic.get(1)
assembling_time = max(random.gauss(mean_ensam, std_ensam), 1)
yield env.timeout(assembling_time)
yield guitar_factory.dispatch.put(1)
In [8]:
#Generators
def body_maker_gen(env, guitar_factory):
for i in range(num_body):
env.process(body_maker(env, guitar_factory))
yield env.timeout(0)
def neck_maker_gen(env, guitar_factory):
for i in range(num_neck):
env.process(neck_maker(env, guitar_factory))
yield env.timeout(0)
def painter_maker_gen(env, guitar_factory):
for i in range(num_paint):
env.process(painter(env, guitar_factory))
yield env.timeout(0)
def assembler_maker_gen(env, guitar_factory):
for i in range(num_ensam):
env.process(assembler(env, guitar_factory))
yield env.timeout(0)
In [13]:
env = simpy.Environment()
guitar_factory = Guitar_Factory(env)
In [14]:
body_gen = env.process(body_maker_gen(env, guitar_factory))
neck_gen = env.process(neck_maker_gen(env, guitar_factory))
painter_gen = env.process(painter_maker_gen(env, guitar_factory))
assembler_gen = env.process(assembler_maker_gen(env, guitar_factory))
In [15]:
env.run(until = total_time)
electronic stock bellow critical level (31) at day 2, hour 6
calling electronic supplier
———————————-
electronic supplier arrives at day 3, hour 7
new electronic stock is 43
———————————-
dispach stock is 50, calling store to pick guitars at day 4, hour 2
———————————-
store picking 57 guitars at day 4, hour 6
———————————-
electronic stock bellow critical level (29) at day 4, hour 7
calling electronic supplier
———————————-
wood stock bellow critical level (71) at day 5, hour 3
calling wood supplier
———————————-
electronic supplier arrives at day 6, hour 0
new electronic stock is 42
———————————-
electronic stock bellow critical level (26) at day 7, hour 0
calling electronic supplier
———————————-
wood supplier arrives at day 7, hour 3
new wood stock is 324
———————————-
dispach stock is 50, calling store to pick guitars at day 8, hour 0
———————————-
electronic supplier arrives at day 8, hour 1
new electronic stock is 39
———————————-
store picking 58 guitars at day 8, hour 4
———————————-
electronic stock bellow critical level (25) at day 9, hour 1
calling electronic supplier
———————————-
electronic supplier arrives at day 10, hour 2
new electronic stock is 38
———————————-
electronic stock bellow critical level (23) at day 11, hour 2
calling electronic supplier
———————————-
dispach stock is 51, calling store to pick guitars at day 12, hour 0
———————————-
electronic supplier arrives at day 12, hour 3
new electronic stock is 37
———————————-
store picking 57 guitars at day 12, hour 4
———————————-
electronic stock bellow critical level (22) at day 13, hour 3
calling electronic supplier
———————————-
electronic supplier arrives at day 14, hour 4
new electronic stock is 37
———————————-
electronic stock bellow critical level (21) at day 15, hour 4
calling electronic supplier
———————————-
dispach stock is 50, calling store to pick guitars at day 15, hour 7
———————————-
store picking 58 guitars at day 16, hour 3
———————————-
electronic supplier arrives at day 16, hour 5
new electronic stock is 35
———————————-
electronic stock bellow critical level (20) at day 17, hour 5
calling electronic supplier
———————————-
wood stock bellow critical level (69) at day 18, hour 0
calling wood supplier
———————————-
electronic supplier arrives at day 18, hour 6
new electronic stock is 33
———————————-
electronic stock bellow critical level (18) at day 19, hour 6
calling electronic supplier
———————————-
dispach stock is 50, calling store to pick guitars at day 19, hour 6
———————————-
wood supplier arrives at day 20, hour 0
new wood stock is 321
———————————-
store picking 57 guitars at day 20, hour 2
———————————-
electronic supplier arrives at day 20, hour 7
new electronic stock is 32
———————————-
electronic stock bellow critical level (16) at day 21, hour 7
calling electronic supplier
———————————-
In [16]:
print(‘Pre paint has {0} bodies and {1} necks ready to be painted’.format(
guitar_factory.body_pre_paint.level, guitar_factory.neck_pre_paint.level))
print(‘Post paint has {0} bodies and {1} necks ready to be assembled’.format(
guitar_factory.body_post_paint.level, guitar_factory.neck_post_paint.level))
print(f’Dispatch has %d guitars ready to go!’ % guitar_factory.dispatch.level)
print(f’———————————-‘)
print(‘total guitars made: {0}’.format(guitars_made + guitar_factory.dispatch.level))
print(f’———————————-‘)
print(f’SIMULATION COMPLETED’)
Pre paint has 0 bodies and 2 necks ready to be painted
Post paint has 26 bodies and 26 necks ready to be assembled
Dispatch has 40 guitars ready to go!
———————————-
total guitars made: 618
———————————-
SIMULATION COMPLETED
In [ ]: