def animation_objects(self): ao0 = sim.AnimateRectangle(spec=lambda arg, t: (0, 0, arg.l(t), 20), fillcolor=lambda arg, t: 'orange' if self in repairman.claimers() else 'red', textcolor='white', text=self.ident, arg=self) return lambda arg, t: arg.l(t) + 2, 0, ao0
def setup(self): self.x = env.x_dis() self.y = env.y_dis() self.an = sim.AnimateRectangle((-10, -10, 10, 10), text='R' + str(self.sequence_number()), x=self.x, y=self.y, text_anchor='c')
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)
def animation_objects(self): ao0 = sim.AnimateRectangle( spec=lambda task, t: (0, 0, (task.duration - (0 if task.start_execution is None else (t - task.start_execution))) * scale_x, 12), fillcolor=lambda task, t: (task.group.color, 80) if task.start_execution is None else task.group.color, arg=self) return lambda task, t: (task.duration - (0 if task.start_execution is None else (t - task.start_execution))) * scale_x, 0, ao0
def animation_objects(self, q): size_x = xvisitor_dim size_y = yvisitor_dim b = 0.1 * xvisitor_dim an0 = sim.AnimateRectangle(spec=(b, 2, xvisitor_dim - b, yvisitor_dim - b), linewidth=0, fillcolor=direction_color(self.direction), text=str(self.tofloor.n), fontsize=xvisitor_dim * 0.7, textcolor='white') return size_x, size_y, an0
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 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, )
def setup(self): self.wait_anim = sim.AnimateRectangle( spec=lambda arg, t: (0, 0, (t - arg.enter_time(arg.queues()[0])) * 10, 20), x=200, y=lambda arg, t: arg.index(arg.queues()[0]) * 30 + 50, fillcolor='red', text=str(self.sequence_number()), text_anchor='w', text_offsetx=-20, textcolor='white', arg=self, parent=self)
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 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 animation_objects(self, q): size_x = xvisitor_dim # how much to displace the next component in x-direction size_y = yvisitor_dim # how much to displace the next component in y-direction b = 0.1 * xvisitor_dim # Instances of Animate class: an0 = sim.AnimateRectangle( spec=(b, 2, xvisitor_dim - b, yvisitor_dim - b), linewidth=0, fillcolor=direction_color(self.direction), text=str(self.tofloor.n), fontsize=xvisitor_dim * 0.7, textcolor="white", ) return size_x, size_y, an0
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(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)
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')
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 setup(self, restaurant, customer): self.restaurant = restaurant self.customer = customer self.driver = sim.Pdf(env.drivers, 1)() self.enter(self.driver.orders) self.enter(env.orders) self.pic_customer = sim.AnimateRectangle( (-10, -10, 10, 10), text=str(self.customer.sequence_number()), fillcolor='gray', x=self.customer.x, y=self.customer.y) self.pic_order = sim.AnimateLine((self.restaurant.x, self.restaurant.y, self.customer.x, self.customer.y), linecolor=self.driver.color, text=self.name(), textcolor=self.driver.color, linewidth=2) if self.driver.ispassive(): self.driver.activate()
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)
import salabim as sim ''' 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.
# 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") , # 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,
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(): 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')
env = sim.Environment(trace=False, random_seed=1021021) x_min = 25 y_min = 25 x_max = 1000 y_max = 550 n_drivers = 3 n_restaurants = 5 n_customers = 25 v = 10 inter_arrival_time = sim.Exponential(1000) env.x_dis = sim.Uniform(x_min, x_max) env.y_dis = sim.Uniform(y_min, y_max) sim.AnimateRectangle((x_min, y_min, x_max, y_max), fillcolor='90%gray') env.customers = [ Customer(inter_arrival_time=inter_arrival_time) for _ in range(n_customers) ] env.drivers = [Driver(v=v) for _ in range(n_drivers)] env.restaurants = [Restaurant() for _ in range(n_restaurants)] env.orders = sim.Queue('all orders') env.animate(True) env.speed(16) env.modelname('pizza delivery') env.orders.length.animate(x=x_min, y=y_max + 20, horizontal_scale=2, width=x_max - x_min,
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")
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') env.run(till=SIM_LENGTH) # Simulation statistics # TLAMs.available_quantity.print_histogram() # fast_ERT.print_statistics() # TLAMs1.print_info()
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, )