
Ptolemy simulation environment
Ptolemy
Ptolemy is a real-time simulation environment for parallel heterogeneous systems. The project is being developed by students at the University of Berkeley under the supervision of Professor Edward Lee. The development language used is Java. Ptolemy is constantly evolving. Support for new calculation models and new demo models are added, and documentation is expanded.
Ptolemy allows you to work with dozens of different calculation models, among which, for example, there is a discrete-event modeling and a finite-state machine. The modeling is based on the concepts of Actor and Director, which can be translated as "Executive link" and "Manager link", respectively. Director defines the calculation model in which the simulated system works. Many Actor'ov in combination with the connections between them determine the actual device system. In the first article, I want to turn to the discrete-time model.
Discrete event
DE provides basic tools for simulating real-time systems, such as queuing systems and communication networks. The simulation process is the movement of tokens between Actor's. A marker inherently represents some kind of data structure. When the marker enters the Actor, it will launch some action that can change the internal state of the Actor and generate new events. The DE scheduler ensures that all events occur strictly synchronously. Transfer of a marker between Actor'ami does not take time. It is important to remember that markers cannot spontaneously appear or disappear.
Let's assemble a simple discrete-time model. Let it be a data channel in which delay and packet loss are modeled. Markers will act as packages. First, open the editor window ( File - New - Graph Editor ). Most of the window is occupied by the workspace on which to assemble the model. To the left of the workspace is a library of Actor's and Director's. Add DE Director from the Directors section to the workspace . Instead of the English word Actor, which in this context is not succinctly translated into Russian, I will continue to use the word “block”.
Since markers cannot spontaneously appear and disappear, we need some source. We use the block SingleEventfrom Actors / DomainSpecific / DescreteEvents . This block does not work cunningly: it produces one marker at a specified point in time. The marker value and time can be specified in the block settings (the parameter settings window is opened by double-clicking on the block). Next, we need to simulate the delay of packet transmission in the channel. To do this, add the Server block from the same section of the library.

Connect the SingleEvent output to the server input.



So far, the Server block delays any token for a strictly defined time specified in its parameters. We introduce an element of randomness. For this you need a Uniform blockfrom the Actors / Random section , which when a marker enters the input generates a new marker with a random value distributed according to the normal law between the lower and upper boundaries (set in the parameters).


For rough correspondence of the simulated channel to the real one, only packet losses during transmission are lacking. To model losses, use the DiscreteRandomSource block.from the same section of Random. An array of generated values is indicated in its values parameter, and an array of probabilities of generating each value in a parameter pmf (Probability mass function). We specify values 0 and 1 in values, and in pmf - 0.85 and 0.15.

When the marker arrives at the trigger input, a block with a probability of 85% will generate zero and with a probability of 15% - one. Connect the trigger input to the server output. (Nodes are used for branching the lines - a black rhombus on the toolbar) We use these values as a sign of loss (unit - packet lost).

Such a simple channel in itself is of little interest, but it is convenient to use it for modeling network protocols. A simulated channel can transmit packets with a random delay and lose them with a certain probability.
Ptolemy allows you to create new Actor'y, collecting them from existing ones. In the Utilities library section, there is a CompositeActor block into which you can place any other blocks, including CompositeActor. Place the channel model in the CompositeActor. The CompositeActor workspace is opened by the OpenActor command from the context menu. The SingleEvent block is no longer needed. Instead, add one input and one output port.

You can simplify the work with the channel if you “bring out” all the important parameters: the lower and upper boundaries of the time delay range and the probability of packet loss. To do this, add the parameters lowDelayBorder, highDelayBorder and lossProbability in the block parameter settings window. The Add button brings up the corresponding dialog, in which in particular you can specify the default values for the added parameters. New parameter names are now available inside the block. Replace specific values with parameter names in Uniform and DiscreteRandomsource blocks.

By building a primitive package source:

You can test the operation of the channel:

In the settings of DE Director, there is an important parameter - stopTime. By default, it is set to infinity, but to observe such a simple model, a value of 50 will be quite enough. Let
me end this acquaintance with Ptolemy. If the topic is in demand, it will soon be continued.