internal static MarkovDecisionProcess Create()
        {
            // Just a simple MDP with simple nondeterministic choices
            //   ⟳0⟶1⟲
            var mdp = new MarkovDecisionProcess(ModelCapacityByMemorySize.Tiny);

            mdp.StateFormulaLabels         = new string[] { Label1Formula.Label, Label2Formula.Label };
            mdp.StateRewardRetrieverLabels = new string[] { };
            mdp.StartWithInitialDistributions();
            mdp.StartWithNewInitialDistribution();
            mdp.AddTransitionToInitialDistribution(0, 1.0);
            mdp.FinishInitialDistribution();
            mdp.FinishInitialDistributions();
            mdp.SetStateLabeling(1, new StateFormulaSet(new[] { true, false }));
            mdp.StartWithNewDistributions(1);
            mdp.StartWithNewDistribution();
            mdp.AddTransition(1, 1.0);
            mdp.FinishDistribution();
            mdp.FinishDistributions();
            mdp.SetStateLabeling(0, new StateFormulaSet(new[] { false, true }));
            mdp.StartWithNewDistributions(0);
            mdp.StartWithNewDistribution();
            mdp.AddTransition(1, 1.0);
            mdp.FinishDistribution();
            mdp.StartWithNewDistribution();
            mdp.AddTransition(0, 1.0);
            mdp.FinishDistribution();
            mdp.FinishDistributions();
            return(mdp);
        }
        internal static MarkovDecisionProcess Create()
        {
            // A MDP which was designed to test prob0e
            //   4
            //   ⇅
            //   0⟼1↘
            //    ↘2⟼3⟲
            var mdp = new MarkovDecisionProcess(ModelCapacityByMemorySize.Tiny);

            mdp.StateFormulaLabels         = new string[] { Label1Formula.Label, Label2Formula.Label };
            mdp.StateRewardRetrieverLabels = new string[] { };
            mdp.StartWithInitialDistributions();
            mdp.StartWithNewInitialDistribution();
            mdp.AddTransitionToInitialDistribution(0, 1.0);
            mdp.FinishInitialDistribution();
            mdp.FinishInitialDistributions();

            mdp.SetStateLabeling(0, new StateFormulaSet(new[] { false, false }));
            mdp.StartWithNewDistributions(0);
            mdp.StartWithNewDistribution();
            mdp.AddTransition(1, 1.0);
            mdp.FinishDistribution();
            mdp.StartWithNewDistribution();
            mdp.AddTransition(2, 1.0);
            mdp.FinishDistribution();
            mdp.StartWithNewDistribution();
            mdp.AddTransition(4, 1.0);
            mdp.FinishDistribution();
            mdp.FinishDistributions();

            mdp.SetStateLabeling(1, new StateFormulaSet(new[] { false, false }));
            mdp.StartWithNewDistributions(1);
            mdp.StartWithNewDistribution();
            mdp.AddTransition(3, 1.0);
            mdp.FinishDistribution();
            mdp.FinishDistributions();

            mdp.SetStateLabeling(2, new StateFormulaSet(new[] { false, false }));
            mdp.StartWithNewDistributions(2);
            mdp.StartWithNewDistribution();
            mdp.AddTransition(3, 1.0);
            mdp.FinishDistribution();
            mdp.FinishDistributions();

            mdp.SetStateLabeling(3, new StateFormulaSet(new[] { true, false }));
            mdp.StartWithNewDistributions(3);
            mdp.StartWithNewDistribution();
            mdp.AddTransition(3, 1.0);
            mdp.FinishDistribution();
            mdp.FinishDistributions();

            mdp.SetStateLabeling(4, new StateFormulaSet(new[] { false, false }));
            mdp.StartWithNewDistributions(4);
            mdp.StartWithNewDistribution();
            mdp.AddTransition(0, 1.0);
            mdp.FinishDistribution();
            mdp.FinishDistributions();
            return(mdp);
        }
예제 #3
0
        private void AddPaddingStatesInMdp()
        {
            foreach (var paddingState in _paddingStates)
            {
                if (paddingState.Key.IsInitial)
                {
                    MarkovDecisionProcess.StartWithInitialDistributions();
                }
                else
                {
                    MarkovDecisionProcess.StartWithNewDistributions(paddingState.Key.State);
                }
                MarkovDecisionProcess.StartWithNewDistribution();
                MarkovDecisionProcess.AddTransition(paddingState.Value, 1.0);
                MarkovDecisionProcess.FinishDistribution();

                if (paddingState.Key.IsInitial)
                {
                    MarkovDecisionProcess.FinishInitialDistributions();
                }
                else
                {
                    MarkovDecisionProcess.FinishDistributions();
                }
            }
        }
        internal static MarkovDecisionProcess Create()
        {
            // MDP of [Parker02, page 36]
            //   0
            //   ⇅
            //   1➞0.6⟼2⟲
            //      0.4⟼3⟲
            var mdp = new MarkovDecisionProcess(ModelCapacityByMemorySize.Tiny);

            mdp.StateFormulaLabels         = new string[] { Label1Formula.Label, Label2Formula.Label };
            mdp.StateRewardRetrieverLabels = new string[] { };
            mdp.StartWithInitialDistributions();
            mdp.StartWithNewInitialDistribution();
            mdp.AddTransitionToInitialDistribution(0, 1.0);
            mdp.FinishInitialDistribution();
            mdp.FinishInitialDistributions();
            mdp.SetStateLabeling(0, new StateFormulaSet(new[] { false, false }));
            mdp.StartWithNewDistributions(0);
            mdp.StartWithNewDistribution();
            mdp.AddTransition(1, 1.0);
            mdp.FinishDistribution();
            mdp.FinishDistributions();
            mdp.SetStateLabeling(1, new StateFormulaSet(new[] { false, false }));
            mdp.StartWithNewDistributions(1);
            mdp.StartWithNewDistribution();
            mdp.AddTransition(0, 1.0);
            mdp.FinishDistribution();
            mdp.StartWithNewDistribution();
            mdp.AddTransition(2, 0.6);
            mdp.AddTransition(3, 0.4);
            mdp.FinishDistribution();
            mdp.FinishDistributions();
            mdp.SetStateLabeling(2, new StateFormulaSet(new[] { true, false }));
            mdp.StartWithNewDistributions(2);
            mdp.StartWithNewDistribution();
            mdp.AddTransition(2, 1.0);
            mdp.FinishDistribution();
            mdp.FinishDistributions();
            mdp.SetStateLabeling(3, new StateFormulaSet(new[] { false, true }));
            mdp.StartWithNewDistributions(3);
            mdp.StartWithNewDistribution();
            mdp.AddTransition(3, 1.0);
            mdp.FinishDistribution();
            mdp.FinishDistributions();
            return(mdp);
        }
예제 #5
0
 private void StartDistributions(int?stateToStartFrom)
 {
     if (stateToStartFrom.HasValue)
     {
         var mdpState = stateToStartFrom.Value;
         MarkovDecisionProcess.StartWithNewDistributions(mdpState);
     }
     else
     {
         MarkovDecisionProcess.StartWithInitialDistributions();
     }
 }
예제 #6
0
        private void ConvertChildCid(long currentCid)
        {
            var distanceFromRootOfSourceNode = _cidDistanceFromRoot[currentCid];
            var cge = _nmdp.GetContinuationGraphElement(currentCid);

            if (cge.IsChoiceTypeUnsplitOrFinal || cge.IsChoiceTypeForward)
            {
                return;
            }
            var mdpState = _cidToArtificialStateMapping[currentCid];

            MarkovDecisionProcess.StartWithNewDistributions(mdpState);

            var cgi = _nmdp.GetContinuationGraphInnerNode(currentCid);

            if (cge.IsChoiceTypeNondeterministic)
            {
                for (var i = cgi.FromCid; i <= cgi.ToCid; i++)
                {
                    MarkovDecisionProcess.StartWithNewDistribution();
                    AddDestination(i, distanceFromRootOfSourceNode);
                    MarkovDecisionProcess.FinishDistribution();
                }
            }
            else if (cge.IsChoiceTypeProbabilitstic)
            {
                MarkovDecisionProcess.StartWithNewDistribution();
                for (var i = cgi.FromCid; i <= cgi.ToCid; i++)
                {
                    AddDestination(i, distanceFromRootOfSourceNode);
                }
                MarkovDecisionProcess.FinishDistribution();
            }

            MarkovDecisionProcess.FinishDistributions();

            for (var i = cgi.FromCid; i <= cgi.ToCid; i++)
            {
                ConvertChildCid(i);
            }
        }
예제 #7
0
        private void ConvertStateTransitions()
        {
            for (var state = 0; state < _nmdp.States; state++)
            {
                var cidOfStateRoot = _nmdp.GetRootContinuationGraphLocationOfState(state);
                Clear(cidOfStateRoot);
                _ltmdpContinuationDistributionMapper.AddInitialDistributionAndContinuation(cidOfStateRoot);

                UpdateContinuationDistributionMapperAndCollectLeafs(cidOfStateRoot);

                MarkovDecisionProcess.StartWithNewDistributions(state);

                var numberOfDistributions = _ltmdpContinuationDistributionMapper.GetNumbersOfDistributions();
                for (var distribution = 0; distribution < numberOfDistributions; distribution++)
                {
                    AddDistribution(distribution);
                }

                MarkovDecisionProcess.FinishDistributions();
            }
        }