Example #1
0
            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);
                }
            }
Example #2
0
        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("}");
        }