Rochester Institute of Technology
RIT Scholar Works
Theses
Thesis/Dissertation Collections
1998
A Graphical petri nets simulator
Shye-Chyun Huang
Follow this and additional works at:
http://scholarworks.rit.edu/theses
This Thesis is brought to you for free and open access by the Thesis/Dissertation Collections at RIT Scholar Works. It has been accepted for inclusion
in Theses by an authorized administrator of RIT Scholar Works. For more information, please contact
Recommended Citation
ROCHESTER INSTITUTE OF TECHNOLOGY
SCHOOL OF COMPUTER SCIENCE AND TECHNOLOGY
A Graphical Petri Nets Simulator
by
Shye-Chyun Huang
A thesis, submitted to
The Faculty of the School of Computer Science and Technology,
in partial fulfillment of the requirements for the degree of
Master of Science in Computer Science
Approved by :
~_0_?_·'h_0_(f~
_
j
Dr. James Heliotis
G/2-7
J88
Prof. Alan Kaminsky
'2.
y
:r~L
n
~8
Dr. Peter G. Anderson
-Title of Thesis : A Graphical Petri Nets Simulator
I Shye-Chyun Huang hereby grant permission to the Wallace Memorial Library, of
RIT,
to
reproduce my thesis in whole or in part. Any reproduction will not be for
commercial use or profit.
Date: July 27,1988
Table
ofContents
Title
andAcceptance Page
1
Abstract
2
Computing
Review Subject Code
2
1.
Introduction
andBackground
3
1.1 Introduction
3
1.2 Basic Petri
Nets
4
1.3
Subclass
ofPetri Nets
8
1.4
Requirements
ofPetri
Net
Tool
12
1.5 The Advantages
ofUsing
aPetri Net Tool
14
2.
Previous
Work
15
2.1
SPECS
Project
15
2.2 PSI
16
2.3 Tool
Overview
18
2.4
Comparisons
between
GPNS
andotherPetri
Net Tools
20
3.
Function
Specification
21
3.1
NetEditor
21
3.2 Simulator
24
3.3
Auxiliary
Application
Program
24
4.
Program
Description
25
4.1
Overview
25
4.2
The System
Organization
Chart
26
4.3 Data
Structure
Formates
27
4.4
The Flow
Chart
ofthe
Shell Program
29
4.5 The
Algorithm
ofthe
Main Function
30
4.6 The
Graphics
Driver
31
4.7
The
User
Interface
32
4.8
Hierarchical
Process Diagram
33
4.9 The Simulator
52
4.10Function
List
54
5.
Conclusion
66
5.1
Problem Encounted
andSolved
66
5.2 Limitation
ofthe
System
67
6.1
Alternative Approaches for Improved System
68
6.2
Suggestion
for Future
Extension Reference
68
7.
Reference
70
Appendix A
Users'Abstract
This
thesis
is
an application software system(Graphical
Petri
Net
simulator
GPNS)
providing
awindow-oriented,
menu-driven and graphicalinterface
simulatorfor
Petri
nets.This
simulatoris
based
onPlace/Transition
nets
(PT-nets). It
allows usersto
design
and simulatePT-net
under aninteractive
graphical environment.GPNS
also provides autility,
Auxiliary
Application
Program
(AAP),
to
make
it
more useful.When
applying the
AAP
withthe
GPNS,
eachfunction
in
the
AAP
canbe
attachedto
acorresponding
transition
in
the Petri
net.Whenever
an enabledtransition
in
the Petri
Net
is fired
will causethe
corresponding
function
in
the
AAP
to
be
executed.In this
case,
It is
closerto
aPredicate/Action
netthan
aPlace/Transition
net,
exceptthat
no predicatesare attached.
This
Petri
Net
simulatorcanbe
avery
goodtutorial tool
in
an educationalenvironment.
Subject
to
somerestrictions,
it
canbe
avery
usefultool
for
modeling
anddesigning
a system.Computing
Review
Subject Codes
The
following
arethe
classification codesfor
this
paper as specifiedin
the
ACM
Computing
Reviews
(1986)
Classification
System.
Primary:
1.3.4
Graphics Package
Secondary:
F.l.l
Computability Theory
1.
Introduction
and
Background
Real
systems aretoo
complexto
be
fully
understood.Even
smallsystems will
eventually
exhibit an enormouscomplexity
when examinedin
sufficient
detail.
Therefore,
the
design, implementation,
andmaintenance of complex systemshave become
seriousproblems,
andthe
subject of much research and experimentation^].Petri
Net is
amodeling
tool
developed
by
focusing
only
on a small part andignoring
the majority
ofthe
systemto
master
the complexity
andto
"understand"the
system.This
modeling tools
canbe
usedto
modelthe
real systemsordevelop
a new one.By
studying the
models rather
than the
realsystem, the
cost,
inconvenience,
ordanger
ofmanipulating
the
real systemcanbe
avoided.1.1
Introduction
Petri
Nets,
introduced
by
Carl Adam Petri in
his thesis[13], have
asimple graphical
representation, widely
elaboratedtheoretical
background,
and excellent
ability to
representsynchronous and asynchronous events.Both
the
structure andthe
behavior
ofa system canbe described
withthe
samegraphical notations[9].
The
properties, concept,
andtechniques
ofPetri
Nets
arebeing
developed
in
a searchfor
natural, simple,
and powerful methodsfor
describing
andanalyzing
the
flow
ofinformation
andcontrolin
systems.The
major use ofPetri
Nets has
been
the modeling
of systems ofeventsin
whichit is
possiblefor
some eventsto
occurconcurrently,
but
there
are constraints onthe
concurrence,
precedence,
orfrequency
ofthese
occurrences[5].
Petri
Nets have
been
used as a powerfulmodeling
tool
in modeling
realsystems
especially
onthose
systemsthat
may
exhibit asynchronous andconcurrentactivities.
3-1.2
Basic Petri Net
The Fig.
1
is
an example ofPetri Nets:
Fig.l
A basic Petri Net
graph consistsofS-elements
andT-elements,
connectedwithdirected
arcs.From
nowon,
the
word"place"
and
"transition"
will
be
usedinstead
ofS-element
andT-element,
respectively.An
arc can connect eitherfrom
a placeto
atransition
orfrom
atransition
to
a place.Therefore,
the
Petri
Net
is
abipartite,
directed
graph[5].Graphically,
places,
represented ascircles,
express acondition which couldbe
eithertrue
ornottrue.
Transitions
map to the
changes ofconditions,
and are represented asboxes
(or
bars
in
some other author'sworks);
arcs aredrawn
as arrows.The
structure of aPetri
Net
containstwo
sets: a set ofPlaces, P,
and a set oftransitions, T.
Two
functions
are specifiedto
connectthe
places andthe
transitions:
/,
the
input
function,
andO,
the
outputfunction.
The input
function /
defines,
for
eachtransition
tjt
the
set ofinput
placesfor it. The
output
function
O
defines,
for
eachtransition
tj,
the
set ofoutputplacesfor it.
Formally,
aPetri
Net
C is defined
asthe
four-tuple C
=(P,TJ,0).
Fig. 2
is
the
structure ofthe
Petri Net
representedin Fig. 1
C
=(P,T,I,0)
P
=(Pl>
P2, P3, P4, P5, P6,
P7J
T
={ti,t2,t3,t4,
t5,t6}
/(ti)
={P2}
O(ti)
={pi}
Z(t2)
={pi}
0(t2)
={p2,P3}
/(t3)
={p3,P5}
0(t3)
={p3}
/(t4)
={p4}
O(U)
=(P5l
Z(t5)
={p3,P7}
0(t5)
={p6}
/(t6)
={P6l
0(t6)
={P7l
Fig.
2
The information
content ofboth
the
graph and structureis identical[5].
In
additionto the
static properties representedby
the graph,
aPetri
Net
has dynamic
propertiesthat
resultfrom
its
execution.Tokens (black
dots)
are usedto
modelthe
concurrentbehavior
ofa system.Petri
Nets
withtokens
arecalled
Marked Nets. A
token residing
on a place meansthe
corresponding
condition
is
true.
Otherwise,
the corresponding
conditionis
nottrue.
A
transition
is
enabledif
allits input
placeshas
atoken
and allits
outputs are empty.The
enabledtransition
couldbe fired
by
removing
the
enabling
token
from
its input
places anddepositing
eachofits
outputplaceswith a newtoken.
Petri
Nets
that
are constructed suchthat
nomorethan
onetoken
can everbe
in
any
placeatthe
sametime
are safe nets.The
definition
couldbe
extendedto
where
Petri
Nets
canhave
no morethan
k
tokens
in
any
given place atthe
same
time.
A
Petri
Net in
whichthe
number oftokens in any
placeis
bounded
by
k
is
called ak-bounded
net.Of
course,
in
this situation,
atransition
couldbe
enabledwithout allits
outputsbeing
empty.If tokens
are usedto
represent
-5-resources, then
it
follows
that
since resources are neither created nordestroyed,
tokens
should alsobe
neithercreatednordestroyed.
A
Petri
Net is
conservativeif
the total
number oftokens
in
the
netis
never changed.To
reducethe complexity
ofPetri
Nets,
the
firing
of atransition
is
considered
to
be instantaneous. Since
time
is
a continuousvariable, then
the
probability
ofany two
or more eventshappening
simultaneously
is
zero,
andtwo
transitions
cannotfire
simultaneously.A
special extension ofPetri
Nets
where a
time
factor is
attachedto transitions
orplacesis
calledatimed
Petri
net.The distribution
oftokens
in
a markedPetri Net
defines
the
state ofthe
net and
is
calledits
marking.The
marking
may
changed as a result ofthe
firing
oftransitions.
In
different
markings,
different
transitions may
be
enabled.In
amarking,
morethan
onetransition
couldbe
enabled.If
firing
one ofthem
willdisable
the
others,
they
are saidto
be
in
conflict.Otherwise, they
are said
to
be in
concurrency.Fig. 3.
a showstwo transitions that
arein
conflict.
Fig
3.b
showstwo transitions that
arein
concurrency.If
the
input
of atransition
is
alsothe
output ofthe
transition, then,
this transition
has
aloop.
Fig. 3
Conflicting
Transitions
Fig. 3.b
Concurrent Transitions
Fig.
3.c
loop
A
transition
is
dead in
amarking if
there
is
no sequenceoftransition
firings
that
can enableit.
A
transition
is
potentially
firable
if there
exists somesequence
that
will enableit.
A
transition
of aPetri
Net is
live if
it is
potentially
firable
in
all reachable markings.A
Petri
Net is live
if
allits
transitions
arelive.
A
live
netis
adeadlock-free
net.A
deadlock
in
aPetri
net1.3
Sub-class
ofPetri Net
Many
extensionshave been
addedto
basic
Petri
Nets
to
extendthe
modeling
power ofPetri
Net
whenapplying
it
on real systems.This
sectiongives short
descriptions
of various extensions ofPetri
Net.
One
ofthe
extensionsis
to
removethe
constraintthat
a placemay
contribute or receive
only
onetoken
from
the
firing
of atransition[10].
This
extensionis for
those
systemsthat
might need morethan
oneidentical
resourceto
changeto
another state.For
example,
considerthe
chemical reactionthat
needstwo
P
andthree
CI2
to
producetwo
PCI3.
This is
modeledby
allowing
multiple arcsbetween
transitions
andplaces,
signifying the
numberoftokens
needed.Petri Nets
that
allow multiplearcshave
been
called generalizedPetri
Nets[5].
Using
an arc with a weighted numberinstead
of multiple arcsbetween
places andtransitions
is
called weightedPetri
Net.
Fig.
4.a
Generalized Petri
Net
Fig. 4.b
Weighted
Petri
Net
Both
weightedPetri
Nets
and generalizedPetri
Nets have
the
sameproperties.
A
special extension ofPetri
Nets
is
so-called zero-testing: atransition
The
arcsthat
connectthe
input
places andthe
transitions
arecalledinhibitor
arcs.
1.3.1
State Machines
State
machines arebasic
Petri
Nets
that
are restricted sothat
eachtransition
has
only
oneinput
and one output.These
nets areobviously
conservative andfinite-state.
They
have
very
high decision
power,
but
are oflimited
usefulnessin
modeling
systemsthat
arenotfinite[5][7].
1.3.2
Marked Graphs
Differing
from
statemachines,
marked graphs restrictthe
places,
but
notthe
transitions,
to only
oneinput
and one output.It
canbe
saidthat
marked graphs arethe
dual
ofstate machines.This
rule eliminatessharing
of placesbetween
transitions
and so eliminates conflict.There
areknown
algorithmsthat
showthat
a marked graphis
live
andsafe,
and solvethe
reachability
problemfor
marked graphs.Thus,
marked graphshave
high
decision
power,
but
have
limited
modeling
power[5][7].Since
marked graphshave
nobranch
controlflow,
parallel activitiescanbe
easily modeled,
but
not alternative activities.1.3.3 Free
Choice
Nets
In free
choice nets each arcfrom
a placeis
eitherthe
unique output ofthe
place orthe
uniqueinput
of atransition.
This
restriction meansthat
if
there
is
atoken
in
a placethen
eitherthe
token
will remainin
that
place untilits
uniqueoutputtransition
fires
or,
if
there
are multipleoutputsfor
the place,
then
there
is
afree
choice asto
which ofthe transitions
is fired. The liveness
and safeness
for
free
choicePetri
Nets
aredecidable
andhave
necessary
andsufficient conditions
for
these
properties[5].Those
netsdescribed
above aregenerally
calledCondition/Events
nets(C/E
nets).A C/E
nethas
the
following
specialcharacterstics.9-1.
A
C/E
netmustbe
asafe net(1-bounded
net).In
otherwords,
no morethan
onetoken
can residein
a place at atime.
2.
A
transition
in
aC/E
net canonly
be
enabled when each ofits input
placesis
loaded
with atoken
and allits
outputs are unloaded.3.
A
C/E
netis
alwaysa pure net.If
atransition
has
aloop
(its
input
placeis
identical
to
its
outputplace),
it
can neverbe
enabled.1.3.4
Place-Transition Nets
(PT-nets)
A
PT-net has
the
following
properties[10].1.
For
every
transition,
there
canbe
multipleinput
and multiple output.2.
More
than
onetoken may
residein
a place atthe
sametime.
3. A
transition
is
enabledonly
when each ofits
input
placeshas
aninteger
number oftokens that
is
greaterthan the
weight ofthe
arc connectedbetween
the
place andthe
transition,
but
those
places connected via outputarcs need notbe
empty.1.3.5
Place-Coloured Nets
(PIC-nets)
In
aPT-net,
allthe tokens
areidentical.
But,
sometimes,
it is
necessary
to
distinguish
these tokens
in
the
netfor modeling
some real systems.PIC
-nets
introduce
the
notation oftoken
identity.
In
coloredPetri
nets,
each
token
has
acolorthat
indicates its
identity,
arcs are
labeled
with expressionsdenoting
functions
or sets(bags)
ofcolored
tokens,
an
initial marking
whichassociatesto every place,
asetof givenvaluesof
the initial
colors,
the
firing
of atransition
is
possibleonly
if
the
input
places of atransition
hold
a set oftokens
requiredby
the
labels
onthe
arcsfrom
the
input
placeto the transition.
1.3.6
Predicate-Transition
Nets
(PrT-nets)
A
PrT-net
specifiesthe relationship
between
tokens
andtransitions.
The
net contains a set of predicates associated with eachtransition
(inscriptions
in
the
transitions); they
givethe
relationshipsbetween
the
input
tokens
that
arenecessary for
the
transition
to
fire.
In
aPrT-net,
atransition
canonly
be
fired
whenthe
names match andthe
predicateis
true.
1.3.7
Predicate-Action Nets
(PrA-nets)
In
PrT-net,
predicatesapply to the
input
places ofthe
transitions
andoperations give new
tokens
in
output places.In
addition,
eachtransition
has
an expression ofthe
form "Predicate
Action"attached
to
it.
A
PrA-net
mustbe
a safenet(
that
implies
the
weights of all arcsin
the
net
is
one).In
orderto
enable atransition
in
aPrA-net,
the
predicateassociated with
the
transition
mustbe
true,
whenthe
enabledtransition
is
fired
the
action attachedto
it
willalsobe
taken.
11-1.4.
Requirements
ofPetri
Net
tool
The
requirements of a graphical net-editoris
illustrated
in
"Petri Net
Tools"by
Frits
Feldbrugge[4]. A
netdescription
in
graphform
consists oftwo
separatebut
relateddata
sets:- a
(logical)
netdescription,
and- a
layout description.
The
netdescription is
a mathematicalstructure,
defined
by
sets, relations,
functions,
etc.describing
the
netstructure,
values of attributes associated with netelement,
marking,
etc.The
layout
description
contains additionalinformation,
such as positions of net elements andattributes, necessary to
constructthe
netdrawing
asit
was madeby
the
user.In
orderto
provide a userfriendly
interface,
a graphical net-editor shouldcontaina rich setofediting
functions
to
atleast do
the
following:
add/remove net
elements,
reposition net
elements,
-
fill in
and/ormodify
netinscriptions
(such
ascapacities, predicates,
markings),
zoom
in/out
work at various
hierarchical
levels,
relatenet elements on
different levels
to
one another and changethese
relationships.provide
total
netoverview,
-copy
net parts(alsobetween
levels),
12-The
GPNS
only
implements
asubsetofthe
modeldescribed
above.It is
a simple net-editor without
hierarchical
net structure andcopy
function. The
entire overviewof
the
GPNS
willbe
seenin
the
later
chapter.1.5
The
advantagesofusing
aPetri Net
tool
By
applying
the
Petri Net
tools
on acomputerthe
usermay
gain someadvantagest
14]. The first
advantageis
the possibility to
obtainbetter
results.The
computerbased
drawing
systems providethe
user with precision anddrawing
quality.Also,
by
applying the
analysistechniques
offeredby
the
computer,
it is
possibleto
obtain results which couldbe
error-prone orvery
time consuming
if
done
by
manually.The
secondimportant
advantage ofusing
Petri Net
tools
is
the
possibility
to
obtainfaster
results.By
taking
the
functions
offeredby
the
computerbased
drawing
system,
such ascopying the
part ofthe net, moving
part ofthe net,
it
canremarkably
speedup the
drawing
andmodifying
process.If
the tool
provides some automaticadjustments,
such asto
realignthe
arcs whenmoving the
node or erasethe
node,
orto
do
some errorchecking,
the
usercan avoidmaking
errorsthat
wouldlater
have
to
be
corrected.A
third
advantageis
the
possibility to
make aninteractive
presentation ofthe
results.A
computerbased
net simulator makesit
possibleto
demonstrate
the
occurrence sequencesin
a net.Users
cantrace the
behavior
ofthe
designed
netstep
by
step,
and observethe
resultimmediately.
Finally,
computerizedtools may
have
the
advantage ofassisting the
userin
structuring the
processby
whichhe
obtainsthe
results.As
anexample,
instead
ofdrawing
a complicatedbig
netthey
force
the
userto
draw
a smallnet,
andthen
refine some ofthe
nodesin
this net,
by drawing
a new netfor
each ofthem.
This
process resultsin
ahierarchy
of smallnets.2. Previous
Work
2.1
SPECS Project
A
graphicalPetri
Nets
tool
sethas
been
accomplishedin
the
SPECS-Project (SPEcification
ofConcurrent
System)[9],
and was supportedby
someSwiss
companies.This
tool
setis
based
on self-modifiedhigh-level
Petri
Nets
(similar
to the
Predicate/Transition-nets),
extended with an object-orientedparadigm and a
hierarchical
structuring
facility
implemented in
the
Smalltalk
programming
environment on a powerful graphical workstation.Its
purposeis
to
supportthe
design
andprototyping
ofdistributed
systems.The
net editor's userinterface has
been implemented
onthe
basis
ofwindows, pop-up
menus andthe
mouse as apointing
device.
To
alarge
part,
use of
the
editoris
self explanatory.It
allows usersto
describe
the
nethierarchically,
but
only
T-elements
canbe
connectedto subnets;
S-elements
remain unchanged
in
eachlevel
ofabstraction.Every
token
in
the
net carriesa
list
of attributeslike
any
Smalltalk
object.Instead
ofapplying
functions
to
individuals,
messages are sentto
objects.The
statesofthe
objectscanthen
be
modified or
tested.
The
forms
ofthe tokens
canbe defined
by
the
userto
makea simulation more understandable.
Conditions
may
be
specifiedin
which atoken
of particularform
is
to
be
used.This
feature is
muchlike
a coloredtoken
in
aPIC-net.
A
timestamp
mechanism alsocanbe
attachedto
eachtoken
whenassociating time
delays
with places.Such
adelay
meansthat
atoken
remainson
the
placefor
atleast
a given number oftime
unitsbefore it
canbe fired.
Therefore,
SPECS
nets canbe
used astimed
Petri
Nets. The
simulatoris
integrated into
the
net editor.At
any time
during
the
design
process, the
netcan
be
simulated.The
following
syntaxis
checkedby
the tool.
It
guarantees syntacticalcorrectness at
any time
during
the
design
process.-
Variables
areidentifiers.
Tokens
are representedby
the
list
oftheir
attributes.-15--
Predicate
inscriptions
consist of: an optional name
(beginning
with alower
caseletter),
an optionaldelay
ordelay
interval
, andthe initial
marking,
whichis
a(possibly
empty) sequence oftokens
with constant attributes.Connector inscriptions
aredescriptions
of one singletoken.
The
attributes of
the token may
be
variables or constantSmalltalk
objects.The latter
canbe
representedby
any
Smalltalk
program.-
Transition
inscriptions
are
Smalltalk
programs.Variables
appearing
also
in
the
connectorinscriptions
do
nothave
to
be declared.
The
simulator maintains apotentially
firable
transition
set.All
transitions
notin
this
set are notfirable.
The
simulator will pick onetransition
in
the
set randomly.If
the transition
is
notfirable,
the transition
will
be
removedfrom
the
set.If
the
transition
is
firable,
the
transition
is
fired
and all
the transitions that
mightbecome firable
afterthis
firing
willbe
addedinto
the
set.More
details
ofthis
tool
aredescribed in [9].
2.2
PSI
A Petri Net based
simulatorfor
flexible
manufacturing
systems calledPSI
is
developed
on aZ80-based
microcomputer underthe operating
systemCP/M[4].
The
code ofthe
simulatoris
writtenin
PASCAL.
With 64K
bytes
ofmemory the
maximum size ofthe
Petri
netis
150
places,
150
transitions,
50
boolean
variables,
50
integers.
Since it
worksvery
slowly
on an8-bit
microcomputer,
a new versionis
underdevelopment
on16-bit
and32-bit
machines.
This
simulatordoes
not offer a graphicalinterface for
users;
allthe
necessary information
is
acquiredby
using
aninput language. It is based
ontimed Petri
Net
combinedwith a coloredPetri
Net.
Hierarchically
describing
netis
not allowed and nolist
ofattributes canbe
associatedwithtokens,
but
the
newversion willeliminatethese
limitations[12].
16-There
are morePetri Net
tools
available or underdevelopment. More
information
aboutthe tools that
arecurrently
available canbe
found
in "Petri
Net
Tools"[4]
and"Petri Net
Tool
Overview
1986"[15].
-17-2.3 Tool
Overview
The
following
table
givesan overview ofsomeexisting
Petri
Net
tools.
Tool
Net Type
editor
ana
lysis
simu
lation
Computer/OS
DAIMI
hi-level
a/n yes noVAXA/MSPDPl0/tops10
SUN3/UNIX4.2
DEMON
stoch. gr yes yesIBM370/MVS-XAorVM
DESIGN
any
gr no noMacintosh
GALILEO
timed
gr yes yesVAXA/MS
GreatSPN
timed/stoch.
gr yes yesSUN
3
/UNIX
4.2
ISAC-GR.
C/A
gr no noIBM PC/MSDOS
CADMUS/MUNIX
MARS
timed
a/g
no yesIBM360/370 ESER
NECON
PrfT
gr. yes noIBM 4381 /VM-SP
NET
Pr/T
+timed
gr. no yes(micro)
VAXA/MS
NET-LAB
PfT
gr- yes yes1MB
PC/MSDOS HP9836
OVIDE
P/T
a/n yes noIBM/OSA/S-VMS
PN. Mach
PrfT
a/n yes yesIBM
PC/MSDOS
P.
Pote
PfT
gr. no yesICL.PERQ/POS
PROTEAN
PrfT
gr. yes yesVAXA/MS
ROPS
stoch. a/n yes noVAXA/MS
SERPE
PrfT
a/g
yes yesVAXA/MS
+ICLPERQ
SIBUN
timed
a/n no yesany
Simula
systemSPAN
stoch. gr. yes yesSUN2/120
TEBE
safeP/T
a/n yes no(micro)
VAXA/MS
a/n = alphanumerical gr. = graphical
a/g
= mixtureofboth
stoch. = stochastic
Tool
Net Type
edit orana
lysis
simu
lation
Computer/OS
CACAPO
C/E
a/n yes noSimemen
BS
2000,
UNIXA/AX
FUN
stoch.a/g
yes yesVM
370
GACOT
timed
a/g
yes yesDEC-VAX,
UNIXA/MS
GASP
PfT
a/n yes noDEC-VAX,
SUN
GTPN
timed
a/n yes noDEC-VAX-780/750,
BSD 4.2
ITI/OPA
hi-level
a/n no noTYMNET
Engine,
ISIS,TYMCOM-10
PES
PfT
a/n yes noSimemen
7xxx,
BS
2000
PeSys
C/E, PfT,
timed
a/n yes yes
PCS
Cadmus,
9230V
MUNIX
TOPAS-N
PrfT
a/n no yesDEC-VAX,
VMS
SPECS
timed,
PrfT
a/g
yes yesSUN,
Smalltalk
PSI
timed,
colored
a/n no yes
CPM,PC
a/n = alphanumerical gr. = graphical
a/g
= mixture ofboth
stoch. = stochastic
analysis : suchas produce a reduced net of
the
same classes. simulator : such asplaying the token
game onthe
screen.19-2.4
Comparisons between GPNS
and otherPetri Net Tools
There
aremany Petri
Net
tools,
andthey
have
offered variouseditors,
simulators and analytical abilities.
It
is
very
diffuclt
to
compareGPNS
withthe
othertools.
GPNS has
agraphicalinterface,
menudriven
neteditorwithsomevery
basic
editing
functions.
Compared
to those tools
without a graphical neteditor,
GPNS is
easierto
use and more userfriendly.
But,
comparedto those
tools
with afancy
graphical neteditor,
GPNS
seemshas
a poorediting
function
set.It
has
only
a one-screen net editor withouthierarchical
netstructure and
copy
subnetfunction.
However,
the capability
of automaticadjustment of arcs when
moving
orerasing
a place/transition should gainsome credits
for GPNS.
For
the simulator,
GPNS
providesautomatic andinteractive
mode.By
using the
interactive
mode,
the
user can observethe
result ofa specialfiring
sequence.By
using the
automaticmode, the
user canobservethe
result whenapplying the
designed
systemin
the
pratical environment.The outstanding
characteristic ofthe
automatic modeis
that
it
allowsthe
userto
decide
whichtransition
has
ahigher
priority to
be
fired
whenit is
enabledby
specifing the
probability
weight ofthe transition.
Safe-net,
K-bounded
net,
Weighted
net,
andPlace/Transitions
netscanbe
simulatedby
GPNS.
Each
placein
the
net canbe
either safe orbounded
sois
the
wholenet.The
mostexciting
feature
ofGPNS
that
makesit different from
the
other
tools
is
that
it has
autility
which can expandthe
power ofthe
simulatorthe
Auxiliary
Application Program
(AAP). The
user canmodify
the
AAP
function
templates
generatedby
GPNS
to
do
many
kinds
of analysis orsimulationof
the
designed Petri
Net.
3.
Functional Specification
The GPNS is
a software packagefor Petri Net
simulation.It
provides a graphical neteditor,
a simulator and atool,
the
Auxiliary
Application
Program(AAP). The GPNS has
been implemented
onthe
basis
ofa graphicalinterface,
pop-up
menusand with mouse as apointing
device.
It
canbe
usedto
simulatePlace
/ Transition
nets.Depending
onthe
user'sapplication,
the
net canbe
eitherk-bounded,
weighted orboth. The AAP
is
an optionaltool
for
enhancing the analyzing
ability
ofGPNS.
This
sectionis
an overview ofGPNS.
To
get a more clearidea
ofGPNS's functions
andhow
to
useGPNS,
the
usershould referto
the
USER'S
MANUAL in
the
appendix.3.1 Net Editor
The
net editor allowsthe
userto
construct aPetri
Net
onthe
screen.Because
it is
a one-screen neteditor,
the
Petri
Net is limited
to
a small size of at most30
places and30
transitions.
Most
ofthe
time,
the
mouseis
used asthe
input device
to
draw
the
net andissue
the
commands;
Occasionally,
keyboard
willbe
usedto
input
the text
information
requiredby
GPNS.
GPNS
provides sevenediting
modes-Select, Text, Place,
Transition,
Arcs,
Token
andErase,
to
let
the
user construct aPetri
Net
onthe
screen.The
user can changethe
currentediting
modeby
selecting
the
symbol whichrepresents
the
desired
editing
modein
the
panel.Then,
the
user usesthe
mouseto specify the
location
onthe
user area wherethe
function is
to
be
performed.Select
select a graphicicon
to
be
the
currently
activeicon,
sothe
usercanmoveit
orsetits
properties.Text
putapieceoftext
onthe working
area.Place
draw
a place onthe working
area.Transition
draw
atransition
onthe working
area.Arcs
draw
an arcto
connect a place and atransition.
Token
setthe token
count of aplace,
probability
weight of atransition,
or weight of an arc.Erase
delete
a graphicicon from
the working
area.By
switching between
these
sevenediting
modes,
user candraw
aPetri
Net
onthe
screen.Then,
the
user can simulatethe
behavior
ofthe Petri
net.The
userissues
commandsby
selecting
one ofthe
five
menutitles
-FILE, EDIT, EXEC,
OPTION
andEXIT
from
the
menubar
to
get acommand
list
underthe
menutitle.
Then,
the
user canissue
a commandby
highlighting
the
command andclicking the
mousebutton. The
commands under each menutitle
areaslisted.
FILE-
Open
Save
Clear
EDIT
Properties
Move
retrieve an
existing
file.
save
the
networkinto
afile.
clear
the
screen andstarta newsession.set
the
properties of aplace, transition
orarc.
move a place or a
transition to
a newlocation.
EXEC
- Automatic simulatethe
Petri
Net
in
a
free-running
mode.
Interactive simulate
the
Petri Net in
astep
mode.EXIT
Prog
Generate
generatethe
sourde codetemplates
ofthe
AAP.
OPTION-
Log
Speed
Run AAP
generate a
log
file
offirings
during
simulation.K-bounded
setthe token
limit
for
the
places.change
the
speed ofthe
automatic simulation.execute
the
AAP
whilesimulating the
Petri
Net.
exit
from
the
GPNS.
All
commands offeredby
GPNS
canbe
found
onthe
menubar.
A
command"QUIT"
which
is
usedto stop the
simulationonly
appears onthe
menubar
during
the
simulation session.3.2
Simulator
The
simulatoris integrated into
the
net editor.At
any time
during
the
design
process, the
net canbe
simulated.The
simulation canbe
executedin
two
modes:interactive
andautomatic.In
the
interactive
mode, the
user cangothrough
the
simulationstep
by
step
anddecide
which enabledtransition
shouldbe fired
in
the
currentmarking.
The
usercanexamine a specialfiring
sequence oftransitions
in
this
mode.
When simulating in
the
automaticmode,
GPNS
randomly
picks a enabledtransition
form
the
currentmarking
andfires
it,
and continuesin
this
way
untilit
reaches adeadlock
or stoppedby
the
user.In the
automaticmode,
the
user can choosefast
speedto
let
the
simulator runquickly,
orthe
slowspeed
to
allow easier observ action ofthe
process.3.3
Auxiliary
Application Program
In
orderto
makethe
GPNS
morepowerful,
GPNS has
an additionaltool
calledAuxiliary
Application Program (AAP).
By
issuing
the
Prog
Generate
command,
the
GPNS
will generate programtemplates
for
userto
modify.Each function in
the
AAP,
writtenby
user,
canbe
attachedto
the
corresponding transition
onthe
Petri
Net.
After modifying
the
AAP,
the
user canlink AAP
withthe
GPNS
and simulatethe
Petri
Net
to
causeAAP
functions
to
be
executed whenthe corresponding
transitions in
the
Petri
Net
are
fired.
The AAP
is
an extensionofthe
GPNS. The
user can useAAP for
many
application
purposes,
such as:debugging
the
Petri
Net,
simulating
a real system'swork,
andanalyzing the
Petri
Net.
Each
AAP function
must returna valueto
GPNS
afterit
was executed.A
non-zero return value will causeGPNS
to
hold
the
simulation anddisplay
a messagebox. The
user canthen
decide
to
continuethe
simulationorstop
the
simulationto
checkthe
program.
4.
PROGRAM
DESCRIPTION
4.1
Overview
The
program ofthis
projectis
madeup
by
five
components-Driver,
Net-editor,
Simulator,
Program-generator
and aShell
program.The
Driver
deals
withthe
graphics primitivesthat
were usedin
the
Net-editor. The
Net-editor
sets
up the
userinterface
(desktop)
onthe
screen,
offersfunctions
that
allow usersto
draw
aPetri
Net
onthe screen,
andhandles
allthe
data
structures ofthe
graphics net.The
simulatorderives
the information
it
neededfrom
the
graphicsnet
layout description. The
simulatorthen
simulatesthe
behavior
ofthe
Petri Net
andinteracts
withthe Net-editor to
display
the
results onthe
screen.
The
Program-generator
createsAuxiliary
Application Programs
(AAP)
templates that
users canmodify
andlink
withthe
GPNS.
After
the
AAP
waslinked
withGPNS,
eachfunction
in
the
AAP
is
attachedto
acorresponding transition
in
the
Petri
Net.
While
simulating,
the
firing
of atransition
will causethe corresponding
AAP function
to
be
executed.The
Project
includes
sixheader
files,
14
programfiles
with162
procedures.Those
header
files
are :consdef.h,
structdef.h,
iconfont.h,
msicon.h,
setup.h,
and system.h.The 14
programfiles
are:main.c,
graphics.c, sgp.c, maputil.c, rectutil.c,
menu.c,
objects.c,
action.c,
segment.c,
sim.c,
form.c,
generator.c,
apply
.c,andapplydo.c.-25-4.2.
The System Organization Chart
USER
Program
Generator
SIMULATOR
Auxiliary
Application
Program
1
Petri
Net
Simulator
System
Organizational Chart
4.3.
Data Structure Format
ofDriver
andNet-editor
unsignedshort
*map;
int
shortx,
short
y;
int
pixelx,
pixel y:
The
following
aredescriptions
of someimportant data
structureformats
that
areusedin
the
project.structure
type
MAP_T
/*
point
to
abitmap
memory
*/
/*
the
#
of unsignedshort of width*/
/*
the
#
of unsignedshort of
height
*/
/*
pixel
#
of width*/
/*
pixel
#
ofheigh */
map
is
a pointerthat
pointsto the
addressofthe
first
short of anarbitrary
sizearray
of shorts.This
array
is
usedto
savethe
pattern ofarectangularbitmap.
Short
x and shorty
specify the
rectangle's width andheight
in
shorts.Pixel
xand pixely
specify the
rectangle's widthandheight
in
pixels.structure
type
RECT_T
left,
/*the
xcoordinatorof upper-leftcorner*/
up,
/*the y
coordinator of upper-leftcorner*/
right,
/*the
xcoordinatorof right-bottom corner*/
bottom;
/*the y
coordinatorofright-bottom corner*/
int
This data
structure specifies a rectangle regionby
two
pointsthe
upper-left corner and
the
right-bottom corner ofthe
rectangle.It is
usedto
specify the
size of rectangularbitmaps
andthe
exact position andthe
boundary
box
oficons.
/*
specify
the
icon
type
*/
/*
the
identify
#
ofentry
*/
/*
token
#
/ probability
wt./
wt.*/
/*
capacity
ofthe
place*/
/*
text
string
or name ofthe
entry
*/
/*
the
input icon
ofthe
arc*/
/*the
outputicon
ofthe
arc*/
/*the
boundry
box
ofthe
icon */
ture type
SEG_
T
int
type;
int
id;
int
token;
int
cap;
char
*text;
struct
SEG_P
*from,
*to;
RECT_T
*bbox;
27-RECT_T
*pos;
/*the
exactpositionofthe
icon
*/
struct
SEG_P
*next;
/*pointerto
nextentry
*/
Type
indicates
whattype
ofthe
icon
is.
It
couldbe:
PLACE, TRANS,
ARCS
and
TEXT.
Id
is
used afterthe
matrixinformation
is
established.It is
usedby
place and
transition to
indicate
the
positionin
the in
andout matrixes.Token
is
used astoken
countif
the type
is
PLACE,
probability
weightif
the type
is
TRANS
and weightif
the type
is
ARCS,
It
is
not usedin
TEXT type.
Cap
is
the
capacity
ofthe
placetype.
It
is
not usedin
the
othertype.
Text
usedto
storethe
internal
name ofthe
PLACE
andTRANS
and usedto
storethe text string
for
the
TEXT
type.
From
andto
areonly
usedby
the
ARCS
type to
indicate
the
input
icon
and outputicon.
Bbox
is
the
boundary
box
ofthe
icon. Pos
specifiesthe
exactlocation
ofthe
icon
onthe working
area.Next
is
the
pointerto
the
nextstructure.
4.4.
The Flow
Chart
ofthe
Shell
Program
No
parametergptns
executable
file
If
one paremeter-file
One
parameterEND
Find
///e.rnak
file
compile
fi/e.cand
file
do.
cfiles
Link
with
gptn.o
file
Shell
Program's
Flow
Chart
29-4.5.
The
Algorithm
ofthe
Main Function
while
(not
done)
{
read mouse
location;
if (located in
panel)
set
the
selecting
editing
mode as currentediting
mode;
else
if
(located
in
userworking
area)
taking
the
actionaccording
the
currentediting
mode;
else
if (located in
menubar)
display
the corresponding menu;
get
the
command;
if ((command
= =EXIT)
&&
confirmed)done=
true;
else
carry
outthe
command;
}
30-4.6.
The Graphical Driver
The
core ofthe
graphicaldriver
usesthe
conceptsfound
in
the
Simple
Graphical
Package(SGP)[6].
It
allowsthe
userto
display
pictures oftwo-dimensional
objects andtransmits
input
actionsfrom
the
userto
the
application program
in
orderto
establishuser-computerinteraction.
The
SGP is divided
into
sixdistinct
classes :1.
Graphic
output primitivesthe
functions
that
resultin
CPU
to
display
on
the
viewsurface.2.
Attribute-setting
the
functions
that
determine
the
line
style ofsubsequent
lines
andthe
color of all subsequent output primitives.3.
Segment
controlthe
functions
that
group
logically
related outputprimitives
into
segments(the
units of selective modification ofthe
display
program).Functions
are availableto
delete,
rename,
or changethe visibility
ofsegments,
andto translate
the
image
onthe
screenwhich was produced
by
a segment.4.
Viewing
operation -the two
functions
that together specify to the
package what part of
the
world coordinate systemto
display
on whatportionof
the
screen.5. Input
-the
functions
that
control user
interaction
withthe
applicationprogram.
6.
Control
-the INITIALIZE
function
helps
the
packageinitialize its
owntables
andthe
graphics status and modeflags
/
registers;
it
alsoinitializes
the
default
valuesfor
the
window(the
unitsquare)
andthe
viewport
(the
entire screen).The TERMINATE function
clearsthe
screenand closes out
the
graphicsdevice
to
provideandorderly
exit.The details
ofthe
SGP
canbe
found
in
Fundamentals
ofInteractive Computer
Graphics[6], This
projectonly
developed
a one screen neteditor,
sothe
fourth
class
is
omitted.4.7.
The
User
Interface
The
Data
Structure
ofthe
User Interface
The
userinterface is
a window-orinted and menu-driven styledesign.
It
includes:
adesktop,
menus,
forms,
messages and apointing
device (mouse).
The
desktop
is
abitmap
window constitutedby
a menubar,
apanel,
an userworking
areaandfour
messagelines.
The
desktop
is
madeup
by
three memory
bitmaps,
onefor
the
menubar,
one
for
the
panel and onefor
the
userworking
area.Those
three memory
bitmaps
are constitutedby
objects(icons)
that
are refreshed(mapped)
to
the
viewing
surface(screen). Those
objects are createdby
using the
functions
ofSGP.
The
menus,
formes
and messages are utilitiesthat
offeredby
UNIX
PC.
The
details
ofhow
to
usethese tools
canbe found
in
UNIX USERS'
MANUAL
-menu(3T),
form(3T)
andMessages(3T)
-32-menu.c
form.c
segment.c
main.c
action. c
rectutil.c
objects.c
maputil.c sgp.c
Hierarchical
Process
Diagram
0
graphics.c
4.8
Hierarchical Process Diagram
Main
create
desktop
~2
take action
~9
initialize
X
winit
I
wcreate?
read
seg
read mouseloc
in
rectmenu select
T
panel select
highlight
msgsX
keypad
newviewX
curs off
terminate
close wexit
ioctl
The bold
rectanglerepresents ahierarchical function
call.The
number
below
the
function
nameis
the
diagram
numberwhereyoucan
find
the
details
ofthe
function.
This
type
ofthe
rectanglerepresentsanelementary
function
call.Hierarchical
Process
Diagram 1
select
font
init
map
select
map
map
to crtframe
rectdel
map
text
created
esktop
I
set menubar set userarea
hline
draw
panelset panel
Hierarchical
Process Diagram
2
set
icon
set token
~"3
set trans
1
set place
3
set place
init
map
selectmap
setfill
set color paintmap
1
settrans
init
map
selectmap
frame
rectfill
rectclear_map
set
token
init
map selectmap
paintmap
menu select
I
I
~F
file_menu
4edit_menu
4
exec_menu
4
T
option
1_menu
option2_menudisp
menumessage
Hierarchical
Process Diagram
3
|
file
menuI
disp
menu saveform
"6
read
seg
message clear workopen
form
empty
screenwrite_all_seg
7
select
map
new_all_seg
7
X
|
edit menu|
I
I
message erase icon
in
bound
set rectdraw
texthilit
icon
"6"
I
I
msgsX
draw
relatedTi
offset rect read mouse erase related
Ti
X
I
X
T
prop
form
6
clear work
disp
menudraw
allseg
7
draw
icon
exec menu
i
I
msgs
hilit
icon
"6
manualsim8
autosim8
I
l
save
form
write allseg
7
"~ translate8
prog
generator8
Hierarchical
Process Diagram
4
draw
icon
X
draw
placedraw
transX
draw
arcI
draw
textX
drasw
tokenI
draw
ratioI
draw
weightdraw
arcdraw
line
draw
arrowX
init
map
I
select
map
X
move abs
2
I
line
abs2
X
map
to crtI
get angle rotate
shift
draw
line
del
map
erase icon
erase place erase trans erase arc erase text
draw
weightHierarchical
Process Diagram
5
38-hilit
icon
I
hilit
placehilit
transhilit
archilit
textinit
map
map
to crtdel
map
open
form
saveform
bound
form
textform
prop
form
1
I
disp
form
trimming
form
Hierarchical
Process Diagram
6
add
seg
inst
seg
mst rect setbbox
addentity
sel
seg
I
selentity
I
loc
in
rect nearby
write all
seg
new allseg
del
seg
draw
allseg
write
seg
newseg
del
entity
draw
seg
draw
icon
Hierarchical
Process Diagram
7
prog
generatorpheader pdecl
psetup
pfheadpbody
ptail pfunc1
pmake
manual select
H
hilit
icon
fire
X
de
hilit
translate
find
relloc
in
rectmanualsim autosim
disp
quitH
translate
T
dofunction*X
set up*
X
del
list
erase quitfind
enablehilit
icon
random select
find
enableinitialize*
message
terminate*
add active enabled
dummy
function
in AAP template
Hierarchical
Process
Diagram 8
-41-take
actionrrZTTTT
'SELECT1
H-EXt"1 H^LACe"1
^RANS1
ARCS
irrxzri
'TOKEN1 ERASE1
II
II
II
II
II
select1 1
TEXT
sel
seg
u pdatehilit
addseg
H^l"
"ce"1
1
in
bound
message addseg
Tr"
l__
"ns1
1
in
bound
message addseg
A
casein
take
actionfunction
Hierarchical
Process
Diagram 9
n^Rcs"1
sel
seg
hilit
icon
message read mouse msgsI
drawn
I
connecting
I
get angle
I
add
seg
overlap
get_c_point get_r_point
X
getcode
inter
x1
inter
yoverlap
erase
icon
|
split1
1
1
1
get angle get_c_point get_r_point rotate shift
1
1
set rect set
bbox
draw
icon
Hierarchical
Process Diagram
10
-43-^token"
I
I
hilit
icon
"6
message sel
seg
T
erase token
draw
tokenX
erase ratioI
draw
ratio erase iconX
draw
icon
erase_weightIrase"1
X
draw_weight
I
I
erase icon
del
seg
T
delete
related clear workdel
seg
erase arcdraw_all_seg
7
draw
relatedX
connecting
X
set rect
X
setbbox
I
overlap
Hierarchical
Process Diagram
11
erase related
erase arc
44-The
structuresusedto
representthe
layout
ofthe
graphics net arefour
linked lists (segment).
They
have
the
samedata
structureformat
-SEG
T.
The
linked list
"phead"contains
the
graphical netdescriptions
of allthe
places
in
the
Petri Net. The linked list
"thead"contains
the
graphical netdescriptions
of allthe
transitions in
the
Petri Net. The
"ahead" containsthe
descriptions
ofarcsandthe
"chead"containsthe
descriptions
oftext.
If
a graphicssymbol(icon)
wasdrawn
onthe working area,
anentity
ofthe
icon is
addedinto
one ofthe
linked lists
according to the
icon's
type.
If
anicon
is
deleted,
the corresponding entity
in
the
linked
list is
also removed.If
the
icon
is
movedto
a newlocation
onthe working
area,
the
contents ofthe
corresponding entity
is
updated.When
the
Save
commandis
issued,
the
contents ofthe
four
linked lists
is
writtento
afile
with a ".ptn" extension.When
opening
anexisting
".ptn"
file,
the
content ofthe
file is
retrievedto
form four
linked lists
that
willbe
manipulatedin
the
GPNS
session.The
following
are some scenarios ofhow GPNS
doing
its job.
Adding
a placeStarting
Conditions
:The
currentediting
modeis
PLACE
mode.The
cursoris
shapedlike
acircle when
located
in
the
userworking
area.Event
:The
user clicksthe
mousebutton in
the
userworking
area.Response
:The
main()
calls read mouseOto
getthe
current mouselocation. It
tests
that
location
andfinds
outit
is
in
the
userworking
area,
soit
callstake
action().The
take
actionO
tests the editing
mode andfind it is
PLACE
mode.Take
actionO
callsin
boundedO
to
checkif
the
circleis
totally
inside
the
user
working
area.Assume
the
circleis
totally
inside
the the
userworking
area, then take
action calls add seg().Add
segO
creates a newinstance
of aSEG
T
structure.It fills
in
the
structureas
follows:
id
=the
sequencenumber ofthe
place,
token
default
token
count of0,
cap
=default
capacity
of-1,text
=default
place name"placeioP,
form
=to
=NULL
(not
usedby
places,
only
by
arcs),
pos =
boundary
rectangle ofthe
placeicon
based
onthe
current position.bbox
= a rectangle2
pixelslarger in
alldimensions
than the
newly-created rectangle
(used for
detecting
selection ofthis
icon).
Then
add seg() addsthe
newly-created structureto the plist, the
linked
list
of places.Then
addsegO
refreshesthe screen,
causing the
newplaceto
appear.