summaryrefslogtreecommitdiff
path: root/Assignment2/src/DTMC.icl
diff options
context:
space:
mode:
authorCamil Staps2018-07-05 20:14:27 +0200
committerCamil Staps2018-07-05 20:14:27 +0200
commit8a0e136dd211139929ba0b9db67c6fcf3142f3c6 (patch)
treee3fefd6190aae607feb28fa861449cafb011d011 /Assignment2/src/DTMC.icl
parentWhoops (diff)
Add printDTMC
Diffstat (limited to 'Assignment2/src/DTMC.icl')
-rw-r--r--Assignment2/src/DTMC.icl32
1 files changed, 31 insertions, 1 deletions
diff --git a/Assignment2/src/DTMC.icl b/Assignment2/src/DTMC.icl
index 9f1e938..9d1ec00 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
@@ -186,4 +214,6 @@ where
Start w
# (dtmc,w) = parseDTMC "die.drn" w
-= [(s.state_id, 'M'.toList s.transitions, '\n') \\ Just s <-: (stateElimination dtmc).states]
+# dtmc = addVars dtmc
+# dtmc = stateElimination dtmc
+= printDTMC dtmc