Create Custom Blocks Using MATLAB Discrete-Event System Block

离散事件年代ystem objects let you implement custom event-driven entity-flow systems using the MATLAB®language. TheMATLAB Discrete-Event Systemblock 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.

您可以创建一个定制的鉴别器ete-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.

TheMATLAB Discrete-Event Systemblock is similar to theMATLAB Systemblock with these differences:

  • The resulting discrete-event System object is an instantiation of thematlab.DiscreteEventSystemclass rather than thematlab.Systemclass.

  • Thematlab.DiscreteEventSystemhas its own set of System object methods particular to discrete-event systems.

  • Thematlab.DiscreteEventSystemalso inherits a subset of theMATLAB Systemmethods. For a complete list of this subset, seeCreate 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 thegetEntityTypesImplmethod:

  • 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,carandtruck, 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 thegetEntityStorageImplmethod 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 (先进先出,LIFO, andpriority).

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

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

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 thegetNumInputsImplandgetNumOutputsImplmethods. You can also specify which ports are entity ports and the entity types for these ports. Use thegetEntityPortsImplmethod 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:

  • 安排活动

  • 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, seeCustomize Discrete-Event System Behavior Using Events and Event Actions.

Implement a Discrete-Event System Object withMATLAB Discrete-Event SystemBlock

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

  1. Open a new model and add theMATLAB Discrete-Event Systemblock from the SimEvents library.

  2. In the block dialog box, from theNewlist, selectBasicto 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 selectingInsert PropertyorInsert 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 theDiscrete-event System object nameparameter. Click the list arrow to see the available discrete-event System objects in the current folder.

    TheMATLAB Discrete-Event Systemblock icon and port labels update to the icons and labels of the corresponding System object. Suppose that you select a System object namedmyServerin 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 blocks with distinct functionalities.

For other examples ofMATLAB Discrete-Event Systemblock and discrete-event System objects, see SimEvents Examples in the Help browser.

To use provided custom blocks, in the SimEvents library, double-click theDesign Patternsblock. TheMATLAB Discrete-Event Systemcategory contains these design patterns:

Example Application

Custom Generator

Implement a more complicated entity generator.

Custom Server

使用一个自定义的服务器。

Selection Queue

Select a specific entity to output from a queue.

For more information, seeSimEvents Common Design Patterns.

See Also

|

Related Topics