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);
        }
Пример #2
0
        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.StartWithNewDistribution();
            mdp.AddTransition(0, 1.0);
            mdp.FinishDistribution();
            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();
                }
            }
        }
Пример #4
0
        private void ConvertRootCid(int?sourceState, long currentCid)
        {
            var distanceFromRootOfSourceNode = _cidDistanceFromRoot[currentCid];
            var sourceNodeMaxDistanceToLeaf  = _cidMaxDistanceFromLeaf[currentCid];
            var requiredPadding  = _maximalDistanceBetweenStates - distanceFromRootOfSourceNode - sourceNodeMaxDistanceToLeaf;
            var stateToStartFrom = CreateNewArtificialPaddingStatesForward(sourceState, requiredPadding);

            distanceFromRootOfSourceNode    += requiredPadding;
            _cidDistanceFromRoot[currentCid] = distanceFromRootOfSourceNode;
            StartDistributions(stateToStartFrom);

            var cge = _nmdp.GetContinuationGraphElement(currentCid);

            if (cge.IsChoiceTypeUnsplitOrFinal)
            {
                // If a state leads directly into a new state, add this state directly.
                // Treat this as if there is a non-deterministic split with only one choice.
                // Thus, we assume that this node is not the root node and its non-existing
                // source has a distance of 0 from the root.
                MarkovDecisionProcess.StartWithNewDistribution();
                AddDestination(currentCid, distanceFromRootOfSourceNode);
                MarkovDecisionProcess.FinishDistribution();
                FinishDistributions(stateToStartFrom);
            }
            else
            {
                var cgi = _nmdp.GetContinuationGraphInnerNode(currentCid);

                if (cge.IsChoiceTypeForward)
                {
                    // This ChoiceType might be created by ForwardUntakenChoicesAtIndex in ChoiceResolver
                    throw new Exception("Bug: RootCid cannot be a forward node");
                }
                else 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();
                }

                FinishDistributions(stateToStartFrom);

                for (var i = cgi.FromCid; i <= cgi.ToCid; i++)
                {
                    ConvertChildCid(i);
                }
            }
        }
        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);
        }
Пример #6
0
        private void AddDistribution(int distribution)
        {
            if (_ltmdpContinuationDistributionMapper.IsDistributionEmpty(distribution))
            {
                return;
            }
            MarkovDecisionProcess.StartWithNewDistribution();

            var enumerator = _ltmdpContinuationDistributionMapper.GetContinuationsOfDistributionEnumerator(distribution);

            while (enumerator.MoveNext())
            {
                var leaf        = GetLeafOfCid(enumerator.CurrentContinuationId);
                var probability = GetProbabilityOfCid(enumerator.CurrentContinuationId);
                MarkovDecisionProcess.AddTransition(leaf.ToState, probability);
            }

            MarkovDecisionProcess.FinishDistribution();
        }
Пример #7
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);
            }
        }