Exemplo n.º 1
0
            internal bool BackwardTraversal(IEnumerable <long> targetTransitionTargets, Action <long> actionOnResultingTransitionTarget, Func <long, bool> transitionTargetsToIgnore)
            {
                var transitionTargetNodes = targetTransitionTargets.Select(TransitionTargetToNodeIndex);

                Func <long, bool> ignoreNodeFunc =
                    node =>
                {
                    var transitionTarget = TryGetTransitionTargetIndex(node);
                    if (transitionTarget == null)
                    {
                        return(false);
                    }
                    return(transitionTargetsToIgnore(transitionTarget.Value));
                };

                var ancestors = _baseGraph.GetAncestors(transitionTargetNodes, ignoreNodeFunc);

                foreach (var ancestor in ancestors)
                {
                    var transitionTargetOfAncestor = TryGetTransitionTargetIndex(ancestor.Key);
                    if (transitionTargetOfAncestor != null)
                    {
                        actionOnResultingTransitionTarget(transitionTargetOfAncestor.Value);
                    }
                }
                // return, if root cid of initial state
                var initialCid     = _ltmdp.GetRootContinuationGraphLocationOfInitialState();
                var initialCidNode = CidToNodeIndex(initialCid);

                return(ancestors.ContainsKey(initialCidNode));
            }
Exemplo n.º 2
0
        public void ConvertInitialStates()
        {
            var cid = _ltmdp.GetRootContinuationGraphLocationOfInitialState();

            ClearStepGraphMapper(cid);
            var locationOfStateRoot = NestedMarkovDecisionProcess.GetPlaceForNewContinuationGraphElements(1);

            NestedMarkovDecisionProcess.SetRootContinuationGraphLocationOfInitialState(locationOfStateRoot);
            AddNodesOfContinuationId(cid, locationOfStateRoot);
        }
Exemplo n.º 3
0
            public UnderlyingDigraph(LabeledTransitionMarkovDecisionProcess ltmdp)
            {
                //Assumption "every node is reachable" is fulfilled due to the construction
                _ltmdp = ltmdp;
                _transitionTargetNo = ltmdp.TransitionTargets;
                _cidNo     = ltmdp.ContinuationGraphSize;
                _stateNo   = ltmdp.SourceStates.Count;
                _baseGraph = new BidirectionalGraph <EdgeType>();

                var initialCid = _ltmdp.GetRootContinuationGraphLocationOfInitialState();

                AddNodesOfContinuationId(initialCid);

                foreach (var sourceState in _ltmdp.SourceStates)
                {
                    var stateRootCid = _ltmdp.GetRootContinuationGraphLocationOfState(sourceState);
                    AddNodesOfContinuationId(stateRootCid);
                    AddStateToRootCidTransition(sourceState, stateRootCid);
                }
                AddTransitionTargets();
            }
Exemplo n.º 4
0
        public static void ExportToGv(this LabeledTransitionMarkovDecisionProcess ltmdp, TextWriter sb)
        {
            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 = ltmdp.GetRootContinuationGraphLocationOfInitialState();

            ExportCid(ltmdp, sb, initialStateName, false, initialCid);

            foreach (var state in ltmdp.SourceStates)
            {
                sb.Write($" {state} [label=\"{state}");
                sb.WriteLine("\"];");

                var cid      = ltmdp.GetRootContinuationGraphLocationOfState(state);
                var fromNode = state.ToString();
                ExportCid(ltmdp, sb, fromNode, false, cid);
            }
            sb.WriteLine("}");
        }