콘텐츠로 건너뛰기

파이썬 환경 다이어그램 사용 방법

[

Build your model: Create an environment and resources

In this Python tutorial, we will learn how to build a discrete-event simulation model to optimize the assembly line of an aircraft manufacturer. We will use the SimPy package to create an environment and manage resources.

Step 1: Define the Assembly Line Components

The main components of the aircraft assembly line are as follows:

  • Fuselage
  • Wings
  • Empennage (the tail end)
  • Power plant (engine and propeller)
  • Landing gear

Each component has a different number of slots in the assembly line. The number of slots for each component is as follows:

  • Fuselage: 3 slots
  • Wings: 2 slots
  • Empennage: 2 slots
  • Power plant: 3 slots
  • Landing gear: 3 slots

The assembly sequence must follow the order of Steps 1-4 as displayed in the following diagram:

Step 1: Fuselage
|
Step 2: Wings
|
Step 3: Power Plant
|
Step 4: Landing Gear

Step 2: Create the Discrete-Event Model

Now, let’s create the SimPy model to simulate the assembly line.

import simpy
# Define the process durations (in hours) for each step
process_durations = {
'step_1_fuselage': 20,
'step_2_wings': 8,
'step_3_power_plant': 10,
'step_4_landing_gear': 8
}
# Create the SimPy environment
env = simpy.Environment()
# Define the capacities (slots) for each step
capacities = {
'step_1_fuselage': 3,
'step_2_wings': 2,
'step_3_power_plant': 2,
'step_4_landing_gear': 3
}
# Create the resources for each step
step_1_fuselage = simpy.Resource(env, capacity=capacities['step_1_fuselage'])
step_2_wings = simpy.Resource(env, capacity=capacities['step_2_wings'])
step_3_power_plant = simpy.Resource(env, capacity=capacities['step_3_power_plant'])
step_4_landing_gear = simpy.Resource(env, capacity=capacities['step_4_landing_gear'])

In the above code, we defined the process durations for each step and created a dictionary called process_durations to store this information. We also created the SimPy environment (env) and defined the capacities of each step using the capacities dictionary. Finally, we created the resources for each step using the simpy.Resource class.

Step 3: Simulate the Assembly Line

Now that we have defined the environment and resources, let’s simulate the assembly line.

# Define the assembly line process
def assembly_line_process(env):
# Step 1: Fuselage
with step_1_fuselage.request() as request:
yield request
yield env.timeout(process_durations['step_1_fuselage'])
# Step 2: Wings
with step_2_wings.request() as request:
yield request
yield env.timeout(process_durations['step_2_wings'])
# Step 3: Power Plant
with step_3_power_plant.request() as request:
yield request
yield env.timeout(process_durations['step_3_power_plant'])
# Step 4: Landing Gear
with step_4_landing_gear.request() as request:
yield request
yield env.timeout(process_durations['step_4_landing_gear'])
# Run the simulation
env.process(assembly_line_process(env))
env.run()

In the above code, we defined the assembly_line_process function which represents the assembly line process. Inside the function, we used the request context manager to request the resources for each step. We then used the yield statement along with env.timeout to simulate the process duration for each step.

Finally, we used env.process to start the assembly line process and env.run to run the simulation.

Step 4: Analyze the Results

Once the simulation is complete, we can analyze the results to evaluate the performance of the assembly line.

# Analyze the results
print("Assembly line simulation results:")
print(f"Step 1 (Fuselage): Total wait time - {step_1_fuselage.wait_time}, Average wait time - {step_1_fuselage.wait_time/len(step_1_fuselage)}, Number of completed processes - {step_1_fuselage.queue}")
print(f"Step 2 (Wings): Total wait time - {step_2_wings.wait_time}, Average wait time - {step_2_wings.wait_time/len(step_2_wings)}, Number of completed processes - {step_2_wings.queue}")
print(f"Step 3 (Power Plant): Total wait time - {step_3_power_plant.wait_time}, Average wait time - {step_3_power_plant.wait_time/len(step_3_power_plant)}, Number of completed processes - {step_3_power_plant.queue}")
print(f"Step 4 (Landing Gear): Total wait time - {step_4_landing_gear.wait_time}, Average wait time - {step_4_landing_gear.wait_time/len(step_4_landing_gear)}, Number of completed processes - {step_4_landing_gear.queue}")

In the above code, we used the wait_time attribute and len function to calculate the total wait time, average wait time, and the number of completed processes for each step in the assembly line.

By analyzing these results, we can understand the performance of the assembly line and identify any bottlenecks or areas for improvement.

In this tutorial, we learned how to build a discrete-event simulation model for an aircraft assembly line using Python and SimPy. We created the environment, defined resources, simulated the assembly line, and analyzed the results.