Example #1
0
        private void UpdateContinuationDistributionMapperAndCollectLeafs(long currentCid)
        {
            var cge = _nmdp.GetContinuationGraphElement(currentCid);

            if (cge.IsChoiceTypeUnsplitOrFinal)
            {
                var cgl = _nmdp.GetContinuationGraphLeaf(currentCid);
                MultiplyProbabilityOfCid(currentCid, cgl.Probability);
                SetLeafOfCid(currentCid, cgl);
            }
            else
            {
                var cgi = _nmdp.GetContinuationGraphInnerNode(currentCid);
                MultiplyProbabilityOfCid(currentCid, cgi.Probability);
                if (cge.IsChoiceTypeForward)
                {
                    // This ChoiceType might be created by ForwardUntakenChoicesAtIndex in ChoiceResolver
                    throw new Exception("Forward transitions not supported");
                }
                else if (cge.IsChoiceTypeNondeterministic)
                {
                    _ltmdpContinuationDistributionMapper.NonDeterministicSplit(currentCid, cgi.FromCid, cgi.ToCid);
                }
                else if (cge.IsChoiceTypeProbabilitstic)
                {
                    _ltmdpContinuationDistributionMapper.ProbabilisticSplit(currentCid, cgi.FromCid, cgi.ToCid);
                }
                var oldProbability = GetProbabilityOfCid(currentCid);
                for (var i = cgi.FromCid; i <= cgi.ToCid; i++)
                {
                    SetProbabilityOfCid(i, oldProbability);
                    UpdateContinuationDistributionMapperAndCollectLeafs(i);
                }
            }
        }
Example #2
0
        private static void ExportCid(NestedMarkovDecisionProcess nmdp, TextWriter sb, string fromNode, bool fromProbabilistic, long currentCid)
        {
            NestedMarkovDecisionProcess.ContinuationGraphElement cge = nmdp.GetContinuationGraphElement(currentCid);
            if (cge.IsChoiceTypeUnsplitOrFinal)
            {
                var cgl = nmdp.GetContinuationGraphLeaf(currentCid);

                var thisNode = $"cid{currentCid}";
                sb.WriteLine($" {thisNode} [ shape=point,width=0.1,height=0.1,label=\"\" ];");
                if (fromProbabilistic)
                {
                    sb.WriteLine($" {fromNode}->{thisNode} [ arrowhead =\"onormal\", label=\"{cgl.Probability.ToString(CultureInfo.InvariantCulture)}\"];");
                }
                else
                {
                    sb.WriteLine($" {fromNode}->{thisNode} [ arrowhead =\"normal\"];");
                }

                sb.WriteLine($" {thisNode} -> {cgl.ToState} [ arrowhead =\"normal\"];");
            }
            else if (cge.IsChoiceTypeForward)
            {
                // only forward node (no recursion)
                // do not print thisNode
                var cgi    = nmdp.GetContinuationGraphInnerNode(currentCid);
                var toNode = $"cid{cgi.ToCid}";
                sb.WriteLine($" {fromNode}->{toNode} [ style =\"dashed\", label=\"{Probability.PrettyPrint(cgi.Probability)}\"];");
            }
            else
            {
                // we print how we came to this node
                var cgi = nmdp.GetContinuationGraphInnerNode(currentCid);

                var thisNode = $"cid{currentCid}";
                sb.WriteLine($" {thisNode} [ shape=point,width=0.1,height=0.1,label=\"\" ];");
                if (fromProbabilistic)
                {
                    sb.WriteLine($" {fromNode}->{thisNode} [ arrowhead =\"onormal\", label=\"{Probability.PrettyPrint(cgi.Probability)}\"];");
                }
                else
                {
                    sb.WriteLine($" {fromNode}->{thisNode} [ arrowhead =\"normal\"];");
                }

                for (var i = cgi.FromCid; i <= cgi.ToCid; i++)
                {
                    ExportCid(nmdp, sb, thisNode, cge.IsChoiceTypeProbabilitstic, i);
                }
            }
        }