def do_animation(): sim.AnimateQueue(servers.requesters(), x=800, y=200, direction='w') sim.AnimateQueue(servers.claimers(), x=900, y=200, direction='n') sim.AnimateMonitor(servers.requesters().length, x=50, y=450, width=env.width()-100, horizontal_scale=4, title=lambda:'Length of requesters. Mean ={:10.2f}'.format(servers.requesters().length.mean())) sim.AnimateMonitor(servers.claimers().length, x=50, y=550, width=env.width()-100, horizontal_scale=4, title=lambda:'Length of claimers. Mean ={:10.2f}'.format(servers.claimers().length.mean())) sim.AnimateMonitor(system.length_of_stay, x=50, y=650, height=75, width=env.width()-100, horizontal_scale=5, vertical_scale=2, as_points=True, title=lambda:'Length of stay in system. Mean ={:10.2f}'.format(system.length_of_stay.mean())) sim.AnimateText(text='Server', x=900, y=200 - 50, text_anchor='n') sim.AnimateText(text='<-- Waiting line', x=900 - 145, y=200 - 50, text_anchor='n') env.animation_parameters(modelname='M/M/c')
def do_animation(): sim.AnimateQueue(servers.requesters(), x=800, y=100, direction="w", title="") sim.AnimateQueue(servers.claimers(), x=900, y=100, direction="n", title="") sim.AnimateMonitor( servers.requesters().length, x=50, y=350, width=env.width() - 100, horizontal_scale=4, title=lambda: "Number of waiting customers. Mean ={:10.2f}".format( servers.requesters().length.mean()), ) sim.AnimateMonitor( servers.claimers().length, x=50, y=450, width=env.width() - 100, horizontal_scale=4, title=lambda: "Number of active clerks. Mean ={:10.2f}".format( servers.claimers().length.mean()), ) sim.AnimateMonitor( system.length_of_stay, x=50, y=550, height=75, width=env.width() - 100, horizontal_scale=4, vertical_scale=2, title=lambda: "Time in post office. Mean ={:10.2f}".format( system.length_of_stay.mean()), ) sim.AnimateText(text="Clerks", x=900, y=100 - 50, text_anchor="n") sim.AnimateText(text="<-- Waiting clients", x=900 - 145, y=100 - 50, text_anchor="n") env.animation_parameters(modelname="M/M/c")
def setup(self, job_generator): self.tasks = sim.Queue(fill=[ Task(job_generator=job_generator, job=self, name='Task ' + str(self.sequence_number()) + '.') for _ in range(job_generator.number_of_tasks_dist()) ], name='tasks.') self.task_in_execution = sim.Queue(name='task_in_execution.') self.slack = start_slack self.an_slack = sim.AnimateText( x=90, y=self.y, text=lambda job, t: '{:7.2f}'.format(job.slack_t(t)), textcolor=lambda job, t: 'white' if job.slack_t(t) < 0 else '50%gray', fontsize=12, text_anchor='se', arg=self) self.an_label = sim.AnimateText(text=str(self.sequence_number()), x=50, y=self.y, fontsize=12, text_anchor='se') self.an_execute = sim.AnimateRectangle( spec=(0, 0, 72, 12), x=100, y=self.y, fillcolor=lambda job, t: '' if job.tasks[ 0].start_execution is None else job.tasks[0].group.color, text=lambda job, t: '' if job.tasks[ 0].start_execution is None else job.tasks[0].machine.name(), textcolor='white', text_anchor='sw', arg=self) self.an_due = sim.AnimateLine( spec=(0, -1, 0, 13), x=lambda job, t: 200 + job.due_t(t) * scale_x, y=self.y, layer=-1, arg=self) self.an_tasks = sim.AnimateQueue(queue=self.tasks, x=200, y=self.y, direction='e', arg=self) self.enter(self.tasks[0].group.jobs) if self.tasks.head().group.idle_machines: self.tasks.head().group.idle_machines.head().activate() self.enter(plant)
def do_animation(): env.animation_parameters(modelname='Machine shop', speed=4, background_color='20%gray') for machine in machines + [other]: sim.AnimateRectangle( spec=lambda arg, t: arg.rectangle(t, remain=False), fillcolor=lambda arg, t: arg.fillcolor(t, remain=False), linewidth=0, text=lambda self, t: '{} {:4d}'.format(self.ident, self.parts_made ), text_anchor='sw', font='narrow', fontsize=15, text_offsetx=-90, textcolor='white', arg=machine) sim.AnimateRectangle( spec=lambda arg, t: arg.rectangle(t, remain=True), fillcolor=lambda arg, t: arg.fillcolor(t, remain=True), linewidth=0, text=lambda self, t: '{} {:4d}'.format(self.ident, self.parts_made ), text_anchor='sw', font='narrow', fontsize=15, text_offsetx=-90, textcolor='white', arg=machine) sim.AnimateQueue(queue=repairman.requesters(), x=lambda t: 10 + repairman.claimers()[0].l(t) + 2 if repairman.claimers() else 10, y=10, direction='e') sim.AnimateQueue(queue=repairman.claimers(), x=10, y=10, direction='e')
horizontal_scale=0.1, vertical_scale=7.5) # > Queue length of stay histogram sim.AnimateText( text=lambda: queue1.length_of_stay.print_histogram(as_str=True), x=ani.q_LOS_hist_x_left, y=ani.q_LOS_hist_y_top, text_anchor='nw', font='narrow', fontsize=10) # Queue1 Animation qa0 = sim.AnimateQueue( queue1, x=ani.queue_x_left + 50, y=ani.queue_y_bottom, title='Queue of Ships Waiting for Reload at Base 1', direction='e', id='blue', ) sim.AnimateRectangle( spec=ani.resource_bar_spec, # text=ani.resource_bar_text, arg=TLAMs1) sim.AnimateRectangle(spec=ani.resource_label_spec, text=ani.resource_label_text, arg=TLAMs1) # Run simulation env.animation_parameters(animate=True, speed=SIM_SPEED) # , width=1500 env.background_color('20%gray')
def process(self): while True: yield self.hold(sim.Uniform(0, 20)()) self.enter(q) yield self.hold(sim.Uniform(0, 20)()) self.leave() env = sim.Environment(trace=False) env.background_color('20%gray') q = sim.Queue('queue') sim.AnimateText('queue, normal', x=100, y=50, text_anchor='nw') qa0 = sim.AnimateQueue(q, x=100, y=50, direction='e', id='blue') sim.AnimateText('queue, limited to six components', x=100, y=250, text_anchor='nw') qa1 = sim.AnimateQueue(q, x=100, y=250, direction='e', max_length=6, id='red') sim.AnimateText('queue, reversed', x=100, y=150, text_anchor='nw') qa2 = sim.AnimateQueue(q, x=100, y=150, direction='e', reverse=True, id='green')
def do_animation(): global xvisitor_dim global yvisitor_dim global xcar global capacity_last, ncars_last, topfloor_last env.modelname("Elevator") env.speed(32) env.background_color("20%gray") if make_video: env.video("Elevator.mp4") xvisitor_dim = 30 yvisitor_dim = xvisitor_dim yfloor0 = 20 xcar = {} xled = {} x = env.width() for car in cars: x -= (capacity + 1) * xvisitor_dim xcar[car] = x x -= xvisitor_dim xsign = x x -= xvisitor_dim / 2 for direction in (up, down): x -= xvisitor_dim / 2 xled[direction] = x x -= xvisitor_dim xwait = x for floor in floors: y = yfloor0 + floor.n * yvisitor_dim floor.y = y for direction in (up, down): if (direction == up and floor.n < topfloor) or (direction == down and floor.n > 0): b = xvisitor_dim / 4 animate_led = sim.AnimatePolygon( spec=(-b, -b, b, -b, 0, b), x=xled[direction], y=y + 2 * b, angle=0 if direction == up else 180, fillcolor=direction_color(direction), visible=lambda arg, t: (arg.floor_direction) in requests, ) animate_led.floor_direction = (floor, direction) sim.AnimateLine(x=0, y=y, spec=(0, 0, xwait, 0)) sim.AnimateText(x=xsign, y=y + yvisitor_dim / 2, text=str(floor.n), fontsize=xvisitor_dim / 2) sim.AnimateQueue(queue=floor.visitors, x=xwait - xvisitor_dim, y=floor.y, direction="w", title="") for car in cars: x = xcar[car] car.pic = sim.AnimateRectangle(x=x, y=car.y, spec=(0, 0, capacity * xvisitor_dim, yvisitor_dim), fillcolor="lightblue", linewidth=0) sim.AnimateQueue(queue=car.visitors, x=xcar[car], y=car.y, direction="e", title="", arg=car) ncars_last = ncars sim.AnimateSlider( x=510, y=0, width=90, height=20, vmin=1, vmax=5, resolution=1, v=ncars, label="#elevators", action=set_ncars, xy_anchor="nw", ) topfloor_last = topfloor sim.AnimateSlider( x=610, y=0, width=90, height=20, vmin=5, vmax=20, resolution=1, v=topfloor, label="top floor", action=set_topfloor, xy_anchor="nw", ) capacity_last = capacity sim.AnimateSlider( x=710, y=0, width=90, height=20, vmin=2, vmax=6, resolution=1, v=capacity, label="capacity", action=set_capacity, xy_anchor="nw", ) sim.AnimateSlider( x=510, y=-50, width=90, height=25, vmin=0, vmax=400, resolution=25, v=load_0_n, label="Load 0->n", action=set_load_0_n, xy_anchor="nw", ) sim.AnimateSlider( x=610, y=-50, width=90, height=25, vmin=0, vmax=400, resolution=25, v=load_n_n, label="Load n->n", action=set_load_n_n, xy_anchor="nw", ) sim.AnimateSlider( x=710, y=-50, width=90, height=25, vmin=0, vmax=400, resolution=25, v=load_n_0, label="Load n->0", action=set_load_n_0, xy_anchor="nw", ) env.animate(True)
def do_animation(): global ylevel, xdoor, waterdepth lockheight = 5 waterdepth = 2 ylevel = {left: 0, right: lockheight} xdoor = {left: -0.5 * locklength, right: 0.5 * locklength} xbound = {left: -1.2 * locklength, right: 1.2 * locklength} env.animation_parameters(x0=xbound[left], y0=-waterdepth, x1=xbound[right], modelname='Lock', speed=8, background_color='20%gray') for side in [left, right]: sim.AnimateQueue(queue=wait[side], x=xdoor[side], y=10 + ylevel[side], direction='n') sim.AnimateRectangle(spec=(xbound[left], ylevel[left] - waterdepth, xdoor[left], ylevel[left]), fillcolor='aqua') sim.AnimateRectangle(spec=(xdoor[right], ylevel[right] - waterdepth, xbound[right], ylevel[right]), fillcolor='aqua') sim.AnimateRectangle(spec=lock_water_rectangle, fillcolor='aqua') sim.AnimateRectangle(spec=lock_door_left_rectangle) sim.AnimateRectangle(spec=lock_door_right_rectangle) sim.AnimateSlider(x=520, y=0, width=100, height=20, vmin=16, vmax=60, resolution=4, v=iat, label='iat', action=set_iat, xy_anchor='nw') sim.AnimateSlider(x=660, y=0, width=100, height=20, vmin=10, vmax=60, resolution=5, v=meanlength, label='mean length', action=set_meanlength, xy_anchor='nw') sim.AnimateMonitor( wait[left].length, linecolor='orange', fillcolor='bg', x=-225, y=-200, xy_anchor='n', horizontal_scale=1, width=450, linewidth=2, title=lambda: 'Number of waiting ships left. Mean={:10.2f}'.format( wait[left].length.mean())) sim.AnimateMonitor( wait[right].length, linecolor='orange', fillcolor='bg', x=-225, y=-300, xy_anchor='n', horizontal_scale=1, width=450, linewidth=2, title=lambda: 'Number of waiting ships right. Mean={:10.2f}'.format( wait[right].length.mean())) sim.AnimateMonitor( wait[left].length_of_stay, linecolor='white', fillcolor='bg', x=-225, y=-400, xy_anchor='n', vertical_scale=0.5, horizontal_scale=5, as_points=True, width=450, height=75, linewidth=4, title=lambda: 'Waiting time of ships left. Mean={:10.2f}'.format(wait[ left].length_of_stay.mean())) sim.AnimateMonitor( wait[right].length_of_stay, linecolor='white', fillcolor='bg', x=-225, y=-500, xy_anchor='n', vertical_scale=0.5, horizontal_scale=5, as_points=True, width=450, height=75, linewidth=4, title=lambda: 'Waiting time of ships left. Mean={:10.2f}'.format(wait[ right].length_of_stay.mean())) sim.AnimateQueue(queue=lockqueue, x=lambda: xdoor[-lock.sideq], y=lock_y, direction=lambda: 'w' if lock.sideq == left else 'e')
return 45, 0, ao0 def process(self): while True: yield self.hold(sim.Uniform(0, 20)()) self.enter(q) yield self.hold(sim.Uniform(0, 20)()) self.leave() env = sim.Environment(trace=False) env.background_color('20%gray') q = sim.Queue('queue') qa0 = sim.AnimateQueue(q, x=100, y=25, title='queue, normal', direction='e', id='blue') qa1 = sim.AnimateQueue(q, x=100, y=75, title='queue, reversed', direction='e', reverse=True, id='green') qa2 = sim.AnimateQueue(q, x=100, y=125, title='queue, maximum 6 components', direction='e', max_length=6, id='red') qa3 = sim.AnimateQueue(q, x=100, y=350, title='queue, text only', direction='s', id='text') sim.AnimateMonitor(q.length, x=10, y=450, width=480, height=100, horizontal_scale=5, vertical_scale=5) sim.AnimateMonitor(q.length_of_stay, x=10, y=570, width=480, height=100, horizontal_scale=5, vertical_scale=5) sim.AnimateText(text=lambda: q.length.print_histogram(as_str=True), x=500, y=700, text_anchor='nw', font='narrow', fontsize=10) sim.AnimateText(text=lambda: q.print_info(as_str=True), x=500, y=340, text_anchor='nw', font='narrow', fontsize=10) [X(i=i) for i in range(15)]
def do_animation(): global ylevel, xdoor, waterdepth lockheight = 5 waterdepth = 2 ylevel = {left: 0, right: lockheight} xdoor = {left: -0.5 * locklength, right: 0.5 * locklength} xbound = {left: -1.2 * locklength, right: 1.2 * locklength} env.animation_parameters( x0=xbound[left], y0=-waterdepth, x1=xbound[right], modelname="Lock", speed=8, background_color="20%gray" ) for side in [left, right]: sim.AnimateQueue(queue=wait[side], x=xdoor[side], y=10 + ylevel[side], direction="n", title="") sim.AnimateRectangle(spec=(xbound[left], ylevel[left] - waterdepth, xdoor[left], ylevel[left]), fillcolor="aqua") sim.AnimateRectangle( spec=(xdoor[right], ylevel[right] - waterdepth, xbound[right], ylevel[right]), fillcolor="aqua" ) sim.AnimateRectangle(spec=lock_water_rectangle, fillcolor="aqua") sim.AnimateRectangle(spec=lock_door_left_rectangle) sim.AnimateRectangle(spec=lock_door_right_rectangle) sim.AnimateSlider( x=520, y=0, width=100, height=20, vmin=16, vmax=60, resolution=4, v=iat, label="iat", action=set_iat, xy_anchor="nw", ) sim.AnimateSlider( x=660, y=0, width=100, height=20, vmin=10, vmax=60, resolution=5, v=meanlength, label="mean length", action=set_meanlength, xy_anchor="nw", ) sim.AnimateMonitor( wait[left].length, linecolor="orange", fillcolor="bg", x=-225, y=-200, xy_anchor="n", horizontal_scale=1, width=450, linewidth=2, title=lambda: "Number of waiting ships left. Mean={:10.2f}".format(wait[left].length.mean()), ) sim.AnimateMonitor( wait[right].length, linecolor="orange", fillcolor="bg", x=-225, y=-300, xy_anchor="n", horizontal_scale=1, width=450, linewidth=2, title=lambda: "Number of waiting ships right. Mean={:10.2f}".format(wait[right].length.mean()), ) sim.AnimateMonitor( wait[left].length_of_stay, linecolor="white", fillcolor="bg", x=-225, y=-400, xy_anchor="n", vertical_scale=0.5, horizontal_scale=1, width=450, height=75, linewidth=4, title=lambda: "Waiting time of ships left. Mean={:10.2f}".format(wait[left].length_of_stay.mean()), ) sim.AnimateMonitor( wait[right].length_of_stay, linecolor="white", fillcolor="bg", x=-225, y=-500, xy_anchor="n", vertical_scale=0.5, horizontal_scale=1, width=450, height=75, linewidth=4, title=lambda: "Waiting time of ships left. Mean={:10.2f}".format(wait[right].length_of_stay.mean()), ) sim.AnimateQueue( queue=lockqueue, x=lambda: xdoor[-lock.sideq], y=lock_y, direction=lambda: "w" if lock.sideq == left else "e", title="", )
def setup_animation_window(): env.background_color('90%gray') sim.AnimateText(text="Traffic Environment Simulation", x=10, y=728, textcolor='20%gray', fontsize=30) # Animation setup for Light A sim.AnimateText(text="Light A", x=10, y=700, textcolor='20%gray', fontsize=20) sim.AnimateRectangle(spec=(10, 530, 70, 690), fillcolor='black') sim.AnimateCircle( radius=20, x=40, y=660, fillcolor=lambda: check_light_state(trafficEnv.lightList[0], 'red')) sim.AnimateCircle( radius=20, x=40, y=610, fillcolor=lambda: check_light_state(trafficEnv.lightList[0], 'amber')) sim.AnimateCircle( radius=20, x=40, y=560, fillcolor=lambda: check_light_state(trafficEnv.lightList[0], 'green')) sim.AnimateRectangle(spec=(83, 650, 786, 714), linecolor='90%gray', linewidth=2, fillcolor='whitesmoke') sim.AnimateQueue(trafficEnv.lightList[0].vehiclesQueue, x=110, y=674, title='Queue', direction='e', max_length=14) sim.AnimateRectangle(spec=(83, 525, 786, 646), linecolor='90%gray', linewidth=2, fillcolor='whitesmoke') sim.AnimateMonitor(trafficEnv.lightList[0].vehiclesQueue.length_of_stay, title="Waiting Time", x=90, y=530, width=689, height=100, horizontal_scale=2, vertical_scale=1) sim.AnimateRectangle(spec=(790, 525, 1024, 714), fillcolor='whitesmoke') sim.AnimateText(text=lambda: "Queue Length: " + str( len(trafficEnv.lightList[0].vehiclesQueue)), x=795, y=694, fontsize=15, textcolor='20%gray') sim.AnimateText(text=lambda: "Queue Length Mean: " + str( round(trafficEnv.lightList[0].vehiclesQueue.length.mean(), 1)), x=795, y=679, fontsize=15, textcolor='20%gray') sim.AnimateText(text=lambda: "Queue Length Maximum: " + str( round(trafficEnv.lightList[0].vehiclesQueue.length.maximum(), 1)), x=795, y=664, fontsize=15, textcolor='20%gray') sim.AnimateText(text=lambda: "Waiting Time Mean: " + str( round(trafficEnv.lightList[0].vehiclesQueue.length_of_stay.mean(), 1)), x=795, y=634, fontsize=15, textcolor='20%gray') sim.AnimateText(text=lambda: "Waiting Time Maximum: " + str( round(trafficEnv.lightList[0].vehiclesQueue.length_of_stay.maximum(), 1 )), x=795, y=619, fontsize=15, textcolor='20%gray') # Animation setup for Light B. sim.AnimateText(text="Light B", x=10, y=450, textcolor='20%gray', fontsize=20) sim.AnimateRectangle(spec=(10, 280, 70, 440), fillcolor='black') sim.AnimateCircle( radius=20, x=40, y=410, fillcolor=lambda: check_light_state(trafficEnv.lightList[1], 'red')) sim.AnimateCircle( radius=20, x=40, y=360, fillcolor=lambda: check_light_state(trafficEnv.lightList[1], 'amber')) sim.AnimateCircle( radius=20, x=40, y=310, fillcolor=lambda: check_light_state(trafficEnv.lightList[1], 'green')) sim.AnimateRectangle(spec=(83, 400, 786, 464), linecolor='90%gray', linewidth=2, fillcolor='whitesmoke') sim.AnimateQueue(trafficEnv.lightList[1].vehiclesQueue, x=110, y=424, title='Queue', direction='e', max_length=14) sim.AnimateRectangle(spec=(83, 275, 786, 396), linecolor='90%gray', linewidth=2, fillcolor='whitesmoke') sim.AnimateMonitor(trafficEnv.lightList[1].vehiclesQueue.length_of_stay, title="Waiting Time", x=90, y=280, width=689, height=100, horizontal_scale=2, vertical_scale=1) sim.AnimateRectangle(spec=(790, 275, 1024, 464), fillcolor='whitesmoke') sim.AnimateText(text=lambda: "Queue Length: " + str( len(trafficEnv.lightList[1].vehiclesQueue)), x=795, y=444, fontsize=15, textcolor='20%gray') sim.AnimateText(text=lambda: "Queue Length Mean: " + str( round(trafficEnv.lightList[1].vehiclesQueue.length.mean(), 1)), x=795, y=429, fontsize=15, textcolor='20%gray') sim.AnimateText(text=lambda: "Queue Length Maximum: " + str( round(trafficEnv.lightList[1].vehiclesQueue.length.maximum(), 1)), x=795, y=414, fontsize=15, textcolor='20%gray') sim.AnimateText(text=lambda: "Waiting Time Mean: " + str( round(trafficEnv.lightList[1].vehiclesQueue.length_of_stay.mean(), 1)), x=795, y=384, fontsize=15, textcolor='20%gray') sim.AnimateText(text=lambda: "Waiting Time Maximum: " + str( round(trafficEnv.lightList[1].vehiclesQueue.length_of_stay.maximum(), 1 )), x=795, y=369, fontsize=15, textcolor='20%gray')
def do_animation(): # Animation initialisation is done in this function # In this example, the simulation code is completely separated from the animation code # Some global variables accesible from any classes and functions in the code global xvisitor_dim # x-dimension of the square representing a visitor global yvisitor_dim # y-dimension of the square representting a visitor global xcar # x-dimension of the elevator car/s global capacity_last, ncars_last, topfloor_last # Some general parameters about the simulation (See Reference: salabim.Environment) env.modelname("Elevator") env.speed(32) env.background_color("20%gray") if make_video: env.video("Elevator.mp4") # We assign values to some the global variables xvisitor_dim = 30 # x-dimension of the square representing a visitor yvisitor_dim = xvisitor_dim # y-dimension of the square representing a visitor yfloor0 = 20 # y-coordinate of floor 0 xcar = {} # This is a dictionary containing the x-coordinates of the cars xled = {} # This is a dictionary containing the x-coordinates of the leds x = env.width() # Width of the animation in screen coordinates (See Reference) # This is the width available to display all the elements on the screen # Now we assign x-coordinates, from the right to left of the screen for car in cars: # We assign x-coordinates to the elevator cars x -= (capacity + 1) * xvisitor_dim # Each car must contain visitors xcar[car] = x # We store the car x-coordinate in the dictionary x -= xvisitor_dim # Additional space (one square) xsign = x # Position of the text with the number of floor x -= xvisitor_dim / 2 # Additional space (half square) for direction in (up, down): # Position of the leds (red/green) x -= xvisitor_dim / 2 xled[direction] = x # We store the led x-coordinates in the dictionary x -= xvisitor_dim # Another square to the right xwait = x # Where to show the queues at different floors for floor in floors: # Components needed to display the floors y = yfloor0 + floor.n * yvisitor_dim # y-coordinate of the floors floor.y = y for direction in (up, down): # Led indicating the direction of the car if (direction == up and floor.n < topfloor) or (direction == down and floor.n > 0): b = xvisitor_dim / 4 # Dimension used to define the triangle animate_led = sim.AnimatePolygon( # See Reference AnimatePolygon spec=(-b, -b, b, -b, 0, b), # this is triangle x=xled[direction], y=y + 2 * b, angle=0 if direction == up else 180, # up points up, down points down fillcolor=direction_color(direction), # up is red, down is green visible=lambda arg, t: arg in requests, arg=(floor, direction), ) # if (floor, direction) in requests, show, otherwise do not show sim.AnimateLine(x=0, y=y, spec=(0, 0, xwait, 0)) # Horizontal lines for floors sim.AnimateText( x=xsign, y=y + yvisitor_dim / 2, text=str(floor.n), fontsize=xvisitor_dim / 2 ) # Text indicating the floor number sim.AnimateQueue(queue=floor.visitors, x=xwait - xvisitor_dim, y=floor.y, direction="w")
x=xsign, y=y + yvisitor_dim / 2, text=str(floor.n), fontsize=xvisitor_dim / 2 ) # Text indicating the floor number sim.AnimateQueue(queue=floor.visitors, x=xwait - xvisitor_dim, y=floor.y, direction="w") , # The queue at each floor of people waiting for the elevator, build westward for car in cars: # Components needed to display the cars x = xcar[car] # A dictionary containing the x-coordinates of the cars car.pic = sim.AnimateRectangle( x=x, y=car.y, # Main rectangle representing the car spec=(0, 0, capacity * xvisitor_dim, yvisitor_dim), fillcolor="lightblue", linewidth=0, ) sim.AnimateQueue(queue=car.visitors, x=xcar[car], y=car.y, direction="e", arg=car) # note that both the rectangle and the queue have a dynamic y-coordinate that # is controlled by the car.y method # The following Animate elements are sliders, which allow controlling different variables # on the animation screen ncars_last = ncars sim.AnimateSlider( x=510, y=0, width=90, height=20, vmin=1, vmax=5, resolution=1, v=ncars,
import salabim as sim class Car(sim.Component): def process(self): yield self.request(pumps) yield self.hold(sim.Uniform(1,9)()) class CarGenerator(sim.Component): def process(self): while True: yield self.hold(sim.Exponential(1)()) Car() sim.reset() env = sim.Environment(trace=False) CarGenerator() pumps = sim.Resource(name='pumps', capacity=4) env.animation_parameters() sim.AnimateQueue(queue=pumps.requesters(), x=800, y=200, direction='w') sim.AnimateQueue(queue=pumps.claimers(), x=900, y=200, direction='n') sim.AnimateText('Pumps', x=900, y=200 - 50, text_anchor='n') sim.AnimateText('<-- Waiting line', x=900 - 145, y=200 - 50, text_anchor='n') env.animation_parameters(modelname='Fuel station') env.run(100) pumps.requesters().length_of_stay.print_histogram(30,0,1)
def do_animation(): global ylevel, xdoor, waterdepth lockheight = 5 # Maximum height of the water inside the lock waterdepth = 2 # Minimum level of water ylevel = { left: 0, right: lockheight } # Dictionary, defining the (fixed) water level at both sides of the lock xdoor = { left: -0.5 * locklength, right: 0.5 * locklength } # x-coordinate of the doors xbound = { left: -1.2 * locklength, right: 1.2 * locklength } # x-coordinate of the limits of the screen # animation_parameters is a method of salabim.Environment to set animation parameters and to start the animation env.animation_parameters(x0=xbound[left], y0=-waterdepth, x1=xbound[right], modelname="Lock", speed=8, background_color="20%gray") for side in [left, right]: sim.AnimateQueue(queue=wait[side], x=xdoor[side], y=10 + ylevel[side], direction="n") # AnimateQueue is a class of Salabim to animate the component in a queue # wait[left] and wait[right] are ship queues at both sides of the lock # AnimateRectangle is a class of Salabim to display a rectangle, optinally with a text # The first rectangle represents the water at the left side of the lock (fixed level) sim.AnimateRectangle(spec=(xbound[left], ylevel[left] - waterdepth, xdoor[left], ylevel[left]), fillcolor="aqua") # The second rectangle represents the water at the right side of the lock (fixed level) sim.AnimateRectangle(spec=(xdoor[right], ylevel[right] - waterdepth, xbound[right], ylevel[right]), fillcolor="aqua") # The third rectangle represents the water inside the lock, which will be switching sim.AnimateRectangle(spec=lock_water_rectangle, fillcolor="aqua") # The fourth rectangle is the left door, which will be apearing and dissapearing sim.AnimateRectangle(spec=lock_door_left_rectangle) # The fifth rectangle is the right door, which will be apearing and dissapearing sim.AnimateRectangle(spec=lock_door_right_rectangle) # AnimateSlider is a class of Salabim to allow adjusting some parameters on the screen during the simulation # In this example, we can adjust the interarrival time and the ships mean length sim.AnimateSlider( x=520, y=0, width=100, height=20, vmin=16, vmax=60, resolution=4, v=iat, label="iat", action=set_iat, xy_anchor="nw", ) sim.AnimateSlider( x=660, y=0, width=100, height=20, vmin=10, vmax=60, resolution=5, v=meanlength, label="mean length", action=set_meanlength, xy_anchor="nw", ) # The class AnimateMonitor allows display monitors on the screen while running the simulation sim.AnimateMonitor( wait[left].length, linecolor="orange", fillcolor="bg", x=-225, y=-200, xy_anchor="n", horizontal_scale=1, width=450, linewidth=2, title=lambda: "Number of waiting ships left. Mean={:10.2f}".format( wait[left].length.mean()), ) sim.AnimateMonitor( wait[right].length, linecolor="orange", fillcolor="bg", x=-225, y=-300, xy_anchor="n", horizontal_scale=1, width=450, linewidth=2, title=lambda: "Number of waiting ships right. Mean={:10.2f}".format( wait[right].length.mean()), ) sim.AnimateMonitor( wait[left].length_of_stay, linecolor="white", fillcolor="bg", x=-225, y=-400, xy_anchor="n", vertical_scale=0.5, horizontal_scale=5, as_points=True, width=450, height=75, linewidth=4, title=lambda: "Waiting time of ships left. Mean={:10.2f}".format(wait[ left].length_of_stay.mean()), ) sim.AnimateMonitor( wait[right].length_of_stay, linecolor="white", fillcolor="bg", x=-225, y=-500, xy_anchor="n", vertical_scale=0.5, horizontal_scale=5, as_points=True, width=450, height=75, linewidth=4, title=lambda: "Waiting time of ships left. Mean={:10.2f}".format(wait[ right].length_of_stay.mean()), ) # There is another queue in the system, the one inside the lock while switching: lockqueue sim.AnimateQueue(queue=lockqueue, x=lambda: xdoor[-lock.sideq], y=lock_y, direction=lambda: "w" if lock.sideq == left else "e")
def process(self): while True: yield self.hold(sim.Uniform(0, 20)()) self.enter(q) yield self.hold(sim.Uniform(0, 20)()) self.leave() env = sim.Environment(trace=False) env.background_color("20%gray") q = sim.Queue("queue") qa0 = sim.AnimateQueue(q, x=100, y=25, title="queue, normal", direction="e", id="blue") qa1 = sim.AnimateQueue(q, x=100, y=75, title="queue, reversed", direction="e", reverse=True, id="green") qa2 = sim.AnimateQueue(q, x=100, y=125, title="queue, maximum 6 components", direction="e", max_length=6,