Create Custom Blocks Using MATLAB Discrete-Event System Block

Discrete-Event System objects let you implement custom event-driven entity-flow systems using the MATLAB® language. The MATLAB Discrete-Event System block enables you to use discrete-event System objects to create a custom block in your SimEvents® model. You can author such discrete-event System objects via a set of MATLAB methods.

You can create a custom discrete-event System object™ from scratch that:

  • Contains multiple entity storage elements, with each storage element containing multiple SimEvents entities, and configure it to sort entities in a particular order.

  • Has an entity or a storage element that can schedule and execute multiple types of events. These events can model activities such as entity creation, consumption, search, transmission, and temporal delay.

  • Can accept entity/signal as input/output, produce entity and signal as outputs, and support both built-in data types and structured/bus data types.

  • Use MATLAB toolboxes for computation and scaling of complex systems.

The MATLAB Discrete-Event System block is similar to the MATLAB System block with these differences:

  • The resulting discrete-event System object is an instantiation of the matlab.DiscreteEventSystem class rather than the matlab.System class.

  • The matlab.DiscreteEventSystem has its own set of System object methods particular to discrete-event systems.

  • The matlab.DiscreteEventSystem also inherits a subset of the MATLAB System methods. For a complete list of this subset, see Create a Discrete-Event System Object.

Entity Types, Ports, and Storage in a Discrete-Event System Framework

An entity is a discrete object that the system processes. An entity has a type and the entity type defines a class of entities that share a common set of data specifications and run-time methods. Examples of data specifications include dimensions, data type, and complexity.

Consider these guidelines when defining custom entity types using the getEntityTypesImpl method:

  • You can specify multiple entity types. Each type must have a unique name.

  • An entity storage element, input port, and output port must specify the entity type they work with.

  • Specify or resolve common data specifications for an entity type. For example, an input port and an output port with the same entity type must have the same data type.

  • When forwarding an entity, the source and destination data specifications must be same in these instances:

    • From an input port to a storage element

    • Between storage elements

    • From a storage element to an output port

  • Each entity type can share a common set of event action methods. When naming these methods, to distinguish the entity type use this convention:

    entitytypeAction

    For example, if there are two entity types, car and truck, use method names such as:

    carEntry
    truckEntry

During simulation, an entity always occupies a unit of storage space. Such storage spaces are provided by entity storage elements. A discrete-event System object can contain multiple entity storage elements. Use the getEntityStorageImpl method to specify storage elements. A storage space is a container with these properties:

  • Entity type — Entity type this storage is handling.

  • Capacity — Maximum number of entities that the storage can contain.

  • Storage type — Criteria to sort storage entities (FIFO, LIFO, and priority).

  • Key name — An attribute name used as key name for sorting. This property is applicable only when the storage type is priority.

  • Sorting direction — Ascending or descending priority queues. This property is applicable only when the storage type is priority.

You can access any entity at an arbitrary location of a storage and specify events.

Ports enable a discrete-event System object to exchange entities and data with other blocks or model components. You can specify a variable number of input and output ports using the getNumInputsImpl and getNumOutputsImpl methods. You can also specify which ports are entity ports and the entity types for these ports. Use the getEntityPortsImpl method to specify these port properties.

Events

You can schedule events for a discrete-event System object to execute. Events are associated with user-defined actions. An event action defines a custom behavior by changing state or entity values, and executing the next set of events.

You can use methods and functions to:

  • Schedule events

  • Define event actions in response to events

  • Initialize events

  • Cancel events

A MATLAB discrete-event System object can have these types of events:

  • Storage events — You can schedule these events on a storage element. The actor is a storage element.

    • You can generate a new entity inside a storage element.

    • You can iterate each entity of a storage element.

  • Entity events — You can schedule these events on an entity. Actor is an entity.

    • You can delay an entity.

    • You can forward an entity from its current storage to another storage or output port.

    • You can destroy the existing entity of a storage element.

For more information on using events and event actions, see Customize Discrete-Event System Behavior Using Events and Event Actions.

Implement a Discrete-Event System Object with MATLAB Discrete-Event System Block

To Implement a custom block by assigning a discrete-event System object, follow these steps.

  1. Open a new model and add the MATLAB Discrete-Event System block from the SimEvents library.

  2. In the block dialog box, from the New list, select Basic to create a System object from a template.

    Modify the template as needed and save the System object.

    You can also modify the template and define Discrete-Event System objects from the MATLAB Editor using code insertion options. By selecting Insert Property or Insert Method, the MATLAB Editor adds predefined properties, methods, states, inputs, or outputs to your System object. Use these tools to create and modify System objects faster, and to increase accuracy by reducing typing errors.

  3. If the System object exists, in the block dialog box, enter its name for the Discrete-event System object name parameter. Click the list arrow to see the available discrete-event System objects in the current folder.

    The MATLAB Discrete-Event System block icon and port labels update to the icons and labels of the corresponding System object. Suppose that you select a System object named myServer in your current folder and generate a custom entity server block that serves entities and outputs each entity through the output port. Then, the block updates as shown in the model.

Many different MATLAB System object functions allow you to capture the properties and implement custom behaviors. The provided template is simplified, but you can add complexity by editing event actions, introducing actions, and modifying parameters. The object-oriented programming features of MATLAB System object enable you to scale your model, and interface it with the graphical programming features of SimEvents.

These topics walk you through a complete workflow for creating custom bocks with distinct functionalities.

For other examples of MATLAB Discrete-Event System block and discrete-event System objects, type SimEvents Examples in the SimEvents Help browser.

To use provided custom blocks, in the SimEvents library, double-click the Design Patterns block. The MATLAB Discrete-Event System category contains these design patterns:

ExampleApplication

Custom Generator

Implement a more complicated entity generator.

Custom Server

Use a custom server.

Selection Queue

Select a specific entity to output from a queue.

For more information, see SimEvents Common Design Patterns.

See Also

|

Related Topics