private static void ExportCid(NestedMarkovDecisionProcess nmdp, TextWriter sb, string fromNode, long currentCid) { NestedMarkovDecisionProcess.ContinuationGraphElement cge = nmdp.GetContinuationGraphElement(currentCid); if (cge.IsChoiceTypeUnsplitOrFinal) { var cgl = nmdp.GetContinuationGraphLeaf(currentCid); sb.WriteLine($" {fromNode} -> {cgl.ToState} [label=\"{Probability.PrettyPrint(cgl.Probability)}\"];"); } else if (cge.IsChoiceTypeDeterministic) { // only forward node (no recursion) var cgi = nmdp.GetContinuationGraphInnerNode(currentCid); var toNode = $"cid{cgi.ToCid}"; sb.WriteLine($" {fromNode}->{toNode} [ style =\"dashed\"];"); } else { var cgi = nmdp.GetContinuationGraphInnerNode(currentCid); var arrowhead = "normal"; if (cge.IsChoiceTypeProbabilitstic) { arrowhead = "onormal"; } for (var i = cgi.FromCid; i <= cgi.ToCid; i++) { var toNode = $"cid{i}"; sb.WriteLine($" {toNode} [ shape=point,width=0.1,height=0.1,label=\"\" ];"); sb.WriteLine($" {fromNode}->{toNode} [ arrowhead =\"{arrowhead}\"];"); ExportCid(nmdp, sb, toNode, i); } } }
public UnderlyingDigraph(NestedMarkovDecisionProcess mdp) { //Assumption "every node is reachable" is fulfilled due to the construction BaseGraph = new BidirectionalGraph(); var currentState = 0; Action <ContinuationGraphElement> addTargetState = cge => { if (cge.IsChoiceTypeUnsplitOrFinal) { var cgl = cge.AsLeaf; if (cgl.Probability > 0.0) { BaseGraph.AddVerticesAndEdge(new Edge(currentState, cgl.ToState)); } } }; for (currentState = 0; currentState < mdp.States; currentState++) { var parentCid = mdp.GetRootContinuationGraphLocationOfState(currentState); var treeTraverser = mdp.GetTreeTraverser(parentCid); treeTraverser.ApplyActionWithStackBasedAlgorithm(addTargetState); } }
public LtmdpToNmdp(LabeledTransitionMarkovDecisionProcess ltmdp) { var stopwatch = new Stopwatch(); stopwatch.Start(); Console.Out.WriteLine("Starting to convert labeled transition Markov Decision Process to Nested Markov Decision Process"); Console.Out.WriteLine($"Ltmdp: States {ltmdp.SourceStates.Count}, TransitionTargets {ltmdp.TransitionTargets}, ContinuationGraphSize {ltmdp.ContinuationGraphSize}"); _ltmdp = ltmdp; CreateStates(); var modelCapacity = new ModelCapacityByModelSize(MdpStates, ltmdp.ContinuationGraphSize * 8L); NestedMarkovDecisionProcess = new NestedMarkovDecisionProcess(modelCapacity); NestedMarkovDecisionProcess.StateFormulaLabels = ltmdp.StateFormulaLabels; SetStateLabeling(); ConvertInitialStates(); ConvertTransitions(); stopwatch.Stop(); _ltmdp = null; Console.Out.WriteLine($"Completed transformation in {stopwatch.Elapsed}"); Console.Out.WriteLine($"Nmdp: States {NestedMarkovDecisionProcess.States}, ContinuationGraphSize {NestedMarkovDecisionProcess.ContinuationGraphSize}"); }
public static void ExportToGv(this NestedMarkovDecisionProcess nmdp, TextWriter sb, bool showRootCids = false) { sb.WriteLine("digraph S {"); //sb.WriteLine("size = \"8,5\""); sb.WriteLine("node [shape=box];"); var initialStateName = "initialState"; sb.WriteLine($" {initialStateName} [shape=point,width=0.0,height=0.0,label=\"\"]);"); var initialCid = nmdp.GetRootContinuationGraphLocationOfInitialState(); ExportCid(nmdp, sb, initialStateName, initialCid); for (var state = 0; state < nmdp.States; state++) { sb.Write($" {state} [label=\"{state}\\n("); for (int i = 0; i < nmdp.StateFormulaLabels.Length; i++) { if (i > 0) { sb.Write(","); } sb.Write(nmdp.StateLabeling[state][i]); } sb.WriteLine(")\"];"); var cid = nmdp.GetRootContinuationGraphLocationOfState(state); var fromNode = state.ToString(); if (showRootCids) { var rootNode = $"cid{cid}"; sb.WriteLine($" {rootNode} [ shape=point,width=0.1,height=0.1,label=\"\" ];"); sb.WriteLine($" {state}->{rootNode};"); fromNode = rootNode; } ExportCid(nmdp, sb, fromNode, cid); } sb.WriteLine("}"); }
// Note: Should be used with using(var modelchecker = new ...) public BuiltinNmdpModelChecker(NestedMarkovDecisionProcess nmdp, TextWriter output = null) : base(nmdp, output) { _underlyingDigraph = Nmdp.CreateUnderlyingDigraph(); }
// Note: Should be used with using(var modelchecker = new ...) protected NmdpModelChecker(NestedMarkovDecisionProcess nmdp, TextWriter output = null) { Nmdp = nmdp; _output = output; }
public TreeTraversal(NestedMarkovDecisionProcess nmdp, long parentContinuationId) { ParentContinuationId = parentContinuationId; Nmdp = nmdp; }