Pular para o conteúdo

Como usar o diagrama de ambiente no Python?

[

Environment Diagram In Python

Introduction to Dynamic Systems and Discrete-Event Simulation Models

  • Identify problems where discrete-event simulations can be helpful in supporting management and decision-making.
  • Understand the main components of discrete-event models and how to interpret model outputs.

Developing Discrete-Event Models Using SimPy

  • Learn how to build a SimPy model environment and add processes and resources.
  • Explore different types of resources available and options to control and schedule events.
  • Build a complete SimPy model for an aircraft assembly line.

Introduction to the SimPy package

import simpy
# create a SimPy environment
env = simpy.Environment()
# define processes and resources
# run simulation
env.run(until=100)

Building a car washer model with SimPy

import simpy
def car_washer(env):
while True:
# washing process
yield env.timeout(10)
env = simpy.Environment()
env.process(car_washer(env))
env.run(until=100)

Modeling a car production line: Python generators

import simpy
def car_production(env):
yield env.timeout(10)
# production process
env = simpy.Environment()
env.process(car_production(env))
env.run(until=100)

Modeling a car production line: Create and run the model

import simpy
def car_production(env):
while True:
yield env.timeout(10)
# production process
env = simpy.Environment()
env.process(car_production(env))
env.run(until=100)

SimPy package: Types of resources

import simpy
def car_production(env, resource):
with resource.request() as req:
yield req
# production process
env = simpy.Environment()
resource = simpy.Resource(env, capacity=1)
env.process(car_production(env, resource))
env.run(until=100)

Identify appropriate SimPy resources

import simpy
def car_production(env, resource):
with resource.request() as req:
yield req
# production process
env = simpy.Environment()
resource = simpy.Resource(env, capacity=1)
env.process(car_production(env, resource))
env.run(until=100)

Managing payment queues

import simpy
def petrol_station(env, resource):
with resource.request() as req:
yield req
# petrol station process
env = simpy.Environment()
resource = simpy.Resource(env, capacity=1)
env.process(petrol_station(env, resource))
env.run(until=100)

Modeling a petrol station: Run the model and analyze the results

import simpy
def petrol_station(env, resource):
with resource.request() as req:
yield req
# petrol station process
env = simpy.Environment()
resource = simpy.Resource(env, capacity=1)
env.process(petrol_station(env, resource))
env.run(until=100)

SimPy Package: Managing the scheduling of events

import simpy
def restaurant(env, resource):
with resource.request() as req:
yield req
# restaurant process
env = simpy.Environment()
resource = simpy.Resource(env, capacity=1)
env.process(restaurant(env, resource))
env.run(until=100)

Restaurant model: Managing tables and waiting times

import simpy
def restaurant(env, resource):
with resource.request() as req:
yield req
# restaurant process
env = simpy.Environment()
resource = simpy.Resource(env, capacity=1)
env.process(restaurant(env, resource))
env.run(until=100)

Restaurant model: Set up, run and analyze results

import simpy
def restaurant(env, resource):
with resource.request() as req:
yield req
# restaurant process
env = simpy.Environment()
resource = simpy.Resource(env, capacity=1)
env.process(restaurant(env, resource))
env.run(until=100)

Building a discrete-event model with SimPy

import simpy
def example_process(env):
while True:
yield env.timeout(10)
# process
env = simpy.Environment()
env.process(example_process(env))
env.run(until=100)

Build your model: Create an environment and resources

import simpy
# create a SimPy environment
env = simpy.Environment()
# define processes and resources
# run simulation
env.run(until=100)

Build your model: Generate aircraft orders

import simpy
def generate_orders(env):
while True:
yield env.timeout(10)
# generate aircraft orders
env = simpy.Environment()
env.process(generate_orders(env))
env.run(until=100)

Build your model: Control assembly line response

import simpy
def assembly_line(env, resource):
with resource.request() as req:
yield req
# assembly line process
env = simpy.Environment()
resource = simpy.Resource(env, capacity=1)
env.process(assembly_line(env, resource))
env.run(until=100)

Build your model: Run the model and examine results

import simpy
def assembly_line(env, resource):
with resource.request() as req:
yield req
# assembly line process
env = simpy.Environment()
resource = simpy.Resource(env, capacity=1)
env.process(assembly_line(env, resource))
env.run(until=100)

Mixing Determinism and Non-Determinism in Models

  • Understand the types of processes in discrete-event models.
  • Distinguish between deterministic and non-deterministic processes and represent them in models.
  • Learn how to randomize events and simulate non-deterministic events.
  • Build a SimPy model combining both deterministic and non-deterministic processes.

Model Application, Clustering, Optimization, and Modularity

  • Learn optimization methods to maximize the impact of your discrete-event models.
  • Perform simulation ensembles using Monte Carlo approaches.
  • Identify clusters in model results to understand behavior and identify critical processes and tipping points.
  • Use objective functions to set targets for model optimization efforts.
  • Make your model scalable to grow stable and in a controlled manner.

Exercise: Build your model - Create an environment and resources

import simpy
# complete the dictionary with information about resources
resources = {
'step_1_fuselage': 20,
'step_2_wings': 8,
'step_3_power_plant': 10,
'step_4_landing_gear': 8
}
# create a SimPy environment
env = simpy.Environment()
# define resources with respective capacities
step_1_fuselage = simpy.Resource(env, capacity=3)
step_2_wings = simpy.Resource(env, capacity=2)
step_3_power_plant = simpy.Resource(env, capacity=2)
step_4_landing_gear = simpy.Resource(env, capacity=3)
# run simulation
env.run(until=100)

Hope you found this Python tutorial useful in understanding how to build a model and create an environment in Python. Stay tuned for more informative tutorials on Python programming.