예제 #1
0
        public void OneReflexiveTransition()
        {
            var ltmdp        = new LabeledTransitionMarkovDecisionProcess(StateCapacity, TransitionCapacity);
            var ltmdpBuilder = new LabeledTransitionMarkovDecisionProcess.LtmdpBuilderDuringTraversal <SimpleExecutableModel>(ltmdp, AnalysisConfiguration.Default);

            // add initial state
            Clear();
            CreateTransition(false, 5, 0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 0, CreateTransitionCollection(), _transitionCount, true);
            Clear();

            // add reflexive state 5
            CreateTransition(false, 5, 0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 5, CreateTransitionCollection(), _transitionCount, false);

            var ltmdpToNmdp = new LtmdpToNmdp(ltmdp);
            var nmdp        = ltmdpToNmdp.NestedMarkovDecisionProcess;

            nmdp.ContinuationGraphSize.ShouldBe(2);
            nmdp.States.ShouldBe(1);

            var initialTransitionTargets = CountTargetStatesOfInitialState(nmdp);

            initialTransitionTargets.ShouldBe(1);
            var initialProbabilitySum = SumProbabilitiesOfInitialState(nmdp);

            initialProbabilitySum.ShouldBe(1.0);

            var transitionTargetsOfState0 = CountTargetStatesOfState(nmdp, 0);

            transitionTargetsOfState0.ShouldBe(1);
            var probabilitySumOfState0 = SumProbabilitiesOfState(nmdp, 0);

            probabilitySumOfState0.ShouldBe(1.0);
        }
예제 #2
0
        public void ThreeReflexiveStatesFromNonInitialState()
        {
            var ltmdp        = new LabeledTransitionMarkovDecisionProcess(StateCapacity, TransitionCapacity);
            var ltmdpBuilder = new LabeledTransitionMarkovDecisionProcess.LtmdpBuilderDuringTraversal <SimpleExecutableModel>(ltmdp, AnalysisConfiguration.Default);

            // add initial state
            Clear();
            CreateTransition(false, 5, 0);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 0, CreateTransitionCollection(), _transitionCount, true);

            // add state 5
            Clear();
            _stepGraph.ProbabilisticSplit(0, 1, 3);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            _stepGraph.SetProbabilityOfContinuationId(1, 0.3);
            _stepGraph.SetProbabilityOfContinuationId(2, 0.3);
            _stepGraph.SetProbabilityOfContinuationId(3, 0.4);
            CreateTransition(false, 7, 1);
            CreateTransition(false, 2, 2);
            CreateTransition(false, 1, 3);
            ltmdpBuilder.ProcessTransitions(null, null, 5, CreateTransitionCollection(), _transitionCount, false);

            // add reflexive state 7
            Clear();
            CreateTransition(false, 7, 0);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 7, CreateTransitionCollection(), _transitionCount, false);

            // add reflexive state 2
            Clear();
            CreateTransition(false, 2, 0);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 2, CreateTransitionCollection(), _transitionCount, false);

            // add reflexive state 1
            Clear();
            CreateTransition(false, 1, 0);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 1, CreateTransitionCollection(), _transitionCount, false);


            ltmdp.TransitionTargets.ShouldBe(7);
            ltmdp.SourceStates.Count.ShouldBe(4);
            ltmdp.SourceStates.First(state => state == 5).ShouldBe(5);

            var initialTransitionTargets = CountTargetStatesOfInitialState(ltmdp);

            initialTransitionTargets.ShouldBe(1);
            var initialProbabilitySum = SumProbabilitiesOfInitialState(ltmdp);

            initialProbabilitySum.ShouldBe(1.0);

            var transitionTargetsOfState5 = CountTargetStatesOfState(ltmdp, 5);

            transitionTargetsOfState5.ShouldBe(3);
            var probabilitySumOfState5 = SumProbabilitiesOfState(ltmdp, 5);

            probabilitySumOfState5.ShouldBe(1.0);
        }
예제 #3
0
        public void TwoDistributionWithFiveContinuationsAfterTwoSplitsWithRemove()
        {
            var ltmdp        = new LabeledTransitionMarkovDecisionProcess(StateCapacity, TransitionCapacity);
            var ltmdpBuilder = new LabeledTransitionMarkovDecisionProcess.LtmdpBuilderDuringTraversal <SimpleExecutableModel>(ltmdp, AnalysisConfiguration.Default);

            // add initial state
            Clear();
            CreateTransition(false, 5, 0);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 0, CreateTransitionCollection(), _transitionCount, true);

            // add state 5
            Clear();
            _stepGraph.ProbabilisticSplit(0, 1, 3);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            _stepGraph.SetProbabilityOfContinuationId(1, 0.3);
            _stepGraph.NonDeterministicSplit(1, 4, 5);
            _stepGraph.PruneChoicesOfCidTo2(0);
            _stepGraph.Forward(2, 4);
            _stepGraph.SetProbabilityOfContinuationId(2, 0.7);
            _stepGraph.SetProbabilityOfContinuationId(4, 1.0);
            _stepGraph.SetProbabilityOfContinuationId(5, 1.0);
            CreateTransition(false, 7, 4);
            CreateTransition(false, 2, 5);
            ltmdpBuilder.ProcessTransitions(null, null, 5, CreateTransitionCollection(), _transitionCount, false);

            // add reflexive state 7
            Clear();
            CreateTransition(false, 7, 0);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 7, CreateTransitionCollection(), _transitionCount, false);

            // add reflexive state 2
            Clear();
            CreateTransition(false, 2, 0);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 2, CreateTransitionCollection(), _transitionCount, false);

            ltmdp.TransitionTargets.ShouldBe(5);
            ltmdp.SourceStates.Count.ShouldBe(3);


            // check that the transformed forward node (was 2) points to the correct target (was 4) and not to anything else.
            var initialRootCidLocation           = ltmdp.GetRootContinuationGraphLocationOfInitialState();
            var initialTarget                    = ltmdp.GetContinuationGraphElement(initialRootCidLocation);
            var state5Transformed                = ltmdp.GetTransitionTarget((int)initialTarget.To);
            var state5TransformedRootCidLocation = ltmdp.GetRootContinuationGraphLocationOfState(state5Transformed.TargetState);
            var state5TransformedRootCid         = ltmdp.GetContinuationGraphElement(state5TransformedRootCidLocation);
            var state5Successors                 = state5TransformedRootCid.To - state5TransformedRootCid.From + 1;

            state5Successors.ShouldBe(2);
            var state5TransformedFirstSplitCidLocation = state5TransformedRootCid.From;
            var state5TransformedFirstSplitCid         = ltmdp.GetContinuationGraphElement(state5TransformedFirstSplitCidLocation);
            var state5TransformedTargetOfForward       = state5TransformedFirstSplitCid.From;
            var state5ForwardNode = ltmdp.GetContinuationGraphElement(state5TransformedRootCid.To);

            state5ForwardNode.ChoiceType.ShouldBe(LtmdpChoiceType.Forward);
            state5ForwardNode.To.ShouldBe(state5TransformedTargetOfForward);
        }
예제 #4
0
        public void ThreeReflexiveStatesFromInitialState()
        {
            var ltmdp        = new LabeledTransitionMarkovDecisionProcess(StateCapacity, TransitionCapacity);
            var ltmdpBuilder = new LabeledTransitionMarkovDecisionProcess.LtmdpBuilderDuringTraversal(ltmdp);

            // add initial state
            Clear();
            _stepGraph.ProbabilisticSplit(0, 1, 3);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            _stepGraph.SetProbabilityOfContinuationId(1, 0.3);
            _stepGraph.SetProbabilityOfContinuationId(2, 0.3);
            _stepGraph.SetProbabilityOfContinuationId(3, 0.4);
            CreateTransition(false, 5, 1);
            CreateTransition(false, 7, 2);
            CreateTransition(false, 2, 3);
            ltmdpBuilder.ProcessTransitions(null, null, 0, CreateTransitionCollection(), _transitionCount, true);

            // add reflexive state 5
            Clear();
            CreateTransition(false, 5, 0);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 5, CreateTransitionCollection(), _transitionCount, false);

            // add reflexive state 7
            Clear();
            CreateTransition(false, 5, 0);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 7, CreateTransitionCollection(), _transitionCount, false);

            // add reflexive state 2
            Clear();
            CreateTransition(false, 2, 0);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 2, CreateTransitionCollection(), _transitionCount, false);

            var ltmdpToNmdp = new LtmdpToNmdp(ltmdp);
            var nmdp        = ltmdpToNmdp.NestedMarkovDecisionProcess;

            nmdp.ContinuationGraphSize.ShouldBe(7);
            nmdp.States.ShouldBe(3);

            var initialTransitionTargets = CountTargetStatesOfInitialState(nmdp);

            initialTransitionTargets.ShouldBe(3);
            var initialProbabilitySum = SumProbabilitiesOfInitialState(nmdp);

            initialProbabilitySum.ShouldBe(1.0);

            var transitionTargetsOfState0 = CountTargetStatesOfState(nmdp, 0);

            transitionTargetsOfState0.ShouldBe(1);
            var probabilitySumOfState0 = SumProbabilitiesOfState(nmdp, 0);

            probabilitySumOfState0.ShouldBe(1.0);
        }
예제 #5
0
        public LtmdpTestBuilder()
        {
            _transitionBuffer.Resize(TransitionCapacity * sizeof(LtmdpTransition), zeroMemory: false);
            _transitions = (LtmdpTransition *)_transitionBuffer.Pointer;

            StepGraph       = new LtmdpStepGraph();
            _choiceResolver = new LtmdpChoiceResolver(StepGraph, true);

            Ltmdp        = new LabeledTransitionMarkovDecisionProcess(StateCapacity, TransitionCapacity);
            LtmdpBuilder = new LabeledTransitionMarkovDecisionProcess.LtmdpBuilderDuringTraversal(Ltmdp);
        }
예제 #6
0
        public void StatesFromNonInitialStateWithMoreDistributions()
        {
            var ltmdp        = new LabeledTransitionMarkovDecisionProcess(StateCapacity, TransitionCapacity);
            var ltmdpBuilder = new LabeledTransitionMarkovDecisionProcess.LtmdpBuilderDuringTraversal <SimpleExecutableModel>(ltmdp, AnalysisConfiguration.Default);

            // add initial state
            Clear();
            CreateTransition(false, 5, 0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 0, CreateTransitionCollection(), _transitionCount, true);

            // add state 5
            Clear();
            _stepGraph.NonDeterministicSplit(0, 1, 3);
            _stepGraph.ProbabilisticSplit(2, 4, 6);
            CreateTransition(false, 1, 1, 1.0);
            CreateTransition(false, 7, 4, 0.3);
            CreateTransition(false, 2, 5, 0.3);
            CreateTransition(false, 1, 6, 0.4);
            CreateTransition(false, 7, 3, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 5, CreateTransitionCollection(), _transitionCount, false);

            // add reflexive state 7
            Clear();
            _stepGraph.NonDeterministicSplit(0, 1, 2);
            _stepGraph.ProbabilisticSplit(1, 3, 4);
            CreateTransition(false, 7, 3, 0.2);
            CreateTransition(false, 2, 4, 0.8);
            CreateTransition(false, 1, 2, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 7, CreateTransitionCollection(), _transitionCount, false);



            // add reflexive state 2
            Clear();
            CreateTransition(false, 2, 0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 2, CreateTransitionCollection(), _transitionCount, false);

            // add reflexive state 1
            Clear();
            CreateTransition(false, 1, 0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 1, CreateTransitionCollection(), _transitionCount, false);

            var ltmdpToNmdp = new LtmdpToNmdp(ltmdp);
            var nmdp        = ltmdpToNmdp.NestedMarkovDecisionProcess;


            nmdp.ContinuationGraphSize.ShouldBe(15);
            nmdp.States.ShouldBe(4);

            var initialTransitionTargets = CountTargetStatesOfInitialState(nmdp);

            initialTransitionTargets.ShouldBe(1);
            var initialProbabilitySum = SumProbabilitiesOfInitialState(nmdp);

            initialProbabilitySum.ShouldBe(1.0);

            var transitionTargetsOfState0 = CountTargetStatesOfState(nmdp, 0);

            transitionTargetsOfState0.ShouldBe(5);
            var probabilitySumOfState0 = SumProbabilitiesOfState(nmdp, 0);

            probabilitySumOfState0.ShouldBe(3.0);
        }
예제 #7
0
        public void TwoDistributionWithFiveContinuationsAfterTwoSplitsWithRemove()
        {
            var ltmdp        = new LabeledTransitionMarkovDecisionProcess(StateCapacity, TransitionCapacity);
            var ltmdpBuilder = new LabeledTransitionMarkovDecisionProcess.LtmdpBuilderDuringTraversal(ltmdp);

            // add initial state
            Clear();
            CreateTransition(false, 5, 0);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 0, CreateTransitionCollection(), _transitionCount, true);

            // add state 5
            Clear();
            _stepGraph.ProbabilisticSplit(0, 1, 3);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            _stepGraph.SetProbabilityOfContinuationId(1, 0.3);
            _stepGraph.NonDeterministicSplit(1, 4, 5);
            _stepGraph.PruneChoicesOfCidTo2(0);
            _stepGraph.Forward(2, 4);
            _stepGraph.SetProbabilityOfContinuationId(2, 0.7);
            _stepGraph.SetProbabilityOfContinuationId(4, 1.0);
            _stepGraph.SetProbabilityOfContinuationId(5, 1.0);
            CreateTransition(false, 7, 4);
            CreateTransition(false, 2, 5);
            ltmdpBuilder.ProcessTransitions(null, null, 5, CreateTransitionCollection(), _transitionCount, false);

            // add reflexive state 7
            Clear();
            CreateTransition(false, 7, 0);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 7, CreateTransitionCollection(), _transitionCount, false);

            // add reflexive state 2
            Clear();
            CreateTransition(false, 2, 0);
            _stepGraph.SetProbabilityOfContinuationId(0, 1.0);
            ltmdpBuilder.ProcessTransitions(null, null, 2, CreateTransitionCollection(), _transitionCount, false);

            var ltmdpToNmdp = new LtmdpToNmdp(ltmdp);
            var nmdp        = ltmdpToNmdp.NestedMarkovDecisionProcess;

            nmdp.ContinuationGraphSize.ShouldBe(8);
            nmdp.States.ShouldBe(3);

            var initialTransitionTargets = CountTargetStatesOfInitialState(nmdp);

            initialTransitionTargets.ShouldBe(1);
            var initialProbabilitySum = SumProbabilitiesOfInitialState(nmdp);

            initialProbabilitySum.ShouldBe(1.0);


            // check that the transformed forward node (was 2) points to the correct target (was 4) and not to anything else.
            var initialRootCidLocation           = nmdp.GetRootContinuationGraphLocationOfInitialState();
            var initialTarget                    = nmdp.GetContinuationGraphLeaf(initialRootCidLocation);
            var state5Transformed                = initialTarget.ToState;
            var state5TransformedRootCidLocation = nmdp.GetRootContinuationGraphLocationOfState(state5Transformed);
            var state5TransformedRootCid         = nmdp.GetContinuationGraphInnerNode(state5TransformedRootCidLocation);
            var state5Successors                 = state5TransformedRootCid.ToCid - state5TransformedRootCid.FromCid + 1;

            state5Successors.ShouldBe(2);
            var state5TransformedFirstSplitCidLocation = state5TransformedRootCid.FromCid;
            var state5TransformedFirstSplitCid         = nmdp.GetContinuationGraphInnerNode(state5TransformedFirstSplitCidLocation);
            var state5TransformedTargetOfForward       = state5TransformedFirstSplitCid.FromCid;
            var state5ForwardNode = nmdp.GetContinuationGraphInnerNode(state5TransformedRootCid.ToCid);

            state5ForwardNode.ChoiceType.ShouldBe(LtmdpChoiceType.Forward);
            state5ForwardNode.ToCid.ShouldBe(state5TransformedTargetOfForward);
        }