def define_environment(self): self.env = sim.Environment(trace=self.tracing, time_unit="minutes") self.env.modelname( "Circuit Board Production: A Two-Stage Hybrid Flow Shop Scheduling Problem" ) self.env.animation_parameters( animate=self.animation, synced=False, width=ENV_W, height=ENV_H, background_color="60%gray", ) if self.animation == True: self.info_makespan = sim.AnimateText(text="Makespan: ", x=10, y=420, fontsize=GLOB_FONTSIZE) self.info_tardiness = sim.AnimateText(text="Total Tardiness: 0", x=10, y=390, fontsize=GLOB_FONTSIZE) self.info_setups = sim.AnimateText(text="Major Setups: 0", x=10, y=360, fontsize=GLOB_FONTSIZE)
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(): 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 process(self, myname): start = env.t an = sim.AnimateText("Hello " + myname, x=lambda t: (t - start) * 100, y=100) yield self.hold(10) an.remove() y.activate()
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 animation(): env.animation_parameters(synced=False, modelname='Job shop', background_color='20%gray') max_len = 0 for i, group in enumerate(groups): x = i * 70 + 100 + 2 y = env.height() - 140 + 20 sim.AnimateText(text=group.name(), x=x, y=y, text_anchor='sw', fontsize=12) for j, machine in enumerate(group.machines): sim.AnimateRectangle( spec=(0, 0, 60, 12), x=x, y=y - 20 - j * 15, fillcolor=lambda machine, t: machine.group.color if machine.task else (machine.group.color, 100), textcolor='white', text=lambda machine, t: machine.task.name() if machine.task else '', arg=machine) max_len = max(max_len, len(group.machines)) env.y_top = y - max_len * 15 - 15 sim.AnimateLine(spec=(0, env.y_top, 2000, env.y_top)) sim.AnimateText(text='job', x=50, y=env.y_top - 15, text_anchor='ne', fontsize=12) sim.AnimateText(text='slack', x=90, y=env.y_top - 15, text_anchor='ne', fontsize=12)
def animation_objects(self, id): if id == 'text': ao0 = sim.AnimateText(text=self.name(), textcolor='fg', text_anchor='nw') return 0, 16, ao0 else: ao0 = sim.AnimateRectangle((0, 0, 40, 20), text=self.name(), fillcolor=id, textcolor='white', arg=self) return 45, 0, ao0
def animation_objects(self, id): ''' the way the component is determined by the id, specified in AnimateQueue 'text' means just the name any other value represents the colour ''' if id == 'text': ao0 = sim.AnimateText(text=self.name(), textcolor='fg', text_anchor='nw', offsetx=-20) return 0, 16, ao0 else: ao0 = sim.AnimateRectangle((-20, 0, 20, 20), text=self.name(), fillcolor=id, textcolor='white', arg=self) return 45, 0, ao0
def draw_legend(): delta = x_max - x_min size = 0.75 sim.AnimateText(text="""\ Legend ----------------- Movable Bridge Unmovable Bridge Lock Vessel Crossroad Water ----------------- """, textcolor='black', fontsize=2, text_anchor='nw', x=x_min + 0.7 * delta, y=y_min + 0.3 * delta) sim.Animate(circle0=(size, ), fillcolor0="yellow", x0=x_min + 0.7 * delta, y0=y_min + 0.238 * delta) sim.Animate(circle0=(size, ), fillcolor0="turquoise", x0=x_min + 0.7 * delta, y0=y_min + 0.2205 * delta) sim.Animate(circle0=(size, ), fillcolor0="orangered", x0=x_min + 0.7 * delta, y0=y_min + 0.203 * delta) sim.Animate(circle0=(size, ), fillcolor0="black", x0=x_min + 0.7 * delta, y0=y_min + 0.1855 * delta) sim.Animate(circle0=(size, ), fillcolor0="red", x0=x_min + 0.7 * delta, y0=y_min + 0.168 * delta) sim.Animate(circle0=(size, ), fillcolor0="blue", x0=x_min + 0.7 * delta, y0=y_min + 0.1505 * delta)
def animation_objects(self, id): """ the way the component is determined by the id, specified in AnimateQueue 'text' means just the name any other value represents the colour """ if id == "text": ao0 = sim.AnimateText(text=self.name(), textcolor="fg", text_anchor="nw", offsetx=-20) return 0, 16, ao0 else: ao0 = sim.AnimateRectangle((-20, 0, 20, 20), text=self.name(), fillcolor=id, textcolor="white", arg=self) return 45, 0, ao0
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') 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')
''' This program demonstrates the various animation classes available in salabim. ''' env = sim.Environment(trace=False) env.animate(True) env.modelname('Demo animation classes') env.background_color('20%gray') sim.AnimatePolygon(spec=(100, 100, 300, 100, 200,190), text='This is\na polygon') sim.AnimateLine(spec=(100, 200, 300, 300), text='This is a line') sim.AnimateRectangle(spec=(100, 10, 300, 30), text='This is a rectangle') sim.AnimateCircle(radius=60, x=100, y=400, text='This is a cicle') sim.AnimateCircle(radius=60, radius1=30, x=300, y=400,text='This is an ellipse') sim.AnimatePoints(spec=(100,500, 150, 550, 180, 570, 250, 500, 300, 500), text='These are points') sim.AnimateText(text='This is a one-line text', x=100, y=600) sim.AnimateText(text='''\ Multi line text ----------------- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
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(): # 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")
def setup(self): self.wait_anim = sim.AnimateRectangle(self.my_rectangle, x=200, y=self.my_y, fillcolor='red', text=str(self.sequence_number()), text_anchor='w', text_offsetx=-20, textcolor='white', arg=self, parent=self) # the arg parameter is used to access the right car in my_y and my_rectangle (self) # the parent parameter is used to automatically remove the animation when the car terminates def process(self): yield self.request(washers) duration = sim.Uniform(0, 5)() self.duration_anim = sim.AnimateRectangle((0, 0, duration * 10, 20), fillcolor='', linecolor='yellow', x=100, y=self.my_y, arg=self, parent=self) self.wait_anim.fillcolor = 'yellow' self.wait_anim.x = 100 yield self.hold(duration) env = sim.Environment(trace=False) env.animate(True) env.modelname('Demo animation dynamic') env.background_color('20%gray') sim.AnimateText('Wash', x=100, y=25, text_anchor='sw') sim.AnimateText('Wait', x=200, y=25, text_anchor='sw') washers = sim.Resource(name='washers', capacity=2) CarGenerator() env.run(100)
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 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 process(self): yield self.request(washers) duration = sim.Uniform(0, 5)() self.duration_anim = sim.AnimateRectangle( spec=(0, 0, duration * 10, 20), x=100, y=lambda arg, t: arg.index(list(self.queues())[0]) * 30 + 50, fillcolor="", linecolor="yellow", arg=self, parent=self, ) self.wait_anim.fillcolor = "yellow" self.wait_anim.x = 100 yield self.hold(duration) env = sim.Environment(trace=False) env.animate(True) env.modelname("Demo animation dynamic lambda") env.background_color("20%gray") sim.AnimateText("Wash", x=100, y=25, text_anchor="sw") sim.AnimateText("Wait", x=200, y=25, text_anchor="sw") washers = sim.Resource(name="washers", capacity=2) CarGenerator() env.run(100)
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)] env.animate(True) env.modelname('Demo queue animation') env.run()
}) # Animation # > Queue length line plot sim.AnimateMonitor(monitor=queue1.length, x=ani.q_lineplot_x_left, y=ani.q_lineplot_y_bottom, width=ani.q_lineplot_width, height=ani.q_lineplot_height, 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,
def setup( self, model, predecessors, img_w=None, img_h=None, img_x=None, img_y=None, img_slots=None, ): # model self.model = model # initial attributes self.predecessors = predecessors self.img_w = img_w self.img_h = img_h self.img_x = img_x self.img_y = img_y self.img_slots = img_slots # flags self.workload = 0 # visualization if self.model.env.animate() == True: self.img = [ [ sim.AnimateRectangle( spec=(0, 0, (self.img_w / self.img_slots), self.img_h), x=self.img_x + i * (self.img_w / self.img_slots), y=self.img_y, fillcolor="white", linecolor="white", linewidth=1, layer=2, arg=( self.img_x + (i * (self.img_w / self.img_slots)) + (self.img_w / (self.img_slots * 2)), self.img_y + (self.img_h / 2), ), screen_coordinates=True, ) for i in range(self.img_slots) ], sim.AnimateRectangle( spec=(0, 0, self.img_w, self.img_h), x=self.img_x, y=self.img_y, fillcolor="white", linecolor="black", linewidth=2, layer=1, screen_coordinates=True, ), ] self.predecessor_connections = [ sim.AnimateLine( spec=( predecessor.img_x + predecessor.img_w, predecessor.img_y if predecessor.__class__.__name__ == "Source" else predecessor.img_y + predecessor.img_h / 2, self.img_x, self.img_y + self.img_h / 2, ), linecolor="black", linewidth=2, layer=2, screen_coordinates=True, ) for predecessor in self.predecessors ] self.info = sim.AnimateText( text="# products: 0", x=self.img[0][0].x, y=self.img[0][0].y - 20, fontsize=18, textcolor="black", screen_coordinates=True, )