Petriscript
PetriScript is a modeling language for Petri nets, designed by Alexandre Hamez and Xavier Renault.[1] The CPN-AMI platform provides many tools to work on Petri nets, such as verifying and model-checking tools.[2]
Originally, simple Petri nets were created through graphic design, but research conducted internally at LIP6 revealed that it was needed to automate such tasks.[3] PetriScript was designed to provide some facilities in modeling places-transition and coloured Petri nets within the CPN-AMI platform. Petriscript's main purpose is to automate modeling operations on Petri nets by merging, creating, and connecting nodes. It supports almost everything needed, such as macros, loops control, lists, and string and arithmetic expressions, and blocks intervention of the user as much as possible. Its syntax is Ada-like.
The following script produces a FIFO with three sections:
define(FIFO_SIZE,3)
define(FIFO_BASE_X,100)
define(FIFO_BASE_Y,100)
define(FIFO_STEP,120)
int $wave := 0;
for $wave in 1..FIFO_SIZE loop
create place "Slot_" & '$wave' (x FIFO_BASE_X + FIFO_STEP * $wave,
y FIFO_BASE_Y);
create place "Empty_" & '$wave' (x FIFO_BASE_X + FIFO_STEP * $wave,
y FIFO_BASE_Y + 100, marking "1");
end loop;
for $wave in 1..FIFO_SIZE+1 loop
create transition "t" & '$wave -1' & "_to_" & '$wave' (x FIFO_BASE_X + FIFO_STEP * $wave - FIFO_STEP / 2,
y FIFO_BASE_Y + 50);
if $wave < FIFO_SIZE+1 then
connect "1" transition "t" &'$wave -1' & "_to_" & '$wave' to place "Slot_" & '$wave';
connect "1" place "Empty_" & '$wave' to transition "t" &'$wave -1' & "_to_" & '$wave';
end if;
if $wave > 1 then
connect "1" transition "t" &'$wave -1' & "_to_" & '$wave' to place "Empty_" & '$wave - 1';
connect "1" place "Slot_" & '$wave - 1' to transition "t" &'$wave -1' & "_to_" & '$wave';
end if;
end loop;
set transition "t0_to_1" to (name "FIFO_Start");
set transition "t" & 'FIFO_SIZE' & "_to_" & 'FIFO_SIZE + 1' to (name "FIFO_End");
Which produces the following graph:
Here is another example that shows the power of PetriScript:
define(X,250)
define(Y,350)
define(radius,50)
define(R,150)
define(SECTIONS,15)
define(INNER_ANGLE,360/SECTIONS)
define(OUTER_ANGLE,360/(2*SECTIONS))
int $i := 0;
int $j := 0;
for $i in 1.. SECTIONS loop
create place "F" & '$i' ( x X, y Y, r radius, t $i * INNER_ANGLE);
create place "Section_" & '$i' ( x X, y Y, r R, t $i * INNER_ANGLE);
create transition "t" & '$i' & "_to_" & '$i mod SECTIONS + 1' ( x X, y Y, r R, t $i * INNER_ANGLE + OUTER_ANGLE);
end loop;
for $i in 1.. SECTIONS loop
connect place "Section_" & '$i' to transition "t"&'$i' & "_to_" & '$i mod SECTIONS + 1';
connect transition "t" & '$i' & "_to_" & '$i mod SECTIONS + 1' to place "Section_" & '$i mod SECTIONS + 1';
if $i /= 1 then
connect place "F" & '$i' to transition "t" & '$i-1' & "_to_" & '$i';
else
connect place "F1" to transition "t" & 'SECTIONS' & "_to_" & '1';
end if;
connect transition "t" &'$i mod SECTIONS + 1' & "_to_" & '($i+1) mod SECTIONS + 1' to place "F" & '$i';
end loop;
for $i in 1.. SECTIONS loop
if $i mod 3 = 0 then
set place "Section_" & '$i' to marking "1";
else
set place "F" & '$i' to marking "1";
end if;
end loop;
Which produces the following graph:
References
- Alexandre Hamez; Xavier Renault. "PetriScript Reference Manual 1.0" (PDF). LIP6. Archived from the original (PDF) on 24 October 2016.
- Principles of Information Systems: Computer science
- Business Database Systems: Computer science, Database management
External links
Full documentation is available here.