SimEvents® Getting Started Guide R2015a
How to Contact MathWorks Latest news: www.mathworks.com Sales and services: www.mathworks.com/sales_and_services User community: www.mathworks.com/matlabcentral Technical support: www.mathworks.com/support/contact_us Phone: 508-647-7000 The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 SimEvents® Getting Started Guide © COPYRIGHT 2005–2015 by The MathWorks, Inc. The software described in this document is furnished under a license agreement.
Revision History November 2005 March 2006 September 2006 March 2007 September 2007 March 2008 October 2008 March 2009 September 2009 March 2010 September 2010 April 2011 September 2011 March 2012 September 2012 March 2013 September 2013 March 2014 October 2014 March 2015 Online only First printing Online only Online only Online only Second printing Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Online only Onl
Contents 1 2 Introduction SimEvents Product Description . . . . . . . . . . . . . . . . . . . . . . . Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 1-2 Discrete-Event Simulation in Simulink Models . . . . . . . . . . . 1-3 Related Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Information About Related Products . . . . . . . . . . . . . . . . . . . Limitations on Usage with Related Products . . . . . . . . . . . . .
Move Blocks into the Model Window . . . . . . . . . . . . . . . . . . . Configure Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Connect Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Run the Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Insert Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Build a Model Using Model Construction Commands . . . . .
Use an Arbitrary Discrete Distribution as Intergeneration Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Use a Step Function as Intergeneration Time . . . . . . . . . . . 4 5 3-9 3-10 Basic Queues and Servers Queues in SimEvents Models . . . . . . . . . . . . . . . . . . . . . . . . . . Behavior and Features of Queues . . . . . . . . . . . . . . . . . . . . . Physical Queues and Logical Queues . . . . . . . . . . . . . . . . . . Access Queue Blocks . . . . . . . .
6 viii Contents Select Arrival Path Using Input Switch . . . . . . . . . . . . . . . . . Role of the Input Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . Round-Robin Approach to Choosing Inputs . . . . . . . . . . . . . . 5-9 5-9 5-9 Combine Entity Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Role of the Path Combiner . . . . . . . . . . . . . . . . . . . . . . . . . Sequence Simultaneous Pending Arrivals . . . . . . . . . . . . . .
1 Introduction • “SimEvents Product Description” on page 1-2 • “Discrete-Event Simulation in Simulink Models” on page 1-3 • “Related Products” on page 1-5 • “What Is an Entity?” on page 1-6 • “What Is an Event?” on page 1-7 • “Run a Sample Model” on page 1-9
1 Introduction SimEvents Product Description Model and simulate discrete-event systems SimEvents provides a discrete-event simulation engine and component library for Simulink®. You can model event-driven communication between components to analyze and optimize end-to-end latencies, throughput, packet loss, and other performance characteristics.
Discrete-Event Simulation in Simulink Models Discrete-Event Simulation in Simulink Models SimEvents software incorporates discrete-event system modeling into the Simulink timebased framework, which is suited for modeling continuous-time and periodic discretetime systems. In time-based systems, state updates occur synchronously with time. By contrast, in discrete-event systems, state transitions depend on asynchronous discrete incidents called events.
1 Introduction of time- and event-based modeling facilitates the simulation of large-scale systems that incorporate smaller subsystems from multiple environments. An example of a large-scale system might have physical modeling for continuous-time systems, such as electrical systems, which communicate via a channel modeled as a discrete-event system. A Simulink model can also contain a purely discrete-event system with no time-based components when modeling event-based processes.
Related Products Related Products In this section... “Information About Related Products” on page 1-5 “Limitations on Usage with Related Products” on page 1-5 Information About Related Products For information about related products, see http://www.mathworks.com/products/ simevents/related.html. Limitations on Usage with Related Products Code Generation SimEvents blocks do not support code generation using the Simulink Coder™ product in version 4.0 (R2011b). In previous versions up until version 3.1.
1 Introduction What Is an Entity? Discrete-event simulations typically involve discrete items of interest. By definition, these items are called entities in SimEvents software. Entities can pass through a network of queues, servers, gates, and switches during a simulation. Entities can carry data, known in SimEvents software as attributes. Note: Entities are not the same as events. Events are instantaneous discrete incidents that change a state variable, an output, and/or the occurrence of other events.
What Is an Event? What Is an Event? In this section... “Overview of Events” on page 1-7 “Relationships Among Events” on page 1-7 “Viewing Events” on page 1-8 Overview of Events In a discrete-event simulation, an event is an instantaneous discrete incident that changes a state variable, an output, and/or the occurrence of other events. Examples of events that can occur during simulation of a SimEvents model are: • The advancement of an entity from one block to another.
1 Introduction not causally related to each other, the processing sequence can significantly affect the simulation behavior. For an example, see “Choose Values for Event Priorities”. For more details, see “Processing Sequence for Simultaneous Events” online. Viewing Events Events do not have a graphical representation. You can infer their occurrence by observing their consequences, by using the Instantaneous Event Counting Scope block, or by using the debugger.
Run a Sample Model Run a Sample Model In this section... “Overview of the Model” on page 1-9 “Accessing the Model” on page 1-9 “Examining Entities and Signals in the Model” on page 1-10 “Key Components of the Model” on page 1-12 “Running the Simulation” on page 1-13 Overview of the Model One way to become familiar with the basics of SimEvents models and the way they work is to examine and run a previously built model. This section describes a SimEvents example model.
1 Introduction Click Open This Example to open the model. Examining Entities and Signals in the Model This section describes the different kinds of ports and lines that appear in the sedemo_DVS_model model. Compared to signal ports, entity ports look different and represent a different concept. Entity Ports and Connections Some blocks in this model can process entities, which the “What Is an Entity?” on page 1-6 section discusses.
Run a Sample Model Entity connection line Entity output port Entity input port Entity connection lines represent relationships among two blocks (or among their entity ports) by indicating a path by which an entity can: • Depart from one block • Arrive simultaneously at a subsequent block The preceding figure shows the connection line: • From OUT, the entity output port of the FIFO Queue block • To IN, the entity input port of the Start Timer block When you run the simulation, entities that depart from th
1 Introduction Signal connection line Signal input port Signal output port In a discrete-event system, the signal input port coming into a block changes to an empty arrow when you perform update diagram: Key Components of the Model The sedemo_DVS_model model uses event-based blocks to simulate the workload of the microcontroller: • At random times, the Time-Based Entity Generator block generates an entity that represents a job for the microcontroller.
Run a Sample Model This block can process at most one job at a time and thus limits the availability of the microcontroller to process new jobs. While a job is in this block, other jobs remain in the FIFO Queue block. • The Start Timer and Read Timer blocks work together to compute the time that each job spends in the server. The result of the computation is the et output signal from the Read Timer block. • The Entity Sink block absorbs jobs that have completed their processing.
1 Introduction 1-14
2 Building Simple Models with SimEvents Software • “Build a Discrete-Event Model” on page 2-2 • “Explore Simulations Using the Debugger and Plots” on page 2-17 • “Build a Hybrid Model” on page 2-29 • “Key Concepts in SimEvents Software” on page 2-43
2 Building Simple Models with SimEvents Software Build a Discrete-Event Model In this section... “Overview” on page 2-2 “Open a Model and Libraries” on page 2-3 “Move Blocks into the Model Window” on page 2-5 “Configure Blocks” on page 2-10 “Connect Blocks” on page 2-13 “Run the Simulation” on page 2-13 “Insert Blocks” on page 2-15 “Build a Model Using Model Construction Commands” on page 2-15 Overview This section describes how to build a new model representing a discrete-event system.
Build a Discrete-Event Model Note: When you later create your own models, use the conversion blocks from the Gateways library (gateway blocks) to convert signals and function-calls from signal-based to event-based and vice versa. Open a Model and Libraries The first steps in building a model are to set up your environment, open a new model window, and open the libraries containing blocks. Open a New Model Window On the Home tab, select New > Simulink Model . An empty model window opens.
2 Building Simple Models with SimEvents Software Open Simulink Libraries In the MATLAB Command Window, enter simulink The Simulink Library Browser opens, using a tree structure to display the available libraries and blocks. To view the blocks in a library listed in the left pane, select the library name, and the list of blocks appears in the right pane. The Library Browser provides access not only to Simulink blocks but also to SimEvents blocks.
Build a Discrete-Event Model Move Blocks into the Model Window To move blocks from libraries into the model window, follow these steps: 1 In the main SimEvents library window, double-click the Generators icon to open the Generators library. Then double-click the Entity Generators icon to open the Entity Generators sublibrary. 2 Drag the Time-Based Entity Generator block from the library into the model window.
2 Building Simple Models with SimEvents Software 3 2-6 In the main SimEvents library window, double-click the Queues icon to open the Queues library.
Build a Discrete-Event Model 4 Drag the FIFO Queue block from the library into the model window. 5 In the main SimEvents library window, double-click the Servers icon to open the Servers library.
2 2-8 Building Simple Models with SimEvents Software 6 Drag the Single Server block from the library into the model window. 7 In the main SimEvents library window, double-click the SimEvents Sinks icon to open the SimEvents Sinks library.
Build a Discrete-Event Model 8 Drag the Signal Scope block and the Entity Sink block from the library into the model window. As a result, the model window looks like the following figure. The model window contains blocks that represent the key processes in the simulation: blocks that generate entities, store entities in a queue, serve entities, and create a plot showing relevant data.
2 Building Simple Models with SimEvents Software Configure Blocks Configuring the blocks in dd1 means setting their parameters appropriately to represent the system being modeled. Each block has a dialog box that enables you to specify parameters for the block. Default parameter values might or might not be appropriate, depending on what you are modeling. View Parameter Values Two important parameters in this D/D/1 queuing system are the arrival rate and service rate.
Build a Discrete-Event Model 3 Click Cancel in both dialog boxes to dismiss them without changing any parameters. The Period and Service time parameters have the same value, which means that the server completes an entity's service at exactly the same time that a new entity is being created. Change Parameter Values Configure blocks to create a plot that shows when each entity departs from the server, and to make the queue have an infinite capacity.
2 Building Simple Models with SimEvents Software Then click OK. The Single Server block acquires a signal output port labeled #d. During the simulation, the block will produce an output signal at this #d port; the signal's value is the running count of entities that have completed their service and departed from the server. 2-12 4 Double-click the FIFO Queue block to open its dialog box. 5 Set the Capacity parameter to Inf and click OK.
Build a Discrete-Event Model Connect Blocks Now that the model window for dd1 contains blocks that represent the key processes, connect the blocks as shown in the following graphic. To connect blocks, do one of the following: • With the mouse, drag from the output port of the source block to the input port of the destination block. • Select the source block. Ctrl+click the destination block. In both cases, SimEvents connects the source block to the destination block.
2 Building Simple Models with SimEvents Software inappropriate for this particular example model, which is completely event-based and contains no blocks with continuous states. The application overrides the inappropriate parameters and alerts you to that fact. If you want to prevent these warnings when you simulate event-based models in the future, you need to set the solver type and step size parameters to appropriate values.
Build a Discrete-Event Model • Starting at T=1, the plot is a stairstep plot. The stairs have height 1 because the server processes one entity at a time, so entities depart one at a time. The stairs have width equal to the constant service time, which is one second. Insert Blocks You can insert a block in an existing line, if the block that you want to insert: • Has only one input and one output port. • Has connection port types (i.e.
2 Building Simple Models with SimEvents Software set_param('MyModel/Time-Based Entity Generator','position',[65 63 150 117]); The position parameter specifies the top left (x,y) and lower right (x+block width, y +block height) corners of the block. Add the FIFO Queue block and position it. add_block('simeventslib/Queues/FIFO Queue','MyModel/FIFO Queue'); set_param('MyModel/FIFO Queue','position',[195 63 280 117]); Connect the blocks.
Explore Simulations Using the Debugger and Plots Explore Simulations Using the Debugger and Plots In this section...
2 Building Simple Models with SimEvents Software Functions | Help | Watch Video Tutorial %==============================================================================% Initializing Model dd1 sedebug>> The sedebug>> notation is the debugger prompt, where you enter commands. Run the Simulation The simulation has initialized but does not proceed. In debugging mode, you indicate to the debugger when to proceed through the simulation and how far to proceed before returning control to you.
Explore Simulations Using the Debugger and Plots One entity is in service Table of entities in the block End the Simulation The simulation is still suspended just before the end. To proceed, enter this command: cont The simulation ends, the debugging session ends, and the MATLAB command prompt returns. For Further Information For additional information about the SimEvents debugger, see “Debug Simulation”.
2 Building Simple Models with SimEvents Software Enable the Queue-Length Signal The FIFO Queue block can report the queue length, that is, the number of entities it stores at a given time during the simulation. To configure the FIFO Queue block to report its queue length, do the following: 1 Double-click the FIFO Queue block to open its dialog box. Click the Statistics tab to view parameters related to the statistical reporting of the block.
Explore Simulations Using the Debugger and Plots Simulate with Different Intergeneration Times By changing the intergeneration time (that is, the reciprocal of the entity arrival rate) in the Time-Based Entity Generator block, you can see when entities accumulate in the queue. Try this procedure: Note: If you skipped the earlier model-building steps, you can open a completed version of the model for this section by entering simeventsdocex('doc_dd1_blockage') in the MATLAB Command Window.
2 Building Simple Models with SimEvents Software First entity Entity arrives arrives at queue and stays in queue First entity departs from queue Entity departs from queue, which becomes empty One entity departs from queue. One entity remains in queue. 3 Reopen the Time-Based Entity Generator block's dialog box and set Period to 0.3. 4 Run the simulation again. Now the entities arrive much faster than the server can process them. You can make these observations from the plot: • Every 0.
Explore Simulations Using the Debugger and Plots 5 Reopen the Time-Based Entity Generator block's dialog box and set Period to 1.1. 6 Run the simulation again. Now the entities arrive more slowly than the server's service rate, so every entity that arrives at the queue is able to depart in the same time instant. The queue length is never greater than zero for a positive amount of time.
2 Building Simple Models with SimEvents Software 1 Double-click the FIFO Queue block to open its dialog box. Click the Statistics tab, set the Average wait parameter to On, and click OK. This causes the block to have a signal output port for the signal representing the average duration that entities wait in the queue. The port label is w. 2 Double-click the Single Server block to open its dialog box. Click the Statistics tab, set both the Average wait and Utilization parameters to On, and click OK.
Explore Simulations Using the Debugger and Plots 8 Run the simulation with different values of the Period parameter in the Time-Based Entity Generator block, as described in “Simulate with Different Intergeneration Times” on page 2-21. Look at the plots to see how they change if you set the intergeneration time to 0.3 or 1.1, for example.
2 Building Simple Models with SimEvents Software • The utilization of the server is nondecreasing if the intergeneration time is small (such as 0.3) because the server is constantly busy once it receives the first entity. The utilization might decrease if the intergeneration time is larger than the service time (such as 1.5) because the server has idle periods between entities.
Explore Simulations Using the Debugger and Plots • The average waiting time in the queue increases throughout the simulation if the intergeneration time is small (such as 0.3) because the queue gets longer and longer. The average waiting time in the queue is zero if the intergeneration time is larger than the service time (such as 1.1) because every entity that arrives at the queue is able to depart immediately.
2 Building Simple Models with SimEvents Software Information About Race Conditions and Random Times Other examples modify this one by varying the processing sequence for simultaneous events or by making the intergeneration times and/or service times random.
Build a Hybrid Model Build a Hybrid Model In this section... “Overview” on page 2-29 “Lesson 1: Run the Time-Based Model” on page 2-30 “Lesson 2: Explore the Time-Based Model” on page 2-32 “Lesson 3: Add Event-Based Behavior” on page 2-35 “Lesson 4: Run the Hybrid Model” on page 2-40 “Event-Based and Time-Based Dynamics in the Simulation” on page 2-42 Overview This tutorial shows you how to add SimEvents blocks to an existing Simulink model to create a hybrid model.
2 Building Simple Models with SimEvents Software • Use discrete events to update signals that influence time-based dynamics. • Adjust parameters in the discrete-event system to affect the results of the overall hybrid model. Note: A more realistic way to represent a distributed control system is to model communication over a shared network, where time delays and transmission failures might depend on network traffic from other distributed components.
Build a Hybrid Model • ABS Controller subsystem that accepts a setpoint from the Desired Relative Slip block and provides a control signal to the braking system. • Brake System Dynamics subsystem that models the behavior of an actual braking system. • Sensor Relative Slip subsystem that feeds a measured slip value back to the ABS Controller block. Simulate the braking system. In the Simulink Editor, select Simulation > Run.
2 Building Simple Models with SimEvents Software Lesson 2: Explore the Time-Based Model Before you modify the model to add discrete-event behavior, you should understand how the time-based portion of the model works. This lesson examines each block in the timebased model. Note: For a more detailed analysis of a similar ABS model, see Modeling an Anti-Lock Braking System.
Build a Hybrid Model Desired Relative Slip Block The desired slip value is based on some physical modeling known as the mu-slip curve. The mu-slip curve is the friction coefficient between the tire and the road surface, mu, expressed as an empirical function of slip. The desired slip is set to the value of slip at which the mu-slip curve reaches a peak value, this being the optimum value for minimum braking distance. For more information about the mu-slip curve, see Modeling an Anti-Lock Braking System.
2 Building Simple Models with SimEvents Software Brake System Dynamics Subsystem The Brake System Dynamics subsystem is complex. What follows is a high-level examination of how it works. For a more detailed analysis of a similar system, see Modeling an Anti-Lock Braking System. The Brake System Dynamics subsystem: • Accepts a control signal from the ABS Controller subsystem, based on the error between measured slip and desired slip.
Build a Hybrid Model Sensor Relative Slip Subsystem The Sensor Relative Slip subsystem contains a Gain block where you can specify the accuracy of the sensor in converting the actual relative slip to a measured value that feeds back to the controller. A gain value of 1 simulates the ideal case of a sensor that measures the slip with 100% accuracy.
2 Building Simple Models with SimEvents Software To learn about the Network Delay subsystem behavior and for instructions on building and integrating the subsystem, see: • “How the Network Delay Subsystem Works” on page 2-36 • “Add the Network Delay Subsystem Block” on page 2-37 • “Add the Network Delay Subsystem Contents” on page 2-38 • “Complete the Hybrid Model” on page 2-39 How the Network Delay Subsystem Works The Network Delay subsystem models a communication link that samples information from the A
Build a Hybrid Model • Periodically, the Time-Based Entity Generator block creates an entity that conveys the control signal value from the ABS controller to the braking system. • The Set Attribute block attaches the control signal value to the entity. This datacarrying entity is a data packet in the network. • The N-Server block models the latency in the communication system by delaying each data packet. • The Get Attribute block models the reconstruction of data at the receiver.
2 Building Simple Models with SimEvents Software Add the Network Delay Subsystem Contents In this procedure, you add event-based blocks that model a communications delay to the Network Delay subsystem block. When you complete the procedure, the contents of the Network Delay block should look as shown in the graphic. 2-38 1 In the SimEvents library, double-click the Generators library. Double-click the Entity Generators sublibrary and drag a Time-Based Entity Generator block into the subsystem window.
Build a Hybrid Model 7 Double-click the Get Attribute block. The Get Attribute tab of the dialog box contains a table. On the first row of the table, set Name to Value. Click OK. The block acquires an extra signal output port, Value. 8 From the Servers library, drag the N-Server block into the subsystem window. 9 Double-click the N-Server block. Set Service time from to Signal port t. Click OK. The block acquires an extra signal input port, t.
2 Building Simple Models with SimEvents Software 7 Connect the previously created Network Delay block between the ABS Controller and Brake System Dynamics blocks. The hybrid model is now complete. 8 Save the model. Lesson 4: Run the Hybrid Model Run the completed abs_hybrid model. In the Simulink Editor, select Simulation > Run.
Build a Hybrid Model • Between 6s and 8s, the measured slip increases and the wheel speed begins to lock up (decrease rapidly towards zero). • At about 14s, the measured slip increases again. The wheel speed locks up, falling to zero. • The vehicle takes almost 17s to come to rest. This value is almost 2s longer than in the original time-based model. Change the Network Performance One way to experiment with the simulation is to change the performance of the network and run the simulation again.
2 Building Simple Models with SimEvents Software Event-Based and Time-Based Dynamics in the Simulation In the abs_hybrid model, the time-based dynamics of the braking system coexist with the event-based dynamics of the network delay subsystem. When you run the simulation, the solver and the event calendar both play a role. Upon major time steps of the solver, the simulation solves the ordinary differential equations that represent the dynamics of the braking system.
Key Concepts in SimEvents Software Key Concepts in SimEvents Software In this section... “Meaning of Entities in Different Applications” on page 2-43 “Entity Ports and Paths” on page 2-43 “Data and Signals” on page 2-44 Meaning of Entities in Different Applications An entity represents an item of interest in a discrete-event simulation. The meaning of an entity depends on what you are modeling.
2 Building Simple Models with SimEvents Software entities try and fail to advance along that same entity path. For example, an entity departs from a queue and, simultaneously, the next entity in the queue tries and fails to depart. Data and Signals In time-based dynamics, signals express the outputs of dynamic systems represented by blocks. Event-based blocks can also read and produce signals.
3 Create Entities Using Intergeneration Times • “Role of Entities in SimEvents Models” on page 3-2 • “Specify Intergeneration Times for Entities” on page 3-4
3 Create Entities Using Intergeneration Times Role of Entities in SimEvents Models In this section... “Create Entities in a Model” on page 3-2 “Vary the Interpretation of Entities” on page 3-2 “Data and Entities” on page 3-2 “Introduction to the Time-Based Entity Generator” on page 3-2 Create Entities in a Model As described in “What Is an Entity?” on page 1-6, entities are discrete items of interest in a discrete-event simulation. You determine what an entity signifies, based on what you are modeling.
Role of Entities in SimEvents Models • How the block determines the time intervals between successive entities. To learn more, see “Specify Intergeneration Times for Entities” on page 3-4. • How the block reacts when it is temporarily unable to output entities. To learn more, see the online reference page for the block. • The relative priority of entity generation events compared to other kinds of events that might occur simultaneously.
3 Create Entities Using Intergeneration Times Specify Intergeneration Times for Entities In this section...
Specify Intergeneration Times for Entities Comparison of Approaches Using intergeneration times from a distribution might be appropriate if you have a mathematical model of the arrival process for the customers, packets, or other items that entities represent in your model. Using intergeneration times from a signal might be appropriate if you: • Want to use a statistical distribution that is not constant, uniform, or exponential.
3 Create Entities Using Intergeneration Times 1 Ï Ô f ( x) = Ì Maximum - Minimum ÔÓ 0 Minimum < x < Maximum Otherwise The exponential distribution with mean 1/λ has probability density function Ïl exp ( -l x) fl ( x) = Ì 0 Ó x≥0 x<0 The probability density function does not predict the actual intergeneration time between a particular entity and the next entity.
Specify Intergeneration Times for Entities Role of initial seed for uniform and exponential distributions If you set Distribution to Uniform or Exponential, the dialog box includes an Initial seed parameter. This parameter specifies the seed on which the stream of random numbers is based. For a fixed seed, the random behavior is repeatable the next time you run the simulation. Changing the seed changes the stream of random numbers.
3 Create Entities Using Intergeneration Times For more information For examples of how to create such signals, see: • “Use a Step Function as Intergeneration Time” on page 3-10 • “Use an Arbitrary Discrete Distribution as Intergeneration Time” on page 3-9 For more details about creating event-based signals, see: • “Generate Random Signals” • “Create Event-Based Signals Using Data Sets” • “Time-Based and Event-Based Signal Conversion” 3 Connect the signal to the Time-Based Entity Generator block at its si
Specify Intergeneration Times for Entities Parameter Values Simulation Results • Distribution = Uniform The first entity, generated at T=0, appears in the plot at T=1 after its service is complete. The second entity, generated at a random time between T=1 and T=3, appears in the plot between T=2 and T=4. • Minimum = 1 • Maximum = 3 • Distribution = Uniform • Minimum = 1 • Maximum = 1.5 • Distribution = Exponential • Mean = 0.
3 Create Entities Using Intergeneration Times P( Dt = 1) = 0.25 P( Dt = 1.5) = 0 .5 P( Dt = 2) = 0.25 When you run the simulation, the plot shows that the entities departing from the server are spaced 1, 1.5, or 2 seconds apart. In this example, however, the simulation time is much too short to verify that the random number generator is applying the specified probabilities. Use a Step Function as Intergeneration Time This example uses the Step block to generate entities at intervals of 1 or 2 seconds.
Specify Intergeneration Times for Entities • Step time = 2.8 • Initial value = 1 • Final value = 2 As a result, the block generates a signal whose value is 1 from T=0 to T=2.8, and whose value is 2 thereafter. When you run the simulation, the plot shows that the entities departing from the server are initially spaced 1 second apart and later spaced 2 seconds apart. The Time-Based Entity Generator block reads intergeneration times from the step signal each time it generates an entity.
3 Create Entities Using Intergeneration Times 3-12 Entity Generation Time Intergeneration Time Until Next Entity Generation Departure Time of Entity from Server 3 2 4 5 2 6 7 2 8 9 2 10
4 Basic Queues and Servers • “Queues in SimEvents Models” on page 4-2 • “Servers in SimEvents Models” on page 4-4 • “Model Basic Queueing Systems” on page 4-6
4 Basic Queues and Servers Queues in SimEvents Models In this section... “Behavior and Features of Queues” on page 4-2 “Physical Queues and Logical Queues” on page 4-2 “Access Queue Blocks” on page 4-3 Behavior and Features of Queues In a discrete-event simulation, a queue stores entities for some length of time that cannot be determined in advance. The queue attempts to output entities as soon as it can, but its success depends on whether the next block accepts new entities.
Queues in SimEvents Models called a logical queue. For example, you might use a queue to provide a temporary storage area for entities that might otherwise have nowhere to go. Such use of a logical queue can prevent deadlocks or simplify the simulation. For example, see “Example of a Logical Queue” on page 4-9. Access Queue Blocks Queue blocks reside in the Queues library of the SimEvents library set. This chapter focuses on the FIFO Queue block.
4 Basic Queues and Servers Servers in SimEvents Models In this section... “Behavior and Features of Servers” on page 4-4 “What Servers Represent” on page 4-4 “Access Server Blocks” on page 4-5 Behavior and Features of Servers In a discrete-event simulation, a server stores entities for some length of time, called the service time, and then attempts to output the entity. During the service period, the block is said to be serving the entity that it stores.
Servers in SimEvents Models • A person (such as a bank teller) who performs a transaction with each arriving customer • A transmitter that processes and sends messages • A machine that assembles parts in a factory • A computer that executes programs You might use an infinite-capacity server to represent a delaying mechanism. An example of this is in the subsystem in “Build a Hybrid Model” on page 2-29.
4 Basic Queues and Servers Model Basic Queueing Systems In this section... “Constructs Involving Queues and Servers” on page 4-6 “Example of a Logical Queue” on page 4-9 “Vary the Service Time of a Server” on page 4-10 See also the example in “Build a Discrete-Event Model” on page 2-2, which illustrates how to create a queue-server pair and view statistics such as server utilization.
Model Basic Queueing Systems on an entity before the second server is available, the entity must stay in the first server past the end of service and the first server cannot accept a new entity for service until the second server becomes available. Parallel Queue-Server Pairs as Alternatives Two queue-server pairs connected in parallel, in which each entity arrives at one or the other, represent alternative operations. For example, vehicles wait in line for one of several tollbooths at a toll plaza.
4 Basic Queues and Servers Serial Connection of Queues Two queues connected in series might be useful if you are using entities to model items that physically experience two distinct sets of conditions while in storage. For example, additional inventory items that overflow one storage area have to stay in another storage area in which a less well-regulated temperature affects the items' long-term quality.
Model Basic Queueing Systems a jammed exit ramp of the freeway. You might model the tollbooth as a server and the traffic jam as a gate. Example of a Logical Queue Suppose you are modeling a queue that can physically hold 100 entities and you want to determine what proportion of the time the queue length exceeds 10. You can model the long queue as a pair of shorter queues connected in series. The shorter queues have length 90 and 10.
4 Basic Queues and Servers Determining the proportion of time the physical queue length exceeds 10 is equivalent to determining the proportion of time the queue length signal of the logical length-90 queue exceeds 0. Vary the Service Time of a Server The subsystem described in “Lesson 3: Add Event-Based Behavior” on page 2-35 includes an Infinite Server block that serves each entity for a random amount of time.
Model Basic Queueing Systems • You want the service time to arise from dynamics of the simulation. In this case, set the Single Server block's Service time from parameter to Signal port t and create a signal whose value at the time an entity arrives at the server is equal to the desired service time for that entity. If the signal representing the service time is an event-based signal such as the output of a Get Attribute block, ensure that the signal's updates occur before the entity arrives at the server.
5 Designing Paths for Entities • “Role of Paths in SimEvents Models” on page 5-2 • “Select Departure Path Using Output Switch” on page 5-5 • “Select Arrival Path Using Input Switch” on page 5-9 • “Combine Entity Paths” on page 5-12 • “Model a Packet Switch” on page 5-16
5 Designing Paths for Entities Role of Paths in SimEvents Models In this section... “Definition of Entity Paths” on page 5-2 “Implications of Entity Paths” on page 5-2 “Overview of Routing Library for Designing Paths” on page 5-3 Definition of Entity Paths An entity path is a connection from an entity output port to an entity input port, depicted as a line connecting the entity ports of two SimEvents blocks.
Role of Paths in SimEvents Models model below shows two queues in a parallel arrangement, preceded by a block that has one entity input port and two entity output ports. By looking at the entity connection lines alone, you cannot tell which queue block's IN port an entity will arrive at. Instead, you need to know more about how the one-to-two block (Output Switch) behaves and you might even need to know the outcome of certain run-time decisions.
5 Designing Paths for Entities Other libraries in the SimEvents library set contain some blocks whose secondary features, such as preemption from a server or timeout from a queue or server, give you opportunities to design paths.
Select Departure Path Using Output Switch Select Departure Path Using Output Switch In this section... “Role of the Output Switch” on page 5-5 “Sample Use Cases” on page 5-5 “Select the First Available Server” on page 5-6 “Use an Attribute to Select an Output Port” on page 5-8 Role of the Output Switch The block in the Routing library selects one among a number of entity output ports. The selected port can change during the simulation.
5 Designing Paths for Entities The topics listed below illustrate the use of the Output Switch block.
Select Departure Path Using Output Switch This deterministic model creates one entity every second and attempts to advance the entity to one of two servers. The two servers have different service times, both greater than 1 second. The server with the longer service time becomes available less frequently and has a smaller throughput. The FIFO Queue block stores entities while both servers are busy.
5 Designing Paths for Entities Use an Attribute to Select an Output Port Consider the situation in which parcels are sorted among several delivery vehicles based on the locations of the specified recipients. If each parcel is an entity, then you can attach data to each entity to indicate the location of its recipient. To implement the sorting, set the Switching criterion parameter in the Output Switch block to From attribute.
Select Arrival Path Using Input Switch Select Arrival Path Using Input Switch In this section... “Role of the Input Switch” on page 5-9 “Round-Robin Approach to Choosing Inputs” on page 5-9 Role of the Input Switch The block in the Routing library chooses among a number of entity input ports. This block selects exactly one entity input port for potential arrivals and makes all other entity input ports unavailable. The selected entity input port can change during the simulation.
5 Designing Paths for Entities The three Set Attribute blocks assign a Type attribute to each entity, where the attribute value depends on which entity generator created the entity. FIFO Queue blocks store entities that cannot enter the Input Switch block yet because either • The Input Switch is waiting to receive an entity at a different entity input port, according to the round-robin switching criterion. • The Single Server block is busy serving an entity, so its entity input port is unavailable.
Select Arrival Path Using Input Switch 5-11
5 Designing Paths for Entities Combine Entity Paths In this section... “Role of the Path Combiner” on page 5-12 “Sequence Simultaneous Pending Arrivals” on page 5-13 “Path Combiner Versus Input Switch” on page 5-15 Role of the Path Combiner You can merge multiple paths into a single path using the Path Combiner block. Merging entity paths does not change the entities themselves, just as merging lanes on a road does not change the vehicles that travel on it.
Combine Entity Paths • Connecting a feedback path: A feedback path enters the same queue as an ordinary path. Sequence Simultaneous Pending Arrivals The Path Combiner block does not experience any collisions, even if multiple entities attempt to arrive at the same time.
5 Designing Paths for Entities to be notified of the change is the first to advance an entity to the Path Combiner block. The Input port precedence parameter determines which of the block's entity input ports is first in the notification sequence. For the list of options, see the online reference page for the Path Combiner block. Significance of Input Port Precedence Consider the sequence of blocks in the figure below, in which a Path Combiner block merges three small queues into a single large queue.
Combine Entity Paths Path Combiner Versus Input Switch The Input Switch block, described in “Select Arrival Path Using Input Switch” on page 5-9, has multiple entity input ports and one entity output ports. The same is true for the Path Combiner block. These two blocks differ in that • The Path Combiner block's acceptance of an entity arrival does not depend on which port the entity arrives at.
5 Designing Paths for Entities Model a Packet Switch In this section... “Overview” on page 5-16 “Generate Packets” on page 5-17 “Store Packets in Input Buffers” on page 5-18 “Rout Packets to Their Destinations” on page 5-19 “Connect Multiple Queues to the Output Switch” on page 5-20 “Model the Channels” on page 5-21 Overview A packet switch is a component of a communication network that connects several sources of data packets with several destinations.
Model a Packet Switch Generate Packets The packet switch example models each packet as an entity. The Time-Based Entity Generator block creates entities. To implement exponentially distributed intergeneration times between successive entities from each source, the block has its Distribution parameter set to Exponential.
5 Designing Paths for Entities Note: The entity does not actually carry a payload. This example models the transmission of data at a level of abstraction that includes timing and routing behaviors but is not concerned with the specific user data in each packet. Copies of the Event-Based Random Number block produce the random destination and length data. The Set Attribute block attaches all the data to each entity.
Model a Packet Switch The queue uses a FIFO queuing discipline, which does not take into account the destination of each packet. Note that such a model can suffer from “head-of-queue blocking,” which occurs when a packet not at the head of the queue is forced to wait even when its destination is available, just because the packet at the head of the queue is aiming for an unavailable destination. Rout Packets to Their Destinations A core block in the packet switch example is the Output Switch block.
5 Designing Paths for Entities This part of the example is similar to the model shown in “Use an Attribute to Select an Output Port” on page 5-8. Connect Multiple Queues to the Output Switch The packet switch model must enable entities to advance from three queues to the single entity input port of the Output Switch block. Candidate blocks are Input Switch and Path Combiner.
Model a Packet Switch • The priorities of the entity generation events. In this example, all Time-Based Entity Generator blocks share the same Generation event priority parameter value. • The Execution order parameter in the model's Configuration Parameters dialog box. In this example, the parameter is set to Randomized. As a result, when two packets are generated simultaneously, the sequence of generation events in this example is random.
5 Designing Paths for Entities 5-22
6 Selected Bibliography [1] Banks, Jerry, John Carlson, and Barry Nelson. Discrete-Event System Simulation, Second Ed. Upper Saddle River, N.J.: Prentice-Hall, 1996. [2] Cassandras, Christos G. Discrete Event Systems: Modeling and Performance Analysis. Homewood, Illinois: Irwin and Aksen Associates, 1993. [3] Cassandras, Christos G., and Stéphane Lafortune. Introduction to Discrete Event Systems. Boston: Kluwer Academic Publishers, 1999. [4] Fishman, George S.