Example #1
0
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')
Example #2
0
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")
Example #3
0
# }
con.ddgGenerator(ddgGenerator1_config)
# con.ddgGenerator(ddgGenerator2_config)

sup.takeGenerator({
    'arrival_dist': TAKE_ARRIVAL_DIST,
    'resource': TLAMs1,
    'n_supplied': TAKE_N_SUPPLIED,
})

# 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,
Example #4
0
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')

sim.AnimateText('queue, text only', x=80, y=460, text_anchor='sw', angle=270)
qa3 = sim.AnimateQueue(q, x=100, y=460, direction='s', id='text')

sim.AnimateMonitor(q.length,
                   x=10,
                   y=480,
                   width=450,
                   height=100,
                   horizontal_scale=5,
                   vertical_scale=5)

sim.AnimateMonitor(q.length_of_stay,
                   x=10,
                   y=600,
                   width=450,
                   height=100,
                   horizontal_scale=5,
                   vertical_scale=5)

sim.AnimateText(text=lambda: q.length.print_histogram(as_str=True),
                x=500,
                y=700,
Example #5
0
            yield self.hold(sim.Uniform(0, 20)())
            self.enter(self.q)
            yield self.hold(sim.Uniform(0, 20)())
            self.leave()


env = sim.Environment(trace=False)
env.background_color("white")

q0 = sim.Queue("Drilling station")
q1 = sim.Queue("Packaging station")

sim.AnimateMonitor(q0.length,
                   x=10,
                   y=10,
                   width=500,
                   height=300,
                   horizontal_scale=10,
                   vertical_scale=20)
sim.AnimateMonitor(q0.length_of_stay,
                   x=10,
                   y=360,
                   width=500,
                   height=300,
                   horizontal_scale=10,
                   vertical_scale=20)

sim.AnimateMonitor(q1.length,
                   x=520,
                   y=10,
                   width=500,
Example #6
0
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')
Example #7
0
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')
Example #8
0
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 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")
modes = "abc def ghi jkl".split()

r = sim.Resource("r")
x0 = X(process="")
x1 = X(process="")
x2 = X(process="")
Interrupter()

sim.AnimateMonitor(
    monitor=x0.status,
    labels=sim.statuses(),
    x=100,
    y=10,
    linewidth=3,
    horizontal_scale=10,
    width=890,
    height=100,
    vertical_scale=12,
    vertical_map=status_map,
    vertical_offset=10,
)
sim.AnimateMonitor(
    monitor=x1.status,
    labels=sim.statuses(),
    x=100,
    y=210,
    linewidth=3,
    horizontal_scale=10,
    width=890,
    height=100,