summaryrefslogtreecommitdiff
path: root/Assignment2
diff options
context:
space:
mode:
authorErin van der Veen2018-07-05 20:16:35 +0200
committerErin van der Veen2018-07-05 20:16:35 +0200
commit4245e64cd27a4c228f5500dbd9fb6bd8dd743f74 (patch)
tree0032f303f6867f62be8b3ba7580c124e6d39d530 /Assignment2
parentMake variables start with a v (diff)
parentAdd printDTMC (diff)
Merge branch 'master' of gitlab.science.ru.nl:eveen/Model-Checking
Diffstat (limited to 'Assignment2')
-rw-r--r--Assignment2/src/DTMC.dcl2
-rw-r--r--Assignment2/src/DTMC.icl31
2 files changed, 32 insertions, 1 deletions
diff --git a/Assignment2/src/DTMC.dcl b/Assignment2/src/DTMC.dcl
index 5d948fb..26cbe19 100644
--- a/Assignment2/src/DTMC.dcl
+++ b/Assignment2/src/DTMC.dcl
@@ -15,5 +15,7 @@ from System.FilePath import :: FilePath
, init :: !Bool
}
+stateElimination :: !*DTMC -> *DTMC
parseDTMC :: !FilePath !*World -> *(!*DTMC, !*World)
+printDTMC :: !*DTMC -> *(!String, !*DTMC)
addVars :: *DTMC -> *DTMC
diff --git a/Assignment2/src/DTMC.icl b/Assignment2/src/DTMC.icl
index 2d7a68f..6c81510 100644
--- a/Assignment2/src/DTMC.icl
+++ b/Assignment2/src/DTMC.icl
@@ -164,6 +164,34 @@ where
| isEmpty current = groupLines head [line] lines
| otherwise = [reverse current:groupLines head [line] lines]
+printDTMC :: !*DTMC -> *(!String, !*DTMC)
+printDTMC dtmc=:{nr_states,states}
+# (state_strings,states) = printStates 0 states
+# s = join "\n"
+ [ "@type: DTMC"
+ , "@parameters"
+ , "@reward_models"
+ , "@nr_states"
+ , toString nr_states
+ , "@model"
+ : state_strings
+ ]
+= (s, {dtmc & states=states})
+where
+ printStates :: !Int !*{Maybe State} -> *(![String], !*{Maybe State})
+ printStates i ss
+ | i == nr_states = ([], ss)
+ # (s,ss) = ss![i]
+ | isNothing s = printStates (i+1) ss
+ # s = fromJust s
+ # repr =
+ [ "state " <+ s.state_id
+ , "\taction 0"
+ : ["\t\t" <+ to <+ " : " <+ prob \\ (to,prob) <- 'M'.toList s.transitions]
+ ]
+ # (reprs,ss) = printStates (i+1) ss
+ = (repr ++ reprs,ss)
+
addVars :: *DTMC -> *DTMC
addVars dtmc = {DTMC | nr_states = dtmc.nr_states, states = addVarsS 0 dtmc.nr_states dtmc.states}
where
@@ -187,4 +215,5 @@ where
Start w
# (dtmc,w) = parseDTMC "die.drn" w
# dtmc = addVars dtmc
-= [(s.state_id, 'M'.toList s.transitions, '\n') \\ Just s <-: (stateElimination dtmc).states]
+# dtmc = stateElimination dtmc
+= printDTMC dtmc