private void AddTransitionTargets() { for (var i = 0L; i < _transitionTargetNo; i++) { var transitionTarget = _ltmdp.GetTransitionTarget(i); var transitionTargetNode = TransitionTargetToNodeIndex(i); var transitionTargetStateNode = StateToNodeIndex(transitionTarget.TargetState); _baseGraph.AddVerticesAndEdge(new Edge <EdgeType>(transitionTargetNode, transitionTargetStateNode, EdgeType.Deterministic)); } }
private void AddNodesOfContinuationId(long continuationId, long locationForContinuationGraphElement) { BufferCidMapping(continuationId, locationForContinuationGraphElement); var choice = _ltmdp.GetContinuationGraphElement(continuationId); if (choice.IsChoiceTypeUnsplitOrFinal) { Assert.That(choice.To <= int.MaxValue, "choice.To must be smaller than int.MaxValue"); var transitionTarget = _ltmdp.GetTransitionTarget((int)choice.To); var targetEntry = new StateStorageEntry(transitionTarget.Formulas, transitionTarget.TargetState); var targetState = _mapper[targetEntry]; NestedMarkovDecisionProcess.AddContinuationGraphLeaf(locationForContinuationGraphElement, targetState, choice.Probability); return; } if (choice.IsChoiceTypeForward) { // no recursive descent here var bufferedTargetCid = GetBufferedNmdpCid(choice.To); NestedMarkovDecisionProcess.AddContinuationGraphInnerNode(locationForContinuationGraphElement, choice.ChoiceType, bufferedTargetCid, bufferedTargetCid, choice.Probability); return; } var offsetTo = choice.To - choice.From; var numberOfChildren = offsetTo + 1; var placesForChildren = NestedMarkovDecisionProcess.GetPlaceForNewContinuationGraphElements(numberOfChildren); NestedMarkovDecisionProcess.AddContinuationGraphInnerNode(locationForContinuationGraphElement, choice.ChoiceType, placesForChildren, placesForChildren + offsetTo, choice.Probability); for (var currentChildNo = 0; currentChildNo < numberOfChildren; currentChildNo++) { var originalContinuationId = choice.From + currentChildNo; var newLocation = placesForChildren + currentChildNo; AddNodesOfContinuationId(originalContinuationId, newLocation); } }
private static void ExportCid(LabeledTransitionMarkovDecisionProcess ltmdp, TextWriter sb, string fromNode, bool fromProbabilistic, long currentCid) { LabeledTransitionMarkovDecisionProcess.ContinuationGraphElement choice = ltmdp.GetContinuationGraphElement(currentCid); if (choice.IsChoiceTypeUnsplitOrFinal) { 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=\"{choice.Probability.ToString(CultureInfo.InvariantCulture)}\"];"); } else { sb.WriteLine($" {fromNode}->{thisNode} [ arrowhead =\"normal\"];"); } var transitionTarget = ltmdp.GetTransitionTarget(choice.To); sb.Write($" {thisNode} -> {transitionTarget.TargetState} [ arrowhead =\"normal\","); sb.Write("label=\""); for (int i = 0; i < ltmdp.StateFormulaLabels.Length; i++) { if (i > 0) { sb.Write(","); } if (transitionTarget.Formulas[i]) { sb.Write("t"); } else { sb.Write("f"); } } sb.WriteLine("\"];"); } else if (choice.IsChoiceTypeForward) { // only forward node (no recursion) // do not print thisNode var toNode = $"cid{choice.To}"; sb.WriteLine($" {fromNode}->{toNode} [ style =\"dashed\", label=\"{choice.Probability.ToString(CultureInfo.InvariantCulture)}\"];"); } else { // we print how we came to this node 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=\"{choice.Probability.ToString(CultureInfo.InvariantCulture)}\"];"); } else { sb.WriteLine($" {fromNode}->{thisNode} [ arrowhead =\"normal\"];"); } for (var i = choice.From; i <= choice.To; i++) { ExportCid(ltmdp, sb, thisNode, choice.IsChoiceTypeProbabilitstic, i); } } }