PetriNet.hs 1.26 KB
Newer Older
Philipp Meyer's avatar
Philipp Meyer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}

module PetriNet
    (PetriNet,name,places,transitions,
     makePetriNet)
where

data PetriNet = PetriNet {
        name :: String,
        places :: [String],
        transitions :: [String],
        arcs :: [(String,String,Integer)],
        initial :: [(String,Integer)]
}

instance Show PetriNet where
        show net = "Petri net " ++ name 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)) ++
                   "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
makePetriNet name places transitions arcs initial =
        PetriNet { name=name, places=places, transitions=transitions,
                   arcs=arcs, initial=initial }