Università degli Studi di Catania
Facoltà di Ingegneria
Dipartimento di Ingegneria Informatica e delle Telecomunicazioni
Viale A.Doria, 6 95125 Catania
University of Catania, Faculty of Engineering
Department of Computer Science and Telecommunications
Viale A.Doria, 6 95125 Catania (ITALY)
Fax: +39 095 338280
1. Softwares needed to run TPTPN Simulator 3
2. Installation Procedure 3
3. How to Link a C++ Procedure to a Transition 3
3.1. Introduction 4
3.2. Project Skeleton 4
A.Procedure Declaration 4
B.Procedure Mapping Section 5
3.2.1.Global Variables 5
3.3. Procedure Implementation 6
On Run 6
On Load/Unload 6
On Exit_Transient 7
3.4. Visibility of the Model 8
Set/Get Marking 9
4. Performance Expression Sintax 11
4.1. Arithmetical Operators 11
4.2. Relational Operators 11
4.3. Logical Operators 11
4.4. Built-in Functions 11
1.Softwares needed to run TPTPN Simulator
You need Windows 95/98/NT 4.0 or 2000 Operating Systems. Microsoft Visual C++ 5.0 or higher is required. It is assumed that Microsoft Visual C++ is installed in the sub directories starting from DevStudio.
In order TPTPN Simulator could correctly work, the following steps must be followed:
if Windows 95/98 is your Operating System, please run instmsiA.exe
if Windows NT 4.0 is your Operating System, please run instmsiW.exe
if Windows 2000 is your Operating Systems, skip at the next step
run WinTTPN.msi. The installation procedure will start. You will be asked to introduce the WinTPTPN Home Directroy. If the installation procedure will success, the following files are installed in the WinTPTPN Home Directroy: CJ609Lib.dll, Linked Procedure Wizard.awx, RandomLib.dll, Student.dll, WinTTPN.exe.
copy or move the file Linked Procedure Wizard.awx into the directory ../DevStudio/SharedIDE/bin/ide
In order to run the TPTPN Simulator use WinTTPN.exe. An important feature of the simulator is the possibility to associate a procedure written in C++ to a transition in the TPTPN model. The following section will explain how to do this.
3.How to Link a C++ Procedure to a Transition
In the following subsections the main steps to follow in order to link a procedure to a transitions in the TPTPN model are explained in details. In particular, the user has to build a proceudre library containing all the procedures (written in C++) and their association to the transitions of the TPTPN model previoulsy defined.
TPTPN Simulator release contains a wizard through which it is possible to define the project skeleton to build the procedure library to be associated to the TPTPN model. In order to make visibile the procedure library related to a petri net model (*.pn file) it is mandatory:
Library name coincides with the name of the model;
Library, once it has been compiled, must be moved into the same directory where the *.pn file is stored.
The project skeleton build through the use of the wizard, contains many files, but only two of these must be modified in order to specify the procedures to be associated to the transitions. These files are an include file (*.h) and a cpp file (*.cpp) having as name the same name of the project (and the name of the petri net model). For example, if the name of the library was my_library when it was created through the wizard, files to be modified are my_library.h and my_library.cpp.
In the include file (e.g. my_library.h) names of the procedures and the mapping between the procedures and the transitions must be specified.
The file is made up by two sections: procedure_declaration_section e procedure_mapping_section.
In this section all the procedures used in the TPTPN model must be defined. The syntax is:
DECLARE_PROCEDURE( procedure_name )
where procedure_name is the name to be assigned to the procedure.
It is mandatory to declare every procedure used in the TPTPN model in this section.
B.Procedure Mapping Section
In this section the mapping between procedures previously declared and the trasnsitions in the TPTPN model are declared.
The file already contains the skeleton made up by the following element:
Inside the parentheses it is possible to relate each procedure to a transition, using the macro ON_TRASITION_FIRING, as shown in the following:
ON_TRASITION_FIRING( #transition, procedure_name )
where #transition is the number of the transition in the TPTPN model to which procedure specified by procedure_name is related. The procedure must be declared in the POCEDURE_DECLARATION_SECTION by the DECLARE_PROCEDURE, as explained before.
DECLARE_PROCEDURE( Check_Resource )
DECLARE_PROCEDURE( Free_Resource )
ON_TRASITION_FIRING( 1, Check_Resource )
ON_TRASITION_FIRING( 2, Free_Resource )
ig.1 shows the code to define two procedures and to associate them to two transitions in the model. Transition numbers are 1 and 2 in the TPTPN model, procedures are called Check_Resource and Free_Resource.
In the file my_library.h it is possible to define the global variables that one or more procedures share. Definition of the variables is performed according to rules defined in C++ language.
Each procedure previously declared needs to be implemented in C++. File my_name.cpp built by the wizard, must contain the code concerning the implementation of the procedures. To reach this goals the macros ON_RUN, ON_LOAD, ON_UNLOAD and ON_EXIT_TRANSIENT() must be used.
ON_RUN macro allows to specify the code to be executed when the transition (associated to the procedure as seen before) fires. The syntax is:
ON_RUN( procedure_name )
where procedure_name is the name of the procedure and the C++ code is the code that will be executed on the firing of the transition associated to the procedure.
Sometimes it is necessary to allocate/initialise variable/object instances used globally (i.e. seen by all the procedures) or locally (seen only inside a procedure) when the simulation starts. Sometimes it is necessary to de allocate a variable or an object instance when the simulation ends.
It is possible to execute a procedure at the start and/or at the end of the simulation using the macros On load and Unload. The syntax is:
ON_LOAD ( procedure_name )
where procedure_name is the name of the procedure and the C++ code is the code that will be executed when the simulation starts.
ON_UNLOAD (procedure_name )
where procedure_name is the name of the procedure and the C++ code is the code that will be executed when the simulation ends.
It is important to point out that the presence of the two macros is mandatory. So they must be already present, and must be empty (i.e. no C++ code is present) when no allocation/initialization or deallocation is necessary.
Sometimes it is necessary to evaluate performance of a system during the interval between the start of the simulation and the instant at which the system reach a steady state condition. Once the steady state has been reached, the user would like to introduce some event and to run the simulation again, in order to see the effect of the event on the performance of the system. In this case it is desired that the simulator stops once the steady state has been reached, without performing T-Students evaluation, and restarts from the current state. A function, called On_Exit_Transient(), has been defined in order to understand when the steady state has been reached and to tell the simulator to stop performing T-Students evaluation or to run again, starting from the current state. The syntax is:
where C++ code must be written in order to return 1 if the user requires that the simulator runs again starting from the actual state. The code must return 0, if the user wants that the simulation stops and the T-Students evaluation is performed.
else return 0;
Figure 2 - Example of ON_EXIT_TRANSIENT()
In the example shown in Fig.2, the user requires that simulation must be performed again if the value of a global variable (counter) is equal to 1. In this case an event is introduced. In particular a token is put in place 19. If the global variable is greater than 1, the simulation must be stopped and the T-Students evaluation must be performed.
3.4.Visibility of the Model
In order to be able to implement a procedure, it is necessary to know the objects and the functions to manipulate them in the TPTPN model.
For each TPTPN model an object, called thePNModel can be used. Functions that can be applied to this object are: DoMessage, Events, Time, GetMarkigOf, SetMarkingOf..
DoMessage makes it possible the output in the proper windows of the simulator. The syntax is:
DoMessage(const char* message)
where message is the pointer to the string of characters to be printed in the output windows. Fig.3 shows a simple example of the use of this function.
thePNModel -> DoMessage(“Check Resource Mapped”)
igure 3 – The message “Check Resource Mapped” is shown in the output windows of the simulator
Functions Events() and Time() returns the number of events and the current simulation time, respectively. Fig.4 shows a simple example of the use of these functions.
msg<<”Time:”<Time()<<“,“<<“Events:”<Events() << endl;
thePNModel -> DoMessage(msg)
Function GetMarkingOf allows to know the number of tokens in a place specified. The syntax is:
GetMarkingOf( #place )
where #place is the place number where are container the token, whose number is required.
Function SetMarkingOf allows the modification of the marking in a psecified place:
SetMarkingOf( #place, #number_of_tokens )
where #place is the place number where the number of tokens must be modified and #number_of_token is the new value of number of tokens. Fig.5 shows an example, related to the set to 0 of the number of tokens in place number 1.
thePNModel -> SetMarkingOf(1, 0);
4.Performance Expression Sintax
TPTPN simulator offers a syntax analyser for the definition of performance evaluation parameters. It is possible to build complex expression combining together the operators and built-in functions, described in the following.
The classical arithmetic binary operators +, -, / and * are recognised. Syntax is:
4.2. Relational Operators
The following relational operators can be used to build boolean expressions: >, <, <=, >= , ==, !=.
The syntax is:
The following logical operators (AND/OR) can be used && (or AND), || (or OR). The syntax is:
The following built-in functions can be used:
Pr() or ProbabilityOf(), to evaluate the probability that the expression is true;
#() or MarkingOf(), to evaluate the average number of tokens in the place ;
Sr() or ServiceRate(), to evaluate the average service rate frequency related to the place ;
Ar() or ArrivalRate(), to evaluate the average arrival rate frequency of tokens in the place ;
Wt() or WaitingTime(), to evaluate the average waiting time of a token in place .