def __init__(self, var_name, env, capacity, *args, **kwargs): """ extend `sim.Component.__init__()`, override name variable, setup Worker specific attributes Args: var_name (str): name of the worker resource env (EnvironmentPlus): salabim_plus simulation environment capacity (int): indicator for the number of workers in this worker resource *arg, **kwargs: sim.Component specific default attributes """ sim.Resource.__init__(self, name=var_name, capacity=capacity, *args, **kwargs) self.state = sim.State(self._name + '_status', value='off_clock') # worker status self.num_working = sim.State( self._name + '_num_working', value=0) # state indicating how many workers are working self.env = env env.objs[self._name] = self
def setup(self, sensitivity, busyness): self.state = sim.State((self.name() + ".state"), value="red") self.vehiclesQueue = sim.Queue(self.name() + ".queue") self.movementSensorSensitivity = sensitivity self.movementState = sim.State(self.name() + ".movementState", value='movement') self.busyness = busyness
def __init__(self, var_name, env, *args, **kwargs): """ extend `sim.Component.__init__()`, override name variable, setup Machine specific attributes Args: var_name (str): name of the machine env (EnvironmentPlus): salabim_plus simulation environment *arg, **kwargs: sim.Component specific default attributes """ sim.Component.__init__(self, name=var_name, *args, **kwargs) self.var_name = self._name.replace( '.', '_') # unique name of that specific machine self.queue = sim.Queue(self.var_name + '_queue') # queue of entities to work on self.in_queue = sim.State( self.var_name + '_in_queue' ) # trigger state to work on an entity, NOTE that the default state is FALSE self.state = sim.State(self.var_name + '_status', value='idle') # machine status self.time_remaining = 0 # time until machine finishes entity being process self.env = env env.objs[self._name] = self
def test38(): def animation_objects(self, value): if value=='blue': an1=sim.Animate(circle0=(40,),fillcolor0=value, linewidth0=0) else: an1=sim.Animate(rectangle0=(-40,-20,40,20), fillcolor0=value,linewidth0=0) an2=sim.Animate(text=value,textcolor0='white') return (an1,an2) class X(sim.Component): def process(self): while True: for i in ('red','green','blue','yellow','red'): letters.set(i[0]) light.set(i) yield self.hold(1) class Q(sim.Queue): pass env=sim.Environment(trace=True) for i in range(3): q=Q(name='rij.') X() light=sim.State('light') light.animate() letters=sim.State('letters') letters.animate(x=100,y=100) env.animation_parameters(synced=False) env.run()
def test33(): class X(sim.Component): def process(self): yield self.hold(1) s1.set(1) yield self.hold(1) s1.set(2) s2.set('red') yield self.hold(2) s1.set(30) class Y(sim.Component): def process(self): while True: yield self.wait((s1,lambda x, component, state: x/2>self.env.now())) yield self.hold(1.5) class Z(sim.Component): def process(self): while True: yield self.wait((s2,lambda x, component, state: x in ("red","yellow"))) yield self.hold(1.5) env=sim.Environment(trace=True) env.print_info() s1=sim.State(name='s.',value=0) s2=sim.State(name='s.',value='green') s3=sim.State(name='s.') q=sim.Queue('q.') x=X() y=Y() z=Z() env.run(10)
def __init__(self, var_name, env, steps, tracker, bom=None, main_exit=None, cut_queue=False, prepop=False, *args, **kwargs): """ extend `sim.Component.__init__()`, override name variable, setup Entity specific attributes Args: var_name (str): name of the entity env (EnvironmentPlus): salabim_plus simulation environment steps (dict): nested dictionary mapping out steps an entity will <-- UPDATE!! take, must follow standard steps dictionary formatting (see steps variable documentation) tracker (EntityTracker): entity tracker used to route new and completed entities bom (dict): nested dictionary mapping out build of materials required to process an entity, must follow standard bom dictionary formatting (see bom variable documentation), optional, default=None main_exit (Kanban|Storage): location to move entity when its completed, optional, default=None cut_queue (bool): indicator denoting entity should enter queues at head of queue *arg, **kwargs: sim.Component specific default attributes """ sim.Component.__init__(self, name=var_name, *args, **kwargs) self.var_name = self._name.replace( '.', '_') # unique name of that specific entity self.state = sim.State(self.var_name + '_state', value='in_wip') # entity status self.step_complete = sim.State( self.var_name + '_step_complete') # trigger state to move to next step self.steps = steps self.bom = bom self.main_exit = main_exit self.cut_queue = cut_queue self.prepop = prepop self.tracker = tracker self.as_built = [] # entity contents that were used to built entity self.env = env env.objs[self._name] = self if self.bom: self.get_materials()
def __init__(self, var_name, env, *args, **kwargs): """ extend `sim.Component.__init__()`, override name variable, setup EntityTracker specific attributes Args: var_name (str): name of the entity env (EnvironmentPlus): salabim_plus simulation environment *arg, **kwargs: sim.Component specific default attributes """ sim.Component.__init__(self, name='track.' + var_name, *args, **kwargs) self.wip = sim.Queue(self._name + '_wip') self.complete = sim.Queue(self._name + '_complete') self.wip_count = sim.State(self._name + '_wip_count', value=0) self.complete_count = sim.State(self._name + '_complete_count', value=0) self.env = env env._add_env_objectlist(self)
def __init__(self, var_name, env, kanban_attr, *args, **kwargs): """ extend `sim.Component.__init__()`, override name variable, setup Kanban specific attributes Args: var_name (str): name of the kanban storage location env (EnvironmentPlus): salabim_plus simulation environment kanban_attr (dict): dictionary mapping out characteristics of the kanban, must follow standard kanban_attr dictionary formatting (see kanban_attr variable documentation) *arg, **kwargs: sim.Component specific default attributes """ sim.Component.__init__(self, name=var_name + '_kanban', *args, **kwargs) self.order_gen = kanban_attr[ 'order_gen'] # EntityGenerator to order entities from self.order_point = kanban_attr[ 'order_point'] # threshold in which an order shall be made self.order_qty = kanban_attr['order_qty'] # quantity of an order self.init_qty = kanban_attr[ 'init_qty'] # initial quantity to order at beginning of simulation self.warmup_time = kanban_attr[ 'warmup_time'] # time to wait in beginning of simulation before evaluating whether an order should be made self.queue = sim.Queue(self._name + '_queue') # kanban queue self.count = sim.State( self._name + '_count', value=0) # state indicating how many entities are in kanban queue self.on_order = sim.State( self._name + '_on_order', value=0) # state indicating how many entities are on order self.total_inv = sim.State( self._name + '_total_inv', value=0) # sum of entities on order and entities in kanban queue self.env = env env.objs[self._name] = self
def test34(): class X(sim.Component): def process(self): try: yield self.hold(-1) except sim.SalabimError: yield self.hold(1) s1.set(1) yield self.hold(1) s1.set(2) s2.set('red') yield self.hold(2) s1.set(30) class Y(sim.Component): def process(self): while True: yield self.wait((s1,'$==2')) yield self.hold(1.5) class Z(sim.Component): def process(self): while True: yield self.wait((s2,'"$" in ("red","yellow")'),all=True) yield self.hold(1.5) env=sim.Environment(trace=True) env.print_info() s1=sim.State(name='s.',value=0) s2=sim.State(name='s.',value='green') s3=sim.State(name='s.') s1.name('piet') q=sim.Queue('q.') x=X() y=Y() z=Z() env.run(10) s1.print_statistics()
def __init__(self, var_name, env, *args, **kwargs): """ extend `sim.Component.__init__()`, override name variable, setup EntityTracker specific attributes Args: var_name (str): name of the entity env (EnvironmentPlus): salabim_plus simulation environment *arg, **kwargs: sim.Component specific default attributes """ sim.Component.__init__(self, name='track.' + var_name, *args, **kwargs) # this is the same line of code that is in the EntityGenerator class self.wip = sim.Queue( self._name + '_wip' ) # this is defining queues of all these names. they will all be prepended with 'tracker.' because self includes the tracker portion because this function is called by the EntityGenerator self.complete = sim.Queue(self._name + '_complete') self.wip_count = sim.State(self._name + '_wip_count', value=0) self.complete_count = sim.State(self._name + '_complete_count', value=0) self.env = env env.objs[self._name] = self
def test31(): class X(sim.Component): def process(self): yield self.hold(1) s1.set() yield self.hold(2) s1.reset() yield self.hold(2) y.print_info() s1.trigger() class Y(sim.Component): def process(self): while True: yield self.wait(s1,(s2,'red'),(s2,'green'),s3) yield self.hold(1.5) env=sim.Environment(trace=True) env.print_info() s1=sim.State(name='s.') s2=sim.State(name='s.') s3=sim.State(name='s.') q=sim.Queue('q.') x=X() y=Y() env.run(10) print('value at ',env.now(),s1.get()) print (s1.value.xduration()) print(s1.value.tx()) print(env) print(y) print(q) print(s1) s1.print_info() s2.print_info()
def __init__(self, var_name, env, *args, **kwargs): """ extend `sim.Component.__init__()`, override name variable, setup Storage specific attributes Args: var_name (str): name of the storage location env (EnvironmentPlus): salabim_plus simulation environment """ sim.Component.__init__(self, name=var_name + '_storage', *args, **kwargs) self.queue = sim.Queue(self._name + '_queue') # storage queue self.count = sim.State(self._name + '_count', value=0) # quantity inside storage queue self.env = env env.objs[self._name] = self
def test32(): class X(sim.Component): def process(self): yield self.wait(go) print('X after wait') yield self.hold(10) def p1(self): print('X in p1') yield self.passivate() class Y(sim.Component): def process(self): yield self.hold(2) x.activate(keep_wait=True, at=20) env = sim.Environment(trace=True) go = sim.State() x = X() y = Y() sim.run()
while len(armazem2) > 0: self.Deck = armazem2.pop() self.Deck.activate() while len(armazem3) > 0: self.Wheel = armazem3.pop() self.Wheel.activate() while len(armazem4) > 0: self.Wheel = armazem4.pop() self.Wheel.activate() if (env.now() // 1440) > 1: gestao.activate() env = sim.Environment(random_seed=200, time_unit='minutes', trace=False) work_control = sim.State('work_control', value='working') #initiation dos processos deck_pack = sim.Resource('deck_pack', capacity=0) wheel_pack = sim.Resource('wheel_pack', capacity=0) skate_unity = sim.Resource('skate_unity', capacity=0) wheel_unity = sim.Resource('wheel_unity', capacity=0) deck_unity = sim.Resource('deck_unity', capacity=0) cuttings = sim.Resource('cuttings', capacity=3) finishing = sim.Resource('finishing', capacity=1) painting = sim.Resource('painting', capacity=1) machining = sim.Resource('machining', capacity=2) printing = sim.Resource('printing', capacity=1) packing_w = sim.Resource('packing_w', capacity=1) packing_d = sim.Resource('packing_d', capacity=2) assembly_line = sim.Resource('assembly_line', capacity=2)
def setup(self): self.vehiclesInBetweenBool = sim.State(self.name() + ".vehiclesPresentState", value=False) self.vehiclesQueue = sim.Queue(self.name() + ".vehiclesQueue")
def setup(self, light, trafficEnv): self.trafficEnv = trafficEnv self.roadBetween = trafficEnv.roadBetween self.atLight = light self.movedState = sim.State(self.name() + ".movedState") self.atLight.vehiclesQueue.add(self)
self.leave(waitingline) env.number_reneged += 1 env.print_trace("", "", "reneged") else: yield self.passivate() # wait for service to be completed class Clerk(sim.Component): def process(self): while True: if len(waitingline) == 0: yield self.wait(worktodo) self.customer = waitingline.pop() yield self.hold(30) self.customer.activate() env = sim.Environment() CustomerGenerator() env.number_reneged = 0 env.number_balked = 0 for i in range(3): Clerk() waitingline = sim.Queue("waitingline") worktodo = sim.State("worktodo") env.run(till=50000) waitingline.print_histograms() worktodo.print_histograms() print("number reneged", env.number_reneged) print("number balked", env.number_balked)
class Customer(sim.Component): def process(self): self.enter(waitingline) worktodo.trigger(max=1) yield self.passivate() class Clerk(sim.Component): def process(self): while True: if len(waitingline) == 0: yield self.wait(worktodo) self.customer = waitingline.pop() yield self.hold(30) self.customer.activate() env = sim.Environment(trace=False) CustomerGenerator() for i in range(3): Clerk() waitingline = sim.Queue('waitingline') worktodo = sim.State('worktodo') env.run(till=50000) waitingline.length.print_histogram(30, 0, 1) print() waitingline.length_of_stay.print_histogram(30, 0, 10) worktodo.print_statistics()
# OK, now wait to get out onto the street; every time a new car # arrives in cross traffic, it will signal us to check the new # next arrival time while env.now() + time_to_exit >= street.nextarrival: yield self.wait(wakeup, mode='wait for wakeup') yield self.hold(time_to_exit, mode='exit') self.release(bufferfront) self.release(buffer) class CarWash(sim.Component): def process(self): while True: yield self.hold(wash_iat.sample()) Car() env = sim.Environment(trace=True) wakeup = sim.State(name='wakeup') wash_time = sim.Pdf((1.0, 0.7, 2.0, 0.3)) street_iat = sim.Exponential(1) wash_iat = sim.Exponential(1) buffer = sim.Resource(capacity=4) bufferfront = sim.Resource() bay = sim.Resource() time_to_exit = 1 CarWash() street = Street() env.run(500)
env.king = self else: yield self.wait((king_died, True, -env.now()), fail_at=self.live_till) if self.failed(): # the prince dies before getting to the throne env.print_trace('', '', 'dies before getting to the throne') return env.king = self env.print_trace('', '', 'vive le roi!', env.king.name()) kings.append((self.name(), env.now(), self.live_till, self.live_till - env.now())) yield self.hold(till=self.live_till) env.print_trace('', '', 'Le roi est mort.') env.king = None king_died.trigger(max=1) if env.king is None: env.lastkingdied = env.now() env = sim.Environment(trace=True) env.king = None env.lastkingdied = env.now() kings = [] king_died = sim.State(name='king died') PrinceGenerator() env.run(5000) print('king from to duration') for king in kings: print('{:20}{:9d}{:9d}{:9d}'.format(*king))
light['west'].set('red') light['east'].set('red') light['north'].set('green') light['south'].set('green') def process(self): while True: yield self.hold(55) for direction in directions: if light[direction].get() == 'green': light[direction].set('yellow') yield self.hold(5) for direction in directions: if light[direction].get() == 'yellow': light[direction].set('red') else: light[direction].set('green') env=sim.Environment(trace=True) directions=('west','east','north','south') light={} for direction in directions: light[direction] = sim.State('light_'+direction) TrafficLight() CarGenerator() env.run(500)
class Client(sim.Component): def process(self): self.enter(waiting_clients) work_to_do.trigger(max=1) yield self.passivate() class ClientGenerator(sim.Component): def process(self): while True: yield self.hold(sim.Exponential(iat).sample()) Client() env = sim.Environment(trace=True) waiting_clients = sim.Queue('waiting_clients') work_to_do = sim.State('work_to_do') nservers = 5 iat = 1 server_time = 4 for i in range(nservers): Server() ClientGenerator(name='clientgenerator') env.run(100)
env.king = self else: yield self.wait((king_died, True, -env.now()), fail_at=self.live_till) if self.failed(): # the prince dies before getting to the throne env.print_trace("", "", "dies before getting to the throne") return env.king = self env.print_trace("", "", "vive le roi!", env.king.name()) kings.append((self.name(), env.now(), self.live_till, self.live_till - env.now())) yield self.hold(till=self.live_till) env.print_trace("", "", "Le roi est mort.") env.king = None king_died.trigger(max=1) if env.king is None: env.lastkingdied = env.now() env = sim.Environment(trace=True) env.king = None env.lastkingdied = env.now() kings = [] king_died = sim.State(name="king died") PrinceGenerator() env.run(5000) print("king from to duration") for king in kings: print("{:20}{:9d}{:9d}{:9d}".format(*king))
class Client(sim.Component): def setup(self): self.enter(waiting_clients) work_to_do.trigger(max=1) class ClientGenerator(sim.Component): def process(self): while True: yield self.hold(sim.Exponential(iat).sample()) Client() env = sim.Environment(trace=True) waiting_clients = sim.Queue("waiting_clients") work_to_do = sim.State("work_to_do") nservers = 5 iat = 1 server_time = 4 for i in range(nservers): Server() ClientGenerator(name="clientgenerator") env.run(100)
waitingLineFinishing = sim.Queue("Line for finishing") waitingLinePainting = sim.Queue("Line for painting") waitingLineStorage2 = sim.Queue("Line for Storage 2") waitingLineExportDecks = sim.Queue("Line for export decks") # Processos para as pranchas pressing = [Pressing() for i in range(4)] storage1 = Storage1() cutting = [Cutting() for i in range(3)] finishing = Finishing() painting = Painting() storage2 = Storage2() exportDecks = [PackingDecks() for i in range(2)] # States para as pranchas pressingState = sim.State("pressingState", value=True) storage1State = sim.State("storage1State", value=True) cuttingState = sim.State("cuttingState", value=True) finishingState = sim.State("finishingState", value=True) paintingState = sim.State("paintingState", value=True) storage2State = sim.State("storage2State", value=True) exportDecksState = sim.State("exportDecksState", value=True) lote_decks = [DeckGenerator(num_deck=pranchas) for i in range(DIAS_SIM)] # -------------------- RODAS -------------------- rodas = (5280 * 4 + 4 * 2640) / 22 # Produção de rodas diária # Filas para as rodas waitingLineFoundry = sim.Queue("Line for foundry")
def __init__(self, var_name, steps_func, env, arrival_type=None, start_at=0, bom=None, main_exit=None, cut_queue=False, interval=None, inv_level=None, *args, **kwargs): """ extend `sim.Component.__init__()`, override name variable, setup EntityGenerator specific attributes Args: var_name (str): name of the entity # steps (dict): nested dictionary mapping out steps an entity will # take, must follow standard steps dictionary # formatting (see steps variable documentation) steps_func (function): entity step building function that maps out the steps an entity will take, must return a properly formatted steps dictionary (see steps variable documentation) env (EnvironmentPlus): salabim_plus simulation environment arrival_type (str): predefined method in which entities can arrive, available methods: ('continuous', 'periodic','ordered','inv_based') start_at (int): time epoch to wait until before starting EntityGenerator, optional, default=0 bom (dict): nested dictionary mapping out build of materials required to process an entity, must follow standard bom dictionary formatting (see bom variable documentation), optional, default=None main_exit (Kanban|Storage): location to move entity when its completed, optional, default=None cut_queue (bool): indicator denoting entity should enter queues at head of queue interval (int): time epoch between entity arrivals (only for arrival_type=`periodic`, optional, default=None) inv_level (int): inventory level at which work in process should be maintained (only for arrival_type=`inv_based`, optional, default=None) *arg, **kwargs: sim.Component specific default attributes """ sim.Component.__init__(self, name='gener.' + var_name, *args, **kwargs) self.entity = Entity # Entity base class self.make_count = 0 self.tracker = EntityTracker( var_name, env) # EntityTracker instance of var_name=var_name self.var_name = self._name.replace('gener.', '').replace('.', '_') # self.steps = steps self.steps_func = steps_func self.bom = bom self.main_exit = main_exit self.cut_queue = cut_queue self.arrival_type = arrival_type self.start_at = start_at self.env = env env.objs[self._name] = self # decision tree to initialize arrival_type specific attributes if arrival_type == 'continuous': pass elif arrival_type == 'periodic': self.interval = interval elif arrival_type == 'ordered': # sim.State used to know if any entities have been ordered # sim.State is defined in the salabim package; its default value is set to FALSE until it is interacted with and becomes true # the value of a state is automatically monitored in the state.value level monitor self.ordered_qty = (sim.State(self.var_name + '_ordered_qty', value=0)) elif arrival_type == 'inv_based': self.inv_level = inv_level # raise error for an unrecognized arrival_type method else: options = ['continuous', 'periodic', 'ordered', 'inv_based'] raise InputError(arrival_type, 'arrival_type', options)
def setup(self, i): self.atwork = sim.State('at work {}'.format(i))
def setup(self): self.green=sim.State(name='green')
import salabim as sim class P(sim.Component): def process(self): while True: x.set('red') yield self.hold(2) x.set('blue') yield self.hold(2) x.set() yield self.hold(2) x.reset() yield self.hold(2) env = sim.Environment() env.animation_parameters(background_color='black') x = sim.State() x.animate() P() env.run()