Main.hs 3.59 KB
Newer Older
Stefan Jaax's avatar
Stefan Jaax 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import System.Environment (getArgs)
import PopulationProtocol
import ProtocolOutput

usageAction :: IO ()
usageAction = do 
    putStrLn "Usage: "
    putStrLn "'./pp2petrinet majorityPP' converts Majority PP to PNet."
    putStrLn "'./pp2petrinet broadCastPP' converts BroadCast PP to PNet."
    putStrLn "'./pp2petrinet thresholdPP l c' converts threshold PP to PNet, where l and c are positive integers."
    putStrLn "'./pp2petrinet moduloPP m c' converts Modulo PP to PNet, where m, c are positive integers."
    putStrLn "'./pp2petrinet oldThresholdPP l c' converts Modulo PP to PNet, where l, c are positive integers."
    putStrLn "'./pp2petrinet flockOfBirdsPP c' converts FlockOfBirds PP to PNet, where c is a positive integer."
    putStrLn "'./pp2petrinet newBirdsPP c' converts NewBirds PP to PNet, where c is a positive integer."
    putStrLn "'./pp2petrinet verifiableFlockOfBirdsPP c' converts VerifiableFlockOfBirds PP to PNet, where c is a positive integer."
    putStrLn "'./pp2petrinet fastMajorityPP m d' converts FastMajority PP to PNet, where m, d must be odd and positive integers."
    putStrLn "'./pp2petrinet layeredProtocol m' converts Protocol with m >= 1 termination layers to PNet."


majorityAction :: IO ()
majorityAction = putStr $ protocolToPetriNet createMajorityProtocol "Majority Protocol"

broadCastAction :: IO ()
broadCastAction = putStr $ protocolToPetriNet createBroadcastProtocol "BroadCast Protocol"

simpleAction :: IO ()
simpleAction = putStr $ protocolToPetriNet simpleProtocol "Simple Protocol"


newBirdsAction :: [String] -> IO ()
newBirdsAction [x] = let pp = createNewBirdsProtocol (read x) in
     putStr $ protocolToPetriNet  pp ("New birds protocol with c = " ++ x)


flockOfBirdsAction :: [String] -> IO ()
flockOfBirdsAction [x] = let pp = createFlockOfBirdsProtocol (read x) in
     putStr $ protocolToPetriNet  pp ("Flock of birds protocol with c = " ++ x)

verifiableFlockOfBirdsAction :: [String] -> IO ()
verifiableFlockOfBirdsAction [x] = let pp = createVerifiableFlockOfBirdsProtocol (read x) in
     putStr $ protocolToPetriNet  pp ("Verifiable flock of birds protocol with c = " ++ x)

oldThresholdAction :: [String] -> IO ()
oldThresholdAction [x, y] = let  pp = createOldThresholdProtocol (read x) (read y) in
    putStr $ protocolToPetriNet  pp ("Old Threshold Protocol with l = " ++ x ++ " and c = " ++ y)
oldThresholdAction _ = usageAction


thresholdAction :: [String] -> IO ()
thresholdAction [x, y] = let (Just pp) = createThresholdProtocol (read x) (read y) in
    putStr $ protocolToPetriNet  pp ("Threshold Protocol with l = " ++ x ++ " and c = " ++ y)
thresholdAction _ = usageAction


moduloAction :: [String] -> IO ()
moduloAction [x, y] = let pp = createModuloProtocol (read x) (read y) in
    putStr $ protocolToPetriNet  pp ("Modulo Protocol with m = " ++ x ++ " and c = " ++ y)
moduloAction _ = usageAction


layeredProtocolAction :: [String] -> IO ()
layeredProtocolAction [m] = let pp = createMLayerProtocol (read m) in
    putStr $ protocolToPetriNet pp ("Layered Protocol with m = " ++ m ++ " layers.")

main = do
    args <- getArgs
    case args of
        ("majorityPP":_) -> majorityAction
        ("broadCastPP":_) -> broadCastAction
        ("thresholdPP":as) -> thresholdAction as
        ("oldThresholdPP":as) -> oldThresholdAction as
        ("moduloPP":as) -> moduloAction as
        ("flockOfBirdsPP":as) -> flockOfBirdsAction as
        ("newBirdsPP":as) -> newBirdsAction as
        ("verifiableFlockOfBirdsPP":as) -> verifiableFlockOfBirdsAction as
        ("simplePP":_) -> simpleAction
        ("layeredProtocol":as) -> layeredProtocolAction as
        _ -> usageAction