Skip to Main Content Skip to Search
Product Documentation

Manipulating Events

Reasons to Manipulate Events

You can manipulate events to accomplish any of these goals:

The term event translation refers to the conversion of one event into another. The result of the translation is often a function call, but can be another type of event. The result of the translation can occur at the same time as, or a later time than, the original event.

Blocks for Manipulating Events

The table below lists blocks that are useful for manipulating events.

Event to ManipulateBlock
Entity advancementEntity Departure Function-Call Generator Event
Signal-based eventSignal-Based Function-Call Generator
Function callSignal-Based Function-Call Generator
Mux

If you connect the Entity Departure Counter block's #d output port to a block that detects sample time hits or rising value changes, then you can view the counter as a mechanism for converting an entity advancement event into a signal-based event. Corresponding to each entity departure from the block is an increase in the value of the #d signal.

Creating a Union of Multiple Events

To generate a function-call signal that represents the union (logical OR) of multiple events, use this procedure:

  1. Generate a function call for each event that is not already a function call. Use blocks in the Event Generators or Event Translation library.

  2. Use the Mux block to combine the function-call signals.

The multiplexed signal carries a function call when any of the individual function-call signals carries a function call. If two individual signals carry a function call at the same time instant, then the multiplexed signal carries two function calls at that time instant.

Examples are in and below.

Example: Counting Events from Multiple Sources

The example below (open model) illustrates different approaches to event translation and event generation. This example varies the approach for illustrative purposes; in your own models, you might decide to use a single approach that you find most intuitive.

The goal of the example is to plot the number of arrivals at a bank of three servers at each value of time. Entities advance to the servers via one or two FIFO Queue blocks. To count arrivals and create the plot, the model translates each arrival at a server into a function call; the Mux block combines the three function-call signals to create an input to the Instantaneous Event Counting Scope block.

The three server paths use these methods for translating an entity arrival into a function call:

Example: Executing a Subsystem Based on Multiple Types of Events

You can configure a Function-Call Subsystem block to detect function calls from one or more sources. The following model fragment uses an event translation block to convert a signal-based event into a function call. When you perform this conversion, you create a subsystem that detects a function call from a Stateflow block and a signal-based event from another source. When either the Stateflow block generates a function call, or the signal connected to the vc port of the Signal-Based Function-Call Generator block changes, the model executes this subsystem. If both events occur simultaneously, the model executes the subsystem twice.

A similar example is in .

Translating Events to Control the Processing Sequence

In some situations, event translation blocks can help you prescribe the processing sequence for simultaneous events. The examples below illustrate how to do this by taking advantage of the sequence in which an event translation block issues two function calls, and by converting an unprioritized function call into a function call having an event priority.

Example: Issuing Two Function Calls in Sequence

In the next model, entity generation and the execution of a function-call subsystem can occur simultaneously. At such times, it is important that the entity generation occur first, so that the entity generator updates the value of the w signal before the function-call subsystem uses w in its computation. This model ensures a correct processing sequence by using the same Signal-Based Function-Call Generator block to issue both function calls and by relying on the fact that the block always issues the f1 function call before the f2 function call.

In this example, the Signal-Based Function-Call Generator block has this configuration:

In this example, the Function-Call Split block in the Simulink libraries is not an alternative because it cannot connect to SimEvents blocks.

Example: Generating a Function Call with an Event Priority

The next model uses an event translation block to prioritize the execution of a function-call subsystem correctly on the event calendar, relative to a simultaneous event. In the model, a Stateflow block and an entity generator respond to edges of the same trigger signal. The Stateflow block calls an event translation block, which in turn calls a function-call subsystem. The subsystem performs a computation using the w output signal from the entity generator.

As in the earlier example, it is important that the entity generator update the value of the w signal before the function-call subsystem uses w in its computation. To ensure a correct processing sequence, the Signal-Based Function-Call Generator block replaces the original function call, which is not scheduled on the event calendar, with a new function call that is scheduled on the event calendar with a priority of 200. The Event-Based Entity Generator block schedules an entity-generation event on the event calendar with a priority of 100. As a result of the event translation and the relative event priorities, the entity generator generates the entity before the event translator issues the function call to the function-call subsystem whenever these events occur at the same value (or sufficiently close values) of the simulation clock.

Conditionalizing Events

The Entity Departure Function-Call Generator Event and Signal-Based Function-Call Generator blocks provide a way to suppress the output function call based on a control signal. If the control signal is zero or negative when the block is about to issue the function call, then the block suppresses the function call. You can use this feature to

Example: Modeling Periodic Shutdown of an Entity Generator

The example below (open model) uses Event-Based Entity Generator blocks to generate entities when a pulse signal changes its value. The top entity generator generates an entity upon each such event. The bottom entity generator responds to a function call issued by an event translation block that detects changes in the pulse signal's value. However, the event translation block issues a function call only upon value changes that occur while the e1 input signal is positive. In this model, a nonpositive value of the e1 signal corresponds to a failure or resting period of the entity generator.

  


Free Discrete Event Simulation Technical Kit

Model electronic system architectures, process flows, and logistics as queuing systems or agent-based systems.

Get free kit

Trials Available

Try the latest version of discrete-event simulation products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS