Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
i7
peregrine
Commits
b113299f
Commit
b113299f
authored
May 06, 2014
by
Philipp Meyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using adjacency lists for representing Petri nets
parent
a4645dde
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
13 deletions
+41
-13
slapnet.cabal
slapnet.cabal
+1
-1
src/Main.hs
src/Main.hs
+1
-1
src/PetriNet.hs
src/PetriNet.hs
+39
-11
No files found.
slapnet.cabal
View file @
b113299f
...
...
@@ -23,6 +23,6 @@ executable slapnet
PetriNet
Parser
-- other-extensions:
build-depends: base >=4.6 && <4.7, sbv, parsec
build-depends: base >=4.6 && <4.7, sbv, parsec
, containers
hs-source-dirs: src
default-language: Haskell2010
src/Main.hs
View file @
b113299f
...
...
@@ -16,7 +16,7 @@ main = do
putStrLn
"Safety and Liveness Analysis of Petri Nets with SMT solvers"
putStrLn
$
"Reading
\"
"
++
file
++
"
\"
"
(
net
,
properties
)
<-
parseFile
file
putStrLn
$
"Analyzing "
++
show
net
putStrLn
$
"Analyzing "
++
show
Name
net
mapM_
(
\
p
->
do
putStrLn
$
"Checking "
++
show
p
putStrLn
$
show
$
checkProperty
net
p
...
...
src/PetriNet.hs
View file @
b113299f
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
module
PetriNet
(
PetriNet
,
name
,
places
,
transitions
,
(
PetriNet
,
showName
,
places
,
transitions
,
initial
,
pre
,
lpre
,
post
,
lpost
,
makePetriNet
)
where
import
qualified
Data.Map
as
M
data
PetriNet
=
PetriNet
{
name
::
String
,
places
::
[
String
],
transitions
::
[
String
],
a
rcs
::
[(
String
,
String
,
Integer
)],
a
djacency
::
M
.
Map
String
([(
String
,
Integer
)],
[(
String
,
Integer
)]
)
,
initial
::
[(
String
,
Integer
)]
}
context
::
PetriNet
->
String
->
([(
String
,
Integer
)],
[(
String
,
Integer
)])
context
net
x
=
M
.
findWithDefault
(
[]
,
[]
)
x
(
adjacency
net
)
pre
::
PetriNet
->
String
->
[
String
]
pre
net
=
map
fst
.
fst
.
context
net
lpre
::
PetriNet
->
String
->
[(
String
,
Integer
)]
lpre
net
=
fst
.
context
net
post
::
PetriNet
->
String
->
[
String
]
post
net
=
map
fst
.
snd
.
context
net
lpost
::
PetriNet
->
String
->
[(
String
,
Integer
)]
lpost
net
=
snd
.
context
net
showName
::
PetriNet
->
String
showName
net
=
"Petri net"
++
(
if
null
(
name
net
)
then
""
else
" "
++
show
(
name
net
))
instance
Show
PetriNet
where
show
net
=
"Petri net"
++
(
if
null
(
name
net
)
then
""
else
" "
++
show
(
name
net
))
++
show
net
=
showName
net
++
"
\n
Places: "
++
unwords
(
places
net
)
++
"
\n
Transitions: "
++
unwords
(
transitions
net
)
++
"
\n
Arcs:
\n
"
++
unlines
(
map
(
\
(
l
,
r
,
w
)
->
l
++
" ->"
++
(
if
w
/=
1
then
"["
++
show
w
++
"]"
else
[]
)
++
" "
++
r
)
(
arcs
net
))
++
(
map
(
\
(
s
,(
l
,
r
))
->
show
l
++
" -> "
++
s
++
" -> "
++
show
r
)
(
M
.
toList
(
adjacency
net
)))
++
"Initial: "
++
unwords
(
map
(
\
(
n
,
i
)
->
n
++
(
if
i
/=
1
then
"["
++
show
i
++
"]"
else
[]
))
(
initial
net
))
makePetriNet
::
String
->
[
String
]
->
[
String
]
->
[(
String
,
String
,
Integer
)]
->
[(
String
,
Integer
)]
->
PetriNet
[(
String
,
String
,
Integer
)]
->
[(
String
,
Integer
)]
->
PetriNet
makePetriNet
name
places
transitions
arcs
initial
=
PetriNet
{
name
=
name
,
places
=
places
,
transitions
=
transitions
,
arcs
=
arcs
,
initial
=
initial
}
let
adjacency
=
foldl
buildMap
M
.
empty
arcs
in
PetriNet
{
name
=
name
,
places
=
places
,
transitions
=
transitions
,
adjacency
=
adjacency
,
initial
=
initial
}
where
buildMap
m
(
l
,
r
,
w
)
=
let
m'
=
M
.
insertWith
addArc
l
(
[]
,[(
r
,
w
)])
m
m''
=
M
.
insertWith
addArc
r
([(
l
,
w
)],
[]
)
m'
in
m''
addArc
(
lNew
,
rNew
)
(
lOld
,
rOld
)
=
(
lNew
++
lOld
,
rNew
++
rOld
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment