Commit 7a40b4fd authored by Philipp Meyer's avatar Philipp Meyer

Using map to store initial marking in Petri net

parent fa4712f6
......@@ -13,9 +13,12 @@ data PetriNet = PetriNet {
places :: [String],
transitions :: [String],
adjacency :: M.Map String ([(String,Integer)], [(String,Integer)]),
initial :: [(String,Integer)]
initMap :: M.Map String Integer
}
initial :: PetriNet -> String -> Integer
initial net p = M.findWithDefault 0 p (initMap net)
context :: PetriNet -> String -> ([(String, Integer)], [(String, Integer)])
context net x = M.findWithDefault ([],[]) x (adjacency net)
......@@ -46,14 +49,15 @@ instance Show PetriNet where
"Initial: " ++ unwords
(map (\(n,i) -> n ++
(if i /= 1 then "[" ++ show i ++ "]" else []))
(initial net))
(M.toList (initMap net)))
makePetriNet :: String -> [String] -> [String] ->
[(String, String, Integer)] -> [(String, Integer)] -> PetriNet
makePetriNet name places transitions arcs initial =
let adjacency = foldl buildMap M.empty arcs
initMap = M.fromList initial
in PetriNet { name=name, places=places, transitions=transitions,
adjacency=adjacency, initial=initial }
adjacency=adjacency, initMap=initMap }
where
buildMap m (l,r,w) =
let m' = M.insertWith addArc l ([],[(r,w)]) m
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment