### Component Setup Example Source: https://www.salabim.org/manual/Reference.html Override the default setup method to initialize component-specific attributes during instantiation. Keyword arguments are passed to this method. ```python class Car(sim.Component): def setup(self, color): self.color = color redcar=Car(color="red") bluecar=Car(color="blue") ``` -------------------------------- ### Salabim 3D Animation Setup and Camera Movement Source: https://www.salabim.org/manual/3dAnimation.html This example demonstrates setting up a Salabim environment for 3D animation, including background color, window dimensions, and animation enabling. It defines two circular trajectories and corresponding animated boxes, then sets a detailed camera movement path. ```python import salabim as sim env = sim.Environment() env.background_color("90%gray") env.width(900) env.height(700) env.position((1000,0)) env.width3d(900) env.height3d(700) env.position3d((0,100)) env.animate(True) env.animate(True) env.animate3d(True) env.show_camera_position() env.show_camera_position(over3d=True) sim.Animate3dGrid(x_range=range(-2,3), y_range=range(-2,3)) traj0 = sim.TrajectoryCircle(radius=2, vmax=1) d0 =traj0.duration() sim.Animate3dBox(x_len=1,y_len=1,z_len=1,color="red", x=lambda t:traj0.x(t%d0), y=lambda t:traj0.y(t%d0), z=0.5, z_angle=lambda t:traj0.angle(t%d0)) traj1 = sim.TrajectoryCircle(radius=1, vmax=1,angle0=360,angle1=0) d1 =traj1.duration() sim.Animate3dBox(x_len=0.5,y_len=0.5,z_len=0.5,color="green", x=lambda t:traj1.x(t%d1), y=lambda t:traj1.y(t%d1), z=0.25, z_angle=lambda t:traj1.angle(t%d1)) env.camera_move(""" view(x_eye=4.0000,y_eye=4.0000,z_eye=4.0000,x_center=0.0000,y_center=0.0000,z_center=0.0000,field_of_view_y=45.0000) # t=0.0000 view(x_eye=3.6000,y_eye=3.6000,z_eye=3.6000) # t=0.4957 view(x_eye=3.2400,y_eye=3.2400,z_eye=3.2400) # t=0.9443 view(x_eye=3.2961,y_eye=3.1830) # t=1.6593 view(x_eye=3.2961,y_eye=3.1830,z_eye=2.9160) # t=3.3829 view(x_eye=3.2961,y_eye=3.1830,z_eye=2.6244) # t=3.5666 view(x_eye=3.2961,y_eye=3.1830,z_eye=2.3620) # t=3.7464 view(x_eye=3.2961,y_eye=3.1830,z_eye=2.1258) # t=3.8976 view(x_eye=3.2961,y_eye=3.1830,z_eye=1.9132) # t=4.1154 view(x_eye=3.2961,y_eye=3.1830,z_eye=1.7219) # t=4.3627 view(x_eye=3.2961,y_eye=3.1830,z_eye=1.5497) # t=4.5476 view(x_eye=3.2961,y_eye=3.1830,z_eye=1.3947) # t=4.7275 view(x_eye=3.3511,y_eye=3.1250) # t=5.3634 view(field_of_view_y=40.5000) # t=6.4102 view(field_of_view_y=36.4500) # t=6.7709 view(field_of_view_y=40.5000) # t=7.2002 view(field_of_view_y=45.0000) # t=7.3853 view(field_of_view_y=50.0000) # t=7.5354 view(field_of_view_y=55.5556) # t=7.6858 view(field_of_view_y=61.7284) # t=7.8731 view(field_of_view_y=68.5871) # t=8.0212 view(field_of_view_y=76.2079) # t=8.2113 view(field_of_view_y=84.6754) # t=8.4003 view(field_of_view_y=94.0838) # t=8.5829 view(field_of_view_y=104.5376) # t=8.7949 view(field_of_view_y=116.1529) # t=9.0388 view(field_of_view_y=129.0587) # t=9.2250 view(field_of_view_y=143.3986) # t=9.4486 view(field_of_view_y=129.0587) # t=11.0184 view(x_eye=4.0000,y_eye=4.0000,z_eye=4.0000,x_center=0.0000,y_center=0.0000,z_center=0.0000,field_of_view_y=45.0000) # t=11.6400 """, lag=1) env.run(sim.inf) ``` -------------------------------- ### Initialize Components with setup Source: https://www.salabim.org/manual/Component.html Use the setup method for initialization, which executes after the component's internal initialization. ```python class Ship(sim.Component): def setup(self, length): self.length = length ship = Ship(length=250) ``` -------------------------------- ### Initialize Components with setup Source: https://www.salabim.org/manual/_sources/Component.rst.txt Use the setup method to initialize attributes after the component is fully created. ```python class Ship(sim.Component): def setup(self, length): self.length = length ship = Ship(length=250) ``` -------------------------------- ### Setup and Initialization Source: https://www.salabim.org/manual/Reference.html Initializes the environment immediately after creation. This method can be overridden for custom setup logic. ```APIDOC ## setup ### Description Called immediately after initialization of an environment. By default this is a dummy method, but it can be overridden. Only keyword arguments are passed. ### Method Not specified (likely called internally during environment setup) ### Endpoint N/A (internal method) ### Parameters #### Keyword Arguments - **kwargs** (Any) - Any keyword arguments passed during initialization. ``` -------------------------------- ### Resource Setup API Source: https://www.salabim.org/manual/Reference.html API for resource setup after initialization. ```APIDOC ## POST /websites/salabim_manual/setup ### Description Called immediately after initialization of a resource. By default, this is a dummy method but can be overridden. ### Method POST ### Endpoint /websites/salabim_manual/setup ### Parameters #### Request Body - **kwargs** (Any) - Accepts any keyword arguments. ``` -------------------------------- ### Full 3D Animation Example Source: https://www.salabim.org/manual/_sources/3dAnimation.rst.txt A complete setup for a 3D environment with animated boxes and camera paths. ```python import salabim as sim env = sim.Environment() env.background_color("90%gray") env.width(900) env.height(700) env.position((1000,0)) env.width3d(900) env.height3d(700) env.position3d((0,100)) env.animate(True) env.animate(True) env.animate3d(True) env.show_camera_position() env.show_camera_position(over3d=True) sim.Animate3dGrid(x_range=range(-2,3), y_range=range(-2,3)) traj0 = sim.TrajectoryCircle(radius=2, vmax=1) d0 =traj0.duration() sim.Animate3dBox(x_len=1,y_len=1,z_len=1,color="red", x=lambda t:traj0.x(t%d0), y=lambda t:traj0.y(t%d0), z=0.5, z_angle=lambda t:traj0.angle(t%d0)) traj1 = sim.TrajectoryCircle(radius=1, vmax=1,angle0=360,angle1=0) d1 =traj1.duration() sim.Animate3dBox(x_len=0.5,y_len=0.5,z_len=0.5,color="green", x=lambda t:traj1.x(t%d1), y=lambda t:traj1.y(t%d1), z=0.25, z_angle=lambda t:traj1.angle(t%d1)) env.camera_move("""\ view(x_eye=4.0000,y_eye=4.0000,z_eye=4.0000,x_center=0.0000,y_center=0.0000,z_center=0.0000,field_of_view_y=45.0000) # t=0.0000 view(x_eye=3.6000,y_eye=3.6000,z_eye=3.6000) # t=0.4957 view(x_eye=3.2400,y_eye=3.2400,z_eye=3.2400) # t=0.9443 view(x_eye=3.2961,y_eye=3.1830) # t=1.6593 view(x_eye=3.2961,y_eye=3.1830,z_eye=2.9160) # t=3.3829 view(x_eye=3.2961,y_eye=3.1830,z_eye=2.6244) # t=3.5666 view(x_eye=3.2961,y_eye=3.1830,z_eye=2.3620) # t=3.7464 view(x_eye=3.2961,y_eye=3.1830,z_eye=2.1258) # t=3.8976 view(x_eye=3.2961,y_eye=3.1830,z_eye=1.9132) # t=4.1154 view(x_eye=3.2961,y_eye=3.1830,z_eye=1.7219) # t=4.3627 view(x_eye=3.2961,y_eye=3.1830,z_eye=1.5497) # t=4.5476 view(x_eye=3.2961,y_eye=3.1830,z_eye=1.3947) # t=4.7275 view(x_eye=3.3511,y_eye=3.1250) # t=5.3634 view(field_of_view_y=40.5000) # t=6.4102 view(field_of_view_y=36.4500) # t=6.7709 view(field_of_view_y=40.5000) # t=7.2002 view(field_of_view_y=45.0000) # t=7.3853 view(field_of_view_y=50.0000) # t=7.5354 view(field_of_view_y=55.5556) # t=7.6858 view(field_of_view_y=61.7284) # t=7.8731 view(field_of_view_y=68.5871) # t=8.0212 view(field_of_view_y=76.2079) # t=8.2113 view(field_of_view_y=84.6754) # t=8.4003 view(field_of_view_y=94.0838) # t=8.5829 view(field_of_view_y=104.5376) # t=8.7949 view(field_of_view_y=116.1529) # t=9.0388 view(field_of_view_y=129.0587) # t=9.2250 view(field_of_view_y=143.3986) # t=9.4486 view(field_of_view_y=129.0587) # t=11.0184 view(x_eye=4.0000,y_eye=4.0000,z_eye=4.0000,x_center=0.0000,y_center=0.0000,z_center=0.0000,field_of_view_y=45.0000) # t=11.6400 """, lag=1) env.run(sim.inf) ``` -------------------------------- ### Component Setup for Animation Source: https://www.salabim.org/manual/_sources/Animation.rst.txt Defines the setup method for a Salabim component, which can be used to prepare objects for animation. ```python class X(sim.Component): def setup(self, i): self.i = i ``` -------------------------------- ### Install Salabim from PyPI Source: https://www.salabim.org/manual/_sources/Overview.rst.txt Install the Salabim package and its dependency 'greenlet' using pip. This is the recommended method for installation and upgrades. ```bash pip install salabim pip install greenlet ``` -------------------------------- ### Bank Simulation Model in Python Source: https://www.salabim.org/manual/Modelling.html This is the main simulation code for the bank example. It defines customer generation, customer behavior, clerk process, and simulation environment setup. Ensure Salabim is installed. ```python import salabim as sim class CustomerGenerator(sim.Component): def process(self): while True: Customer() self.hold(sim.Uniform(5, 15).sample()) class Customer(sim.Component): def process(self): self.enter(waitingline) if clerk.ispassive(): clerk.activate() self.passivate() class Clerk(sim.Component): def process(self): while True: while len(waitingline) == 0: self.passivate() self.customer = waitingline.pop() self.hold(30) self.customer.activate() env = sim.Environment(trace=True) CustomerGenerator() clerk = Clerk() waitingline = sim.Queue("waitingline") env.run(till=50) print() waitingline.print_statistics() ``` -------------------------------- ### Install Salabim and Greenlet from PyPI Source: https://www.salabim.org/manual/Overview.html The recommended method for installing Salabim and its dependency, greenlet, using pip. This ensures you get the latest stable versions. ```bash pip install salabim pip install greenlet ``` -------------------------------- ### Component Setup Source: https://www.salabim.org/manual/Reference.html The setup method is called immediately after a component is initialized. It can be overridden to perform custom initialization logic using keyword arguments. ```APIDOC ## POST /websites/salabim_manual/setup ### Description Initializes a component immediately after its creation. This method can be overridden for custom setup logic. ### Method POST ### Endpoint /websites/salabim_manual/setup ### Parameters #### Request Body - **kwargs** (Any) - Optional - Keyword arguments for initialization. ### Request Example { "kwargs": { "color": "red" } } ### Response #### Success Response (200) - **None** - This method does not return any value. ### Note Only keyword arguments will be passed. Example usage within a class: ```python class Car(sim.Component): def setup(self, color): self.color = color redcar = Car(color='red') bluecar = Car(color='blue') ``` ``` -------------------------------- ### Install PySimpleGUI for Salabim Source: https://www.salabim.org/manual/_sources/UI.rst.txt Commands to install the required PySimpleGUI package for the graphical UI. ```bash pip install PySimpleGUI-4-foss ``` ```bash pip install pysimplegui ``` -------------------------------- ### Example Queue Info Output Source: https://www.salabim.org/manual/Queue.html This is an example of the output generated by `q.print_info()`, showing queue details and customer entries. ```text Queue 0x20e116153c8 name=waitingline component(s): customer.4995 enter_time 49978.472 priority=0 customer.4996 enter_time 49991.298 priority=0 ``` -------------------------------- ### Install 3D OpenGL Installer Script Source: https://www.salabim.org/manual/_sources/Overview.rst.txt Execute a Python script to install OpenGL, required for 3D animation on Windows. This script is fetched directly from the Salabim GitHub repository. ```python python -c "import requests;exec(requests.get('https://raw.githubusercontent.com/salabim/salabim/master/tools/opengl_installer.py').text)" ``` -------------------------------- ### Install OpenCV and NumPy for Video Production Source: https://www.salabim.org/manual/Overview.html Install the opencv-python and numpy packages, which are necessary for video production capabilities within Salabim. ```bash pip install opencv-python pip install numpy ``` -------------------------------- ### Install PyOpenGL for 3D Animation on Linux Source: https://www.salabim.org/manual/_sources/Overview.rst.txt Install PyOpenGL and its acceleration package for 3D animation capabilities on Linux systems. Also includes the command to install the freeglut development library. ```bash pip3 install pyopengl pip3 install pyopengl-accelerate sudo apt-get install freeglut3-dev ``` -------------------------------- ### Setup Queue Initialization Source: https://www.salabim.org/manual/Reference.html A method called immediately after a queue is initialized. It can be overridden to perform custom setup actions using keyword arguments. ```python setup(_** kwargs: Any_) → None ``` -------------------------------- ### Initialize Simulation Environment and Animation Source: https://www.salabim.org/manual/_sources/Animation.rst.txt Sets up the environment, queues, monitors, and starts the animation loop. ```python env = sim.Environment(trace=False) env.background_color('20%gray') q = sim.Queue('queue') qa0 = sim.AnimateQueue(q, x=100, y=50, title='queue, normal', direction='e', id='blue') qa1 = sim.AnimateQueue(q, x=100, y=250, title='queue, maximum 6 components', direction='e', max_length=6, id='red') qa2 = sim.AnimateQueue(q, x=100, y=150, title='queue, reversed', direction='e', reverse=True, id='green') qa3 = sim.AnimateQueue(q, x=100, y=440, 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() ``` -------------------------------- ### Salabim Simulation Output Example Source: https://www.salabim.org/manual/_sources/Modelling.rst.txt This is an example of the output generated by Salabim's print_statistics() method, detailing simulation events and timings. ```none line# time current component action information ------ ---------- -------------------- ----------------------------------- line numbers refers to Bank, 1 clerk.py 30 default environment initialize 30 main create 30 0.000 main current 32 customergenerator.0 create 32 customergenerator.0 activate scheduled for 0.000 @ 6+ process=process 33 clerk.0 create 33 clerk.0 activate scheduled for 0.000 @ 21+ process=process 34 waitingline create 36 main run +50.000 scheduled for 50.000 @ 36+ 6+ 0.000 customergenerator.0 current 8 customer.0 create 8 customer.0 activate scheduled for 0.000 @ 13+ process=process 9 customergenerator.0 hold +14.631 scheduled for 14.631 @ 9+ 21+ 0.000 clerk.0 current 24 clerk.0 passivate @ 24+ 13+ 0.000 customer.0 current 14 customer.0 enter waitingline 16 clerk.0 activate scheduled for 0.000 @ 24+ 17 customer.0 passivate @ 17+ 24+ 0.000 clerk.0 current 25 customer.0 leave waitingline 26 clerk.0 hold +30.000 scheduled for 30.000 @ 26+ 9+ 14.631 customergenerator.0 current 8 customer.1 create 8 customer.1 activate scheduled for 14.631 @ 13+ process=process 9 customergenerator.0 hold +7.357 scheduled for 21.989 @ 9+ 13+ 14.631 customer.1 current 14 customer.1 enter waitingline 17 customer.1 passivate @ 17+ 9+ 21.989 customergenerator.0 current 8 customer.2 create 8 customer.2 activate scheduled for 21.989 @ 13+ process=process 9 customergenerator.0 hold +10.815 scheduled for 32.804 @ 9+ 13+ 21.989 customer.2 current 14 customer.2 enter waitingline 17 customer.2 passivate @ 17+ 26+ 30.000 clerk.0 current 27 customer.0 activate scheduled for 30.000 @ 17+ 25 customer.1 leave waitingline 26 clerk.0 hold +30.000 scheduled for 60.000 @ 26+ 17+ 30.000 customer.0 current 17+ customer.0 ended 9+ 32.804 customergenerator.0 current 8 customer.3 create 8 customer.3 activate scheduled for 32.804 @ 13+ process=process 9 customergenerator.0 hold +7.267 scheduled for 40.071 @ 9+ 13+ 32.804 customer.3 current 14 customer.3 enter waitingline 17 customer.3 passivate @ 17+ 9+ 40.071 customergenerator.0 current 8 customer.4 create 8 customer.4 activate scheduled for 40.071 @ 13+ process=process ``` -------------------------------- ### Distribution Specification Examples Source: https://www.salabim.org/manual/_sources/Distributions.rst.txt Provides examples of distribution specifications that can be read by sim.Distribution, including standard and abbreviated forms. ```python Uniform(10, 15) Triangular(1, 5, 2, time_unit='minutes') IntUniform(10, 20) ``` ```python Uni(10,15) Tri(1, 5, 2, time_unit='minutes') Int(10, 20) ``` ```python U(10, 15) T(1, 5, 2, time_unit='minutes') I(10, 20) ``` ```python Extern(random.uniform, 2, 6) ``` ```python Ext(random.uniform, 2, 6) ``` -------------------------------- ### Animate Square Example Source: https://www.salabim.org/manual/_sources/Animation.rst.txt Shows how to create a square animation. The first example displays a square around (100,100) indefinitely. The second example shows the same square moving from (100,100) to (200,0) over 10 time units. ```python Animate(x0=100,y0=100,rectangle0==(-10,-10,10,10)) ``` ```python Animate(t1=env.now()+10,x0=100,y0=100,x1=200,y1=0,rectangle0=(-10,-10,10,10)) ``` -------------------------------- ### Start Salabim Animation Source: https://www.salabim.org/manual/_sources/3dAnimation.rst.txt To start both 2D and 3D animations, set the environment's animate flag to True. This should be called after enabling 3D animation. ```python env.animate(True) ``` -------------------------------- ### Install PyWavefront and Pyglet for OBJ Files Source: https://www.salabim.org/manual/Overview.html Install pywavefront for loading .obj files and pyglet version 1.4.0, which is specifically required for compatibility with pywavefront in 3D animations. ```bash pip install pywavefront pip install pyglet==1.4.0 ``` -------------------------------- ### Install Pillow Package Source: https://www.salabim.org/manual/Overview.html Install the Pillow library, which is required for image manipulation and animation support in Salabim, especially on CPython distributions that do not include it by default. ```bash pip install Pillow ``` -------------------------------- ### Initialize Environment with Specific Start Datetime Source: https://www.salabim.org/manual/Miscellaneous.html Set a specific starting datetime for the simulation environment. This affects how simulation time is displayed and interpreted. ```python env = sim.Environment(datetime0=datetime.datetime(2022, 4, 29), trace=True) ``` -------------------------------- ### Animate Circle Update Example Source: https://www.salabim.org/manual/_sources/Animation.rst.txt Shows how to initialize an animation object and then update its properties mid-simulation. This example creates a circle that moves horizontally and grows, then updates it to shrink and move vertically. ```python an=Animate(t0=0,t1=10,x0=0,x1=100,y0=0,circle0=(10,),circle1=(20,)) ``` ```python an.update(t1=10,y1=50,circle1=(10,)) ``` -------------------------------- ### Install PyOpenGL and FreeGLUT on Linux Source: https://www.salabim.org/manual/Overview.html Commands to install PyOpenGL, its acceleration module, and the FreeGLUT development library required for 3D animation under Debian-based Linux distributions. ```bash pip3 install pyopengl pip3 install pyopengl-accelerate sudo apt-get install freeglut3-dev ``` -------------------------------- ### Wait logic examples Source: https://www.salabim.org/manual/Reference.html Demonstrations of waiting for single or multiple states with varying priority and logical conditions. ```python yield self.wait(s1) ``` ```python yield self.wait(s1,s2) ``` ```python yield self.wait((s1,False,100),(s2,"on"),s3) ``` ```python yield self.wait(s1,s2,all=True) ``` -------------------------------- ### Enable 3D Animation Source: https://www.salabim.org/manual/3dAnimation.html Enable 3D animation and start the simulation environment. ```python env.animate3d(True) ``` ```python env.animate(True) ``` -------------------------------- ### Define and Manipulate States Source: https://www.salabim.org/manual/_sources/State.rst.txt Basic examples for creating, setting, and retrieving state values. ```python dooropen=sim.State('dooropen') ``` ```python dooropen.set() ``` ```python self.wait(dooropen) ``` ```python dooropen.trigger(max=1) ``` ```python print('door is ',('open' if dooropen() else 'closed')) ``` ```python print('door is ',('open' if dooropen.get() else 'closed')) ``` ```python light=sim.State('light', value='red') ... light.state.set('green') ``` ```python level=sim.State('level', value=0) ... level.set(level()+10) ``` -------------------------------- ### Define Merged Trajectory with Start Times Source: https://www.salabim.org/manual/Trajectory.html This example shows how to create a merged trajectory from multiple sub-trajectories, specifying a start time (t0) for the overall trajectory. Note that t0 values in subsequent sub-trajectories are ignored. ```python traj0 = sim.TrajectoryPolygon(polygon=(0, 0, 0, 600), vmax=50, t0=10) traj1 = sim.TrajectoryCircle(radius=100, x_center=100, y_center=600, angle0=180, angle1=90, t0=5) traj2 = sim.TrajectoryPolygon(polygon=(100, 700, 700, 700), vmax=50, t0=20) traj = sim.TrajectoryMerged((traj0, traj1, traj2)) ``` -------------------------------- ### Initialize Environment with Tracing Enabled Source: https://www.salabim.org/manual/Miscellaneous.html Create a Salabim environment with the trace facility enabled from the start. This will log simulation events. ```python env = sim.Environment(trace=True) ``` -------------------------------- ### Install Pillow Package Source: https://www.salabim.org/manual/_sources/Overview.rst.txt Install the Pillow library, required for animation features on CPython and other platforms. Use this command if Pillow is not already installed. ```bash pip install Pillow ``` -------------------------------- ### Initialize Salabim Environment Source: https://www.salabim.org/manual/_sources/Modelling.rst.txt Standard ways to initialize the simulation environment. ```python import salabim as sim ``` ```python env = sim.Environment() ``` ```python app = sim.App() ``` -------------------------------- ### Get Time Unit Source: https://www.salabim.org/manual/Reference.html Gets the current time unit of the simulation. ```APIDOC ## get_time_unit get_time_unit(template: str = None) -> str ### Description Gets the current time unit. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **str** - The current time unit dimension (default "n/a"). ### Response Example N/A ### Notes - The `template` parameter is typically used in UI functions. - If `template` is "d", returns time unit as duration. - If `template` is "t", returns time unit as time. - If `template` is "(d)", returns time unit as (duration). - If `template` is "(t)", returns time unit as (time). - "n/a" is suppressed, and an extra space is added at the front if the result is not an empty string. ``` -------------------------------- ### Queue Initialization Source: https://www.salabim.org/manual/_sources/Queue.rst.txt How to instantiate a new queue in Salabim. ```APIDOC ## Queue Initialization ### Description Creates a new instance of a Salabim Queue. ### Request Example waitingline = sim.Queue('waitingline') ``` -------------------------------- ### Initialize Simulation Environment and Queues Source: https://www.salabim.org/manual/Animation.html Sets up the simulation environment, including background color, and defines multiple queue objects with different configurations for visualization. This is a foundational step for running a simulation with animated queues. ```python env = sim.Environment(trace=False) env.background_color('20%gray') q = sim.Queue('queue') qa0 = sim.AnimateQueue(q, x=100, y=50, title='queue, normal', direction='e', id='blue') qa1 = sim.AnimateQueue(q, x=100, y=250, title='queue, maximum 6 components', direction='e', max_length=6, id='red') qa2 = sim.AnimateQueue(q, x=100, y=150, title='queue, reversed', direction='e', reverse=True, id='green') qa3 = sim.AnimateQueue(q, x=100, y=440, title='queue, text only', direction='s', id='text') ``` -------------------------------- ### Queue Initialization and Basic Operations Source: https://www.salabim.org/manual/Queue.html Demonstrates how to initialize a Salabim Queue and perform basic operations like adding and retrieving components. ```APIDOC ## Queue Initialization and Basic Operations ### Description This section covers the initialization of a Salabim Queue and fundamental methods for adding and retrieving components. ### Method - `sim.Queue(name)`: Initializes a new queue with a given name. - `q.add(c)` or `q.append(c)`: Adds component `c` to the tail of the queue `q`. - `q.add_at_head(c)`: Adds component `c` to the head of the queue `q`. - `q.remove(c)`: Removes component `c` from the queue `q`. - `q.pop()`: Removes and returns the head component from the queue `q`. - `q.head()` or `q[0]`: Returns the head component of the queue `q` without removing it. - `q.tail()` or `q[-1]`: Returns the tail component of the queue `q` without removing it. - `q.name()`: Returns the name of the queue. ### Request Example ```python import salabim as sim # Initialize a queue waitingline = sim.Queue('waitingline') # Create a component (assuming Component class exists) # c = Component('my_component') # Add component to the queue # waitingline.add(c) # Retrieve the head component # head_component = waitingline.head() # Remove a component # waitingline.remove(c) ``` ### Response #### Success Response (200) - `q.name()` returns a string (the queue's name). - `q.add()`, `q.append()`, `q.add_at_head()`, `q.remove()`, `q.pop()` return `None`. - `q.head()`, `q.tail()` return the component object. #### Response Example ```json { "queue_name": "waitingline", "head_component": {"id": "component1", "type": "machine"} } ``` ``` -------------------------------- ### Typical Salabim Input File Structure Source: https://www.salabim.org/manual/Reading%20items%20from%20a%20file.html An example of a typical input file format for Salabim models, demonstrating comments, quoted strings, and item separators. ```text # Typical experiment file for a salabim model 1000 # run length 'Experiment 2.0' # run name #Model speed color #-------------- ----- ------ 'Peugeot 208' 150 red 'Peugeot 3008' 175 orange 'Citroen C5' 160 blue 'Renault "Twingo"' 165 green // France {country} Europe {continent} #end of file ``` -------------------------------- ### Environment Initialization Source: https://www.salabim.org/manual/Reference.html Initializes a Salabim simulation environment with various configuration options. ```APIDOC ## Environment Initialization ### Description Initializes a Salabim simulation environment with various configuration options. ### Method Constructor for the Environment class ### Endpoint N/A (Class constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **trace** (bool or file handle) - Optional - Defines whether to trace the simulation. If a file handle is provided, trace output is sent to that file. Defaults to False. - **random_seed** (Hashable) - Optional - The seed for random number generation. If "*", a purely random value is used. If None, the default seed 1234567 is used. If the null string, no action on random is taken. Defaults to None. - **set_numpy_random_seed** (bool) - Optional - If True (default), numpy.random.seed() is called with the given seed. Ignored if numpy is not installed. - **time_unit** (str) - Optional - Supported time units: "years", "weeks", "days", "hours", "minutes", "seconds", "milliseconds", "microseconds", "n/a". Defaults to "n/a". - **datetime0** (bool or datetime) - Optional - If True, time and durations are displayed as datetime objects. If falsy (default), disabled. If True and no time_unit is specified, time_unit will be set to seconds. - **name** (str) - Optional - Name of the environment. If omitted, the name is derived from the class or "default environment". - **print_trace_header** (bool) - Optional - If True (default), prints a header line for trace output. Only printed if trace=True. - **isdefault_env** (bool) - Optional - If True (default), this environment becomes the default. If False, it does not. - **retina** (bool) - Optional - Retina display setting. - **do_reset** (bool) - Optional - If True, resets the simulation environment. If False, does not. If None (default), resets under Pythonista, otherwise no reset. - **blind_animation** (bool) - Optional - If False (default), animation runs as expected. If True, animations run silently, useful for servers or when tkinter is not installed. - **yieldless** (bool) - Optional - Yieldless simulation setting. ### Request Example ```python import salabim as sim env = sim.Environment(trace=True, random_seed=123, time_unit='hours') ``` ### Response #### Success Response (200) Environment object created. #### Response Example ```json { "message": "Environment created successfully" } ``` ``` -------------------------------- ### Component Entry Methods for Salabim Queues Source: https://www.salabim.org/manual/_sources/Queue.rst.txt Demonstrates various ways a component can enter a queue, including at the tail, head, in front of another component, behind another component, or sorted by priority. ```python c.enter(q) q.add(c) or q.append(c) c enters q at the tail ``` ```python c.enter_to_head(q) q.add_at_head(c) c enters q at the head ``` ```python c.enter_in_front(q, c1) q.add_in_front_of(c, c1) c enters q in front of c1 ``` ```python c.enter_behind(q, c1) q.add_behind(c, c1)` c enters q behind c1 ``` ```python c.enter_sorted(q, p) q.add_sorted(c, p) c enters q according to priority p ``` -------------------------------- ### Initialize Environment with Datetime Support Source: https://www.salabim.org/manual/Miscellaneous.html Create a Salabim environment with datetime support enabled. This is necessary for using datetime objects for simulation time. ```python env = sim.Environment(datetime0=True) ``` -------------------------------- ### Initialize Salabim Environment Source: https://www.salabim.org/manual/Reference.html Instantiate the Salabim Environment with various configuration options. Parameters control tracing, random seed, time units, datetime display, environment naming, and default behavior. ```python env = sim.Environment(trace=True, animation=True, speed=5) ``` -------------------------------- ### Install Pillow on Linux Source: https://www.salabim.org/manual/Overview.html Specific commands for installing Pillow on Linux systems, ensuring both the core library and Tkinter support are included. ```bash sudo apt-get purge python3-pil sudo apt-get install python3-pil python3-pil.imagetk ``` -------------------------------- ### Implement Producer-Consumer with Salabim Store Source: https://www.salabim.org/manual/Store.html A basic simulation setup where a producer adds items to an unlimited store and a consumer retrieves them. ```python import salabim as sim class Consumer(sim.Component): def process(self): while True: product = self.from_store(products) self.hold(sim.Uniform(0, 2)) class Producer(sim.Component): def process(self): while True: self.hold(1) product = sim.Component("product.") self.to_store(products, product) env = sim.Environment(trace=False) products = sim.Store("products") consumer = Consumer() producer = Producer() env.run(100) producer.status.print_histogram(values=True) consumer.status.print_histogram(values=True) products.length.print_histogram() ``` -------------------------------- ### Get Current State Value Source: https://www.salabim.org/manual/State.html Retrieve the current value of a state by calling the state object directly or using its `get()` method. ```python print('door is ',('open' if dooropen() else 'closed')) ``` ```python print('door is ',('open' if dooropen.get() else 'closed')) ``` -------------------------------- ### Install OpenGL for 3D Animation on Windows Source: https://www.salabim.org/manual/Overview.html A Python script to automatically install necessary OpenGL components for 3D animation on Windows systems. ```python python -c "import requests;exec(requests.get('https://raw.githubusercontent.com/salabim/salabim/master/tools/opengl_installer.py').text)" ``` -------------------------------- ### Example Input File Structure Source: https://www.salabim.org/manual/_sources/Reading%20items%20from%20a%20file.rst.txt A sample input file demonstrating comments, quoted strings, and item separation. The '//' sequence marks the end of a list. ```text # Typical experiment file for a salabim model 1000 # run length 'Experiment 2.0' # run name #Model speed color #-------------- ----- ------ 'Peugeot 208' 150 red 'Peugeot 3008' 175 orange 'Citroen C5' 160 blue 'Renault "Twingo"' 165 green // France {country} Europe {continent} #end of file ``` -------------------------------- ### Basic Store Interaction Example Source: https://www.salabim.org/manual/Store.html Demonstrates a simple scenario of a process requesting an item from a store. The process will wait if no item is immediately available. ```python import salabim as sim # Create a simulation environment env = sim.Environment() # Create a store with unlimited capacity store = sim.Store(env, capacity=float('inf')) # Define a process that requests an item from the store def requester(env, store): print(f'{env.now:.2f}: Requesting item from store') item = yield store.get() print(f'{env.now:.2f}: Received item: {item}') # Schedule the process env.process(requester(env, store)) # Start the simulation env.run(10) ``` -------------------------------- ### Initialize a Queue Source: https://www.salabim.org/manual/Queue.html Create a new queue instance within the simulation environment. ```python waitingline=sim.Queue('waitingline') ``` -------------------------------- ### POST /Resource Source: https://www.salabim.org/manual/Reference.html Initializes a new Resource instance within the simulation environment. ```APIDOC ## POST /Resource ### Description Creates a new resource instance with specified capacity and monitoring settings. ### Method POST ### Endpoint /Resource ### Parameters #### Request Body - **name** (str) - Optional - Name of the resource. - **capacity** (float) - Optional - Capacity of the resource (default 1). - **initial_claimed_quantity** (float) - Optional - Initial claimed quantity (default 0). - **anonymous** (bool) - Optional - If True, claims are not related to any component. - **preemptive** (bool) - Optional - If True, components with lower priority are bumped. - **honor_only_first** (bool) - Optional - If True, only the first requester is honored. - **honor_only_highest_priority** (bool) - Optional - If True, only highest priority requester is honored. - **monitor** (bool) - Optional - If True, enables monitoring. - **env** (Environment) - Optional - The simulation environment. ``` -------------------------------- ### Entering a Queue in Salabim Source: https://www.salabim.org/manual/Modelling.html This code demonstrates how a component (customer) enters a queue. The customer is added to the tail of the specified 'waitingline' queue. ```python self.enter(waitingline) ``` -------------------------------- ### Get or Set Component Priority in Queue Source: https://www.salabim.org/manual/Reference.html Gets or sets the priority of a component within a queue. Changing the priority may alter the queue's order. ```python priority(_q : Queue_, _priority : float = None_) → float ``` -------------------------------- ### Instantiate Components and Run Animation Source: https://www.salabim.org/manual/Animation.html This code snippet instantiates 15 components (presumably of class X) and then enables animation for the environment, sets a model name, and runs the simulation. It's the final step to visualize the simulation. ```python [X(i=i) for i in range(15)] env.animate(True) env.modelname('Demo queue animation') env.run() ``` -------------------------------- ### Example Queue Statistics Output Source: https://www.salabim.org/manual/_sources/Queue.rst.txt An example of the output format when printing statistics for a queue, showing duration, mean, and standard deviation for length and length of stay. ```text -------------------------------------------- -------------- ------------ ------------ ------------ Length of waitingline duration 50000 48499.381 1500.619 mean 8.427 8.687 std.deviation 4.852 4.691 ``` -------------------------------- ### sample() Source: https://www.salabim.org/manual/Reference.html Returns a sample from the distribution. ```APIDOC ## sample() ### Description Returns a single sample from the distribution. ### Method N/A (Method of an object) ### Endpoint N/A ### Parameters None ### Request Example None ### Response #### Success Response (200) - **sample** (float) - A sampled value from the distribution. #### Response Example ```json { "sample": 0.75 } ``` ``` -------------------------------- ### Print Camera Settings Source: https://www.salabim.org/manual/3dAnimation.html Example output format when pressing 'p' to print current camera settings. ```python view(x_eye=16.3435,y_eye=7.5267,z_eye=7.5267,x_center=-10.0000,y_center=0.0000,z_center=0.0000,field_of_view_y=40.5000) # t=22.8377 ``` -------------------------------- ### Define Trajectory Start Time with t0 Source: https://www.salabim.org/manual/_sources/Trajectory.rst.txt Specify a custom start time for a trajectory using the 't0' parameter. For merged trajectories, only the 't0' of the first sub-trajectory is considered. ```python traj0 = sim.TrajectoryPolygon(polygon=(0, 0, 0, 600), vmax=50, t0=10) traj1 = sim.TrajectoryCircle(radius=100, x_center=100, y_center=600, angle0=180, angle1=90, t0=5) traj2 = sim.TrajectoryPolygon(polygon=(100, 700, 700, 700), vmax=50, t0=20) traj = sim.TrajectoryMerged((traj0, traj1, traj2)) ``` -------------------------------- ### Get Level Monitor Value at Specific Time Source: https://www.salabim.org/manual/Monitor.html Retrieve the value of a level monitor at a specific simulation time using `get(time)` or a direct call with a time parameter. ```python print (mylevel.get(4)) # will print the value at time 4 ``` ```python print (mylevel(4)) # will print the value at time 4 ``` -------------------------------- ### Get Current Level Monitor Value Source: https://www.salabim.org/manual/Monitor.html Retrieve the last tallied value (current value) of a level monitor using `get()` or direct call. Ensure the monitor is updated before calling. ```python mylevel = sim.Monitor('level', level=True, initial_tally=0) ... mylevel.tally(10) self.hold(1) print(mylevel()) # will print 10 ``` -------------------------------- ### Implement a Producer-Consumer pattern with a Store Source: https://www.salabim.org/manual/_sources/Store.rst.txt Demonstrates basic store interaction where a producer adds components and a consumer retrieves them. ```python # demo store import salabim as sim class Consumer(sim.Component): def process(self): while True: product = self.from_store(products) self.hold(sim.Uniform(0, 2)) class Producer(sim.Component): def process(self): while True: self.hold(1) product = sim.Component("product.") self.to_store(products, product) env = sim.Environment(trace=False) products = sim.Store("products") consumer = Consumer() producer = Producer() env.run(100) producer.status.print_histogram(values=True) consumer.status.print_histogram(values=True) products.length.print_histogram() ```