diff options
author | Camil Staps | 2018-07-05 20:14:27 +0200 |
---|---|---|
committer | Camil Staps | 2018-07-05 20:14:27 +0200 |
commit | 8a0e136dd211139929ba0b9db67c6fcf3142f3c6 (patch) | |
tree | e3fefd6190aae607feb28fa861449cafb011d011 /Assignment2 | |
parent | Whoops (diff) |
Add printDTMC
Diffstat (limited to 'Assignment2')
-rw-r--r-- | Assignment2/src/DTMC.dcl | 2 | ||||
-rw-r--r-- | Assignment2/src/DTMC.icl | 32 |
2 files changed, 33 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 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 |