0% found this document useful (0 votes)
12 views1 page

Simulation Python Code

Uploaded by

shahdalmageed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Simulation Python Code

Uploaded by

shahdalmageed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import simpy

import random

def part(env, name, machine1, machine2):


arrival_time = env.now
print(f'{name} arrives at {arrival_time:.2f}')

# First processing at Machine 1


with machine1.request() as request:
yield request
processing_time = random.triangular(4.5, 9.3, 11)
yield env.timeout(processing_time)
print(f'{name} processed at Machine 1 for {processing_time:.2f} minutes')

# Processing at Machine 2
with machine2.request() as request:
yield request
processing_time = random.triangular(16.4, 19.1, 20.8)
yield env.timeout(processing_time)
print(f'{name} processed at Machine 2 for {processing_time:.2f} minutes')

# Second processing at Machine 1


with machine1.request() as request:
yield request
processing_time = random.triangular(4.5, 9.3, 11)
yield env.timeout(processing_time)
print(f'{name} processed again at Machine 1 for {processing_time:.2f}
minutes')

cycle_time = env.now - arrival_time


print(f'{name} exits the system at {env.now:.2f}, cycle time: {cycle_time:.2f}
minutes')

def setup(env, interarrival_time, machine1, machine2):


i = 0
while True:
yield env.timeout(random.expovariate(1.0 / interarrival_time))
i += 1
env.process(part(env, f'Part {i}', machine1, machine2))

# Initialize environment and resources


env = simpy.Environment()
machine1 = simpy.Resource(env, capacity=1)
machine2 = simpy.Resource(env, capacity=1)

# Setup and run the simulation


env.process(setup(env, 20, machine1, machine2))
env.run(until=20000)

You might also like