CS代考 Guitar1

Guitar1

In [2]:

import simpy
import random

In [3]:

#Parameters

#working hours
hours = 8

#business days
days = 5

#total working time (hours)
total_time = hours * days

#containers
#wood
wood_capacity = 1000
initial_wood = 500

#dispatch
dispatch_capacity = 500

In [4]:

class Guitar_Factory:
def __init__(self, env):
self.wood = simpy.Container(env, capacity = wood_capacity, init = initial_wood)
self.dispatch = simpy.Container(env ,capacity = dispatch_capacity, init = 0)

In [5]:

def body_maker(env, guitar_factory):
while True:
yield guitar_factory.wood.get(1)
body_time = 1
yield env.timeout(body_time)
yield guitar_factory.dispatch.put(1)

In [6]:

def neck_maker(env, guitar_factory):
while True:
yield guitar_factory.wood.get(1)
neck_time = 1
yield env.timeout(neck_time)
success = random.randint(0,100)
if success > 30:
yield guitar_factory.dispatch.put(2)
elif success > 10:
yield guitar_factory.dispatch.put(1)

In [13]:

env = simpy.Environment()
guitar_factory = Guitar_Factory(env)

In [14]:

body_maker_process = env.process(body_maker(env, guitar_factory))
neck_maker_process = env.process(neck_maker(env, guitar_factory))

In [15]:

env.run(until = total_time)

In [16]:

print(‘Dispatch has %d bodies and necks ready to go!’ % guitar_factory.dispatch.level)
print(‘———————————-‘)
print(‘SIMULATION COMPLETED’)

Dispatch has 102 bodies and necks ready to go!
———————————-
SIMULATION COMPLETED

In [17]:

print(guitar_factory.wood.level)

420

In [ ]: