首页 > > 详细

program讲解 、辅导 c/c++,Java编程

Methodological instructions
for laboratory work

Modeling colored Petri nets in CPN Tools

Laboratory work No. 1.
Topic: Petri nets. Introduction to CPN Tools

Theoretical information
CPN Tools is a special software tool designed for modelling hierarchical temporary coloured Petri nets. Such networks constitute a universal algorithmic system that makes it possible to describe arbitrary object.
CPN Tools allows you to visualize the model using a Petri net graph and use the CPN ML (Coloured Petri Net Mark-up Language) programming language for a formalized description of the model.
Purpose of CPN Tools:
development of complex objects and modelling of processes in various applied areas, including: modelling of production and business processes;
modelling of control systems for production systems and robots;
specification and verification of protocols, assessment of network capacity and quality of service, design of telecommunication devices and networks.
Main functions of CPN Tools:
creating (editing) models;
analysis of model behaviour using network dynamics simulation
Petrie;
construction and analysis of the state space of the model.

Interface CPN Tools
The remaining version of the program can be downloaded from the site http://cpntools.org/. The site also contains documentation for design and initial applications, which allows you to quickly master the basic principles of creating models in CPN Tools. After launch, the main CPN Tools window will appear (Fig. 1).

Figure 1 - Main window of CPN Tools
The main window consists of two areas: the work area (on the right) and the menu area (on the left), containing the Tool box, Help system and Options settings. In the work area, you can call up both individual toolbars (Fig. 2) and a graphical representation of the model in the form of a Petri net. To open the tool palette, you need to drag it, holding down the left mouse button, from the menu to the work area.

Figure 2 - Toolbars in the CPN Tools workspace

Two functions are available in the interface assigned to the user:
attraction of the created border «Load Net»;
creation of a new network «New Net».
To create a new network (Fig. 3), you need to press the right mouse button in the work area and press the right mouse button in the menu, select the “New net” item and move the mouse cursor to the new one. The work with other menus in the CPN Tools program is organized in a similar manner.

Figure 3 - Create a new model in CPN Tools

After executing the command to create a new model, the program window will take the form that you see in Figure 4. In this case, a new item «New net.cpn» will appear in the menu area, by opening which you can change the model parameters, declare data types and enter new variables. In addition, right-clicking on the «New net.cpn» item will open a context menu in which you can save the network, undo/redo the action, create a new page and close the network.
Figure 4 - Appearance of the CPN Tools program after creating a new model

There are a few more steps you need to take before you begin. Click on the «Tool box» item in the workspace, select «Create» from the drop-down list, click on it with the mouse and, while holding the mouse button, drag it onto the workspace. Do the same with the «Simulation» item. After completing these steps, panels will be added to create a Petri net (Create) and to control the modelling process (Sim), and the user interface of the program will take the form shown in Figure 5.

Figure 5 - Appearance of the CPN Tools program after adding
new control panels

The tools of the Create panel with their detailed descriptions are presented in Table 1.
The tools of the Simulation panel with their detailed descriptions are presented in Table 2. To set the number of modelling steps, you need to right-click on the corresponding tool and select «Set options» in the context menu that appears. For a modelling tool with visualization of intermediate results, in a similar way you can set the time between modelling steps

Table 1
Tools panel Create

Tool image Description of the tool
Creating a transition. To do this, click on the tool and then on the model in those places where you need to create transitions.
Creating a position. To perform this, you need to click on the tool, and then on the model in those places where you need to create positions.
Creating an arc. To do this, click on the tool and then on the model elements that need to be connected. You can only connect a position with a transition. In this case, the arc will be directed from the first selected element to the second.
Creating a vertical line. To do this, click on the tool and then on the model. The vertical and horizontal lines are intended to organize the model. Elements located near the line are attracted to it. Using this tool, you can improve the perception of the model.
Deleting an element. To delete, click on the tool, and then on the model elements that need to be deleted.
Cloning an element. To clone, you need to use the selected tool to click on the element that needs to be cloned. After this, the cursor will change to the selected element. Then, by clicking on the model, we will create a copy of the element each time. Cloned elements are not renamed. You need to do this yourself.
Changing the direction of the arc. To perform this, you need to click on the corresponding arc with the selected tool. The arc can be either one-sided or two-sided. A double-sided arc is used to save model space and is an analogue of two arcs directed in the opposite direction and having the same expressionsя.
Creating a horizontal line. Similar to creating a vertical line.

Table 2
Tools panel Simulation

Tool image Description of the tool
Transferring the model to the initial state. In this case, all transitions are assigned their initial marking. To perform this, you need to click on the model with the selected tool.
Stopping the model execution. To perform this, you need to click on the model with the selected tool.
Performing an active transition with specific markings. This tool is discussed in more detail below.
Performing one modelling step, that is, one transition. To perform this, you need to click on the model with the selected tool. In this case, one of the active transitions will fire. When you click on an active transition, it will be triggered.
Performing a specified number of steps with a certain time interval between them and visually changing the network markings. To perform this, you need to click on the model with the selected tool. The simulation process can be stopped.
Perform a specified number of steps, without showing intermediate markings. To perform this, you need to click on the model with the selected tool.
Checking the selected text for correctness in terms of the syntax of the built-in programming language CPN ML. To execute, you need to use the selected tool to click on the text containing the CPN ML code.

For interaction with model elements and tool palettes, CPN Tools provides a set of context-sensitive menus that appear on the screen when you click the right mouse button. The menu has the shape of a circle with the names of sectors (see Fig. 3). To save the menu on the screen, you should hold down the mouse button while moving the sector to select the required element. In most cases, the elements of the context-sensitive menus duplicate the tools in the palettes.
In CPN Tools, models are called networks (net). Their description is located in the menu under standard elements. Each network in CPN Tools is represented by the following menu fields:
name - the name of the corresponding file with the extension .cpn;
step (step) - the number of steps performed during the simulation;
time (time) - current model time;
options (options) - network options;
history (history) - a list of commands that were executed above network;
declarations (declarations) - descriptions of multiple colours, variables, functions, constants;
pages (page) - names of network pages (working areas of the model).
Context-sensitive menus are used to create new descriptions and new pages. To open an existing network page, you need to drag it from the side menu to the work area.
CPN Tools provides graphical feedback that reflects the current state of the system:
pop-up messages - a rectangle that appears when you hover the mouse over an object and provides context-sensitive information (errors during syntax checking, errors during network modelling, tooltips in palettes, information for the state indicator, the result of using the CPN ML language evaluation tool, the full path to the saved network);
state indicator - shows the current state of the model (green - the action was completed successfully; red - an error occurred while performing the action; purple - a long-term operation is currently in progress);
element highlighting - colour coding to highlight objects with certain properties:
obright red - indicates objects with errors during syntax checking and network modelling;
odark red - indicates repeated names of positions and transitions during syntax checking;
ogreen - indicates allowed transitions during network modelling;
odark blue - indicates the dependency between descriptions and other elements such as positions, transitions and pages;
osea green colour - indicates the object that contains the description;
oorange – indicates that the object’s syntax checking has not yet begun;
oyellow - indicates that the object’s syntax check is currently being performed;
o– pink - indicates which merged positions belong to the merge set;
o– aqua color - indicates port/socket assignments and page/subpage relationships when working with hierarchical networks;
changing shape of the cursor – determines the actions that can be performed.

Model description language
In CPN Tools, each Petri net element has its own attributes, described in the CPN ML language. Using the network element creation tools, you can place the element on the model page. Then the element attributes are added. To do this, click on the appropriate element and use the Tab button on your keyboard to toggle attributes. Pressing the Esc key on the keyboard allows you to leave the selected item; the same result can be obtained by clicking on any other area of the model.
Position attributes (Fig. 6):
colour of chips;
initial marking;
name.

Figure 6 - CPN Tools Item Attributes

The attribute of an arc is the expression expr, which must correspond to the set of colours of the position associated with the arc (Fig. 7). The transition input arc expression is the template for token selection. This pattern is described as a predicate that can be applied in the filter function to the corresponding set of colours. The transition output arc expression is a constructor for creating new tokens. Such a constructor often uses input arc label variables and in simple cases can coincide with one of them.

Figure 7 - Arc Attribute CPN Tools

Transition attributes (Fig. 8):
transition name;
transition trigger condition (a Boolean expression that evaluates to true or false);
delay time (positive integer);
code segment (ML language procedure that is used for more complex processing of input tokens).

Figure 8 - CPN Tools Transition Attributes
Transition delays apply to all transition output tokens.

Laboratory work No. 0. Model
"Feed the Students"
Consider the example of students eating pie for lunch. A hungry student becomes full after eating a pie.
Thus, we have:
two types of chips: “pies” and “students”;
three positions: “hungry student”, “food”, “satisfied student”;
one transition: “eat”.
1. Draw a network graph. To do this, use the context menu to create a new network, add positions, transition and arcs (Fig. 9).

Figure 9 - Network graph of the “Feed the students” model

2. In the menu, set new model declarations: types of tokens, initial values of positions, expressions for arcs. To do this, hover the mouse over the Standard declarations menu, right-click to open the context menu and select New Decl.
After this, we assign type s to chips related to students, type p to chips related to pies, set the values of the variables x and y for the arcs and the initial values of the multisets init_stud and init_food (Fig. 10):
colset s=unit with student;
colset p=unit with pasty;
var x:s; var y:p;
val init_stud = 3`student;
val init_food = 5`pasty;
As a result, we get a working model (Fig. 11).

Figure 10 - Declarations of the “Feed the Students” model

Figure 11 - Model “Feed the Students”
After launching, chips of the “pies” type from the “food” position and chips of the “students” type from the “hungry student” position, having passed through the “eat” transition, end up in the “well-fed student” position and are transformed into the “students” type (Fig. 12).

Figure 9 - Launch of the “Feed the Students” model

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!