/// <summary> /// Show all transitions from the given node and from the nodes that are reached from /// the given node etc., until the maximum nr of transitions is reached /// </summary> internal void ShowReachable(Node node) { int transCnt = (firstExploration ? (initTransitions < 0 ? maxTransitions : initTransitions) : maxTransitions); firstExploration = false; if (excludeIsomorphicStates) { Set<IState> frontier = new Set<IState>(stateMap[node]); StateContainer<IState> visited = new StateContainer<IState>(this.modelProgram, stateMap[node]); while (!frontier.IsEmpty && this.transitions.Count < transCnt) { IState sourceIState = frontier.Choose(0); Node sourceNode = nodeMap[sourceIState]; frontier = frontier.Remove(sourceIState); foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(sourceIState)) { foreach (CompoundTerm action in this.modelProgram.GetActions(sourceIState, aSymbol)) { Node targetNode; if (TryGetTargetNode(sourceNode, action, out targetNode)) { IState targetIState = stateMap[targetNode]; IState isomorphicState; Transition t; if (!visited.HasIsomorphic(targetIState, out isomorphicState)) { frontier = frontier.Add(targetIState); //visited = visited.Add(targetIState); visited.Add(targetIState); t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); } else { if (collapseExcludedIsomorphicStates) t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, nodeMap[isomorphicState]); else { Term isoNode = nodeMap[isomorphicState]; t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); if (!targetNode.Equals(sourceNode) && !targetNode.Equals(isoNode)) groupingTransitions = groupingTransitions.Add(new Triple<Term, CompoundTerm, Term>(targetNode, new CompoundTerm(new Symbol("IsomorphicTo"), new Sequence<Term>()), isoNode)); } } this.transitions = this.transitions.Add(t); this.hiddenTransitions = this.hiddenTransitions.Remove(t); } } } } //Console.WriteLine(dashedTransitions.ToString()); //Console.WriteLine(visited.ToString()); } else { Set<Node> frontier = new Set<Node>(node); Set<Node> visited = frontier; while (!frontier.IsEmpty && this.transitions.Count < transCnt) { Node sourceNode = frontier.Choose(0); frontier = frontier.Remove(sourceNode); foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(stateMap[sourceNode])) { foreach (CompoundTerm action in this.modelProgram.GetActions(stateMap[sourceNode], aSymbol)) { Node targetNode; if (TryGetTargetNode(sourceNode, action, out targetNode)) { if (!visited.Contains(targetNode)) { frontier = frontier.Add(targetNode); visited = visited.Add(targetNode); } Transition t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); this.transitions = this.transitions.Add(t); this.hiddenTransitions = this.hiddenTransitions.Remove(t); } } } } } }
/// <summary> /// Show all transitions from the given node and from the nodes that are reached from /// the given node etc., until the maximum nr of transitions is reached /// </summary> internal void ShowReachable(Node node) { int transCnt = (firstExploration ? (initTransitions < 0 ? maxTransitions : initTransitions) : maxTransitions); firstExploration = false; if (excludeIsomorphicStates) { Set <IState> frontier = new Set <IState>(stateMap[node]); StateContainer <IState> visited = new StateContainer <IState>(this.modelProgram, stateMap[node]); while (!frontier.IsEmpty && this.transitions.Count < transCnt) { IState sourceIState = frontier.Choose(0); Node sourceNode = nodeMap[sourceIState]; frontier = frontier.Remove(sourceIState); foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(sourceIState)) { foreach (CompoundTerm action in this.modelProgram.GetActions(sourceIState, aSymbol)) { Node targetNode; if (TryGetTargetNode(sourceNode, action, out targetNode)) { IState targetIState = stateMap[targetNode]; IState isomorphicState; Transition t; if (!visited.HasIsomorphic(targetIState, out isomorphicState)) { frontier = frontier.Add(targetIState); //visited = visited.Add(targetIState); visited.Add(targetIState); t = new Triple <Term, CompoundTerm, Term>(sourceNode, action, targetNode); } else { if (collapseExcludedIsomorphicStates) { t = new Triple <Term, CompoundTerm, Term>(sourceNode, action, nodeMap[isomorphicState]); } else { Term isoNode = nodeMap[isomorphicState]; t = new Triple <Term, CompoundTerm, Term>(sourceNode, action, targetNode); if (!targetNode.Equals(sourceNode) && !targetNode.Equals(isoNode)) { groupingTransitions = groupingTransitions.Add(new Triple <Term, CompoundTerm, Term>(targetNode, new CompoundTerm(new Symbol("IsomorphicTo"), new Sequence <Term>()), isoNode)); } } } this.transitions = this.transitions.Add(t); this.hiddenTransitions = this.hiddenTransitions.Remove(t); } } } } //Console.WriteLine(dashedTransitions.ToString()); //Console.WriteLine(visited.ToString()); } else { Set <Node> frontier = new Set <Node>(node); Set <Node> visited = frontier; while (!frontier.IsEmpty && this.transitions.Count < transCnt) { Node sourceNode = frontier.Choose(0); frontier = frontier.Remove(sourceNode); foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(stateMap[sourceNode])) { foreach (CompoundTerm action in this.modelProgram.GetActions(stateMap[sourceNode], aSymbol)) { Node targetNode; if (TryGetTargetNode(sourceNode, action, out targetNode)) { if (!visited.Contains(targetNode)) { frontier = frontier.Add(targetNode); visited = visited.Add(targetNode); } Transition t = new Triple <Term, CompoundTerm, Term>(sourceNode, action, targetNode); this.transitions = this.transitions.Add(t); this.hiddenTransitions = this.hiddenTransitions.Remove(t); } } } } } }
/// <summary> /// Check if the term represented by goal is reachable. Empty string results in traversing the whole state space. /// </summary> /// <param name="goal">The goal term involving the model program name as outer function symbol.</param> public ReachabilityResult CheckReachability(string goal) { uint transCnt = 0; uint stateCount = 0; //(firstExploration ? (initTransitions < 0 ? maxTransitions : initTransitions) : maxTransitions); //firstExploration = false; //excludeIsomorphicStates = false; Set<CompoundTerm> goals = processGoal(modelProgram, goal); Pair<Set<CompoundTerm>, Set<Term>> simpleAndFsmGoals = splitGoals(goals); if (GoalsSatisfied(simpleAndFsmGoals, modelProgram.InitialState)) goto end; if (excludeIsomorphicStates) { Set<IState> frontier = new Set<IState>(modelProgram.InitialState); //stateCount++; //Set<IState> visited = Set<IState>.EmptySet; StateContainer<IState> visited = new StateContainer<IState>(this.modelProgram, modelProgram.InitialState); stateCount++; // need to add a check about the initial state. Set<string> transitionPropertyNames = Set<string>.EmptySet; TransitionProperties transitionProperties; while (!frontier.IsEmpty) { IState sourceIState = frontier.Choose(0); frontier = frontier.Remove(sourceIState); foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(sourceIState)) { foreach (CompoundTerm action in this.modelProgram.GetActions(sourceIState, aSymbol)) { //Node targetNode = GetTargetNode(sourceNode, action); IState targetIState = modelProgram.GetTargetState(sourceIState, action, transitionPropertyNames, out transitionProperties); //if (this.modelProgram.IsAccepting(targetIState)) // this.acceptingNodes = this.acceptingNodes.Add(targetNode); //if (!this.modelProgram.SatisfiesStateInvariant(targetState)) // this.errorNodes = this.errorNodes.Add(targetNode); //IState isomorphicState; //Transition t; transCnt++; IState isomorphicState; if (!visited.HasIsomorphic(targetIState, out isomorphicState)) { if (GoalsSatisfied(simpleAndFsmGoals, targetIState)) goto end; frontier = frontier.Add(targetIState); visited.Add(targetIState); stateCount++; //visited.Add(targetIState); //t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); } //else //{ // //if (collapseExcludedIsomorphicStates) // // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, nodeMap[isomorphicState]); // //else // { // Term isoNode = nodeMap[isomorphicState]; // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); // if (!targetNode.Equals(sourceNode) && !targetNode.Equals(isoNode)) // groupingTransitions = groupingTransitions.Add(new Triple<Term, CompoundTerm, Term>(targetNode, new CompoundTerm(new Symbol("IsomorphicTo"), new Sequence<Term>()), isoNode)); // } //} //this.transitions = this.transitions.Add(t); //this.hiddenTransitions = this.hiddenTransitions.Remove(t); } } } //Set<IState> frontier = new Set<IState>(stateMap[node]); //StateContainer<IState> visited = new StateContainer<IState>(this.modelProgram, stateMap[node]); //while (!frontier.IsEmpty && this.transitions.Count < transCnt) //{ // IState sourceIState = frontier.Choose(0); // Node sourceNode = nodeMap[sourceIState]; // frontier = frontier.Remove(sourceIState); // foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(sourceIState)) // { // foreach (CompoundTerm action in this.modelProgram.GetActions(sourceIState, aSymbol)) // { // Node targetNode = GetTargetNode(sourceNode, action); // IState targetIState = stateMap[targetNode]; // IState isomorphicState; // Transition t; // if (!visited.HasIsomorphic(targetIState, out isomorphicState)) // { // frontier = frontier.Add(targetIState); // //visited = visited.Add(targetIState); // visited.Add(targetIState); // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); // } // else // { // if (collapseExcludedIsomorphicStates) // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, nodeMap[isomorphicState]); // else // { // Term isoNode = nodeMap[isomorphicState]; // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); // if (!targetNode.Equals(sourceNode) && !targetNode.Equals(isoNode)) // groupingTransitions = groupingTransitions.Add(new Triple<Term, CompoundTerm, Term>(targetNode, new CompoundTerm(new Symbol("IsomorphicTo"), new Sequence<Term>()), isoNode)); // } // } // this.transitions = this.transitions.Add(t); // this.hiddenTransitions = this.hiddenTransitions.Remove(t); // } // } //} ////Console.WriteLine(dashedTransitions.ToString()); ////Console.WriteLine(visited.ToString()); } else { Set<IState> frontier = new Set<IState>(modelProgram.InitialState); Console.Out.WriteLine(frontier.ToString()); Console.Out.WriteLine(modelProgram.ToString()); stateCount++; // need to add a check about the initial state. Set<IState> visited = new Set<IState>(modelProgram.InitialState); Set<string> transitionPropertyNames = Set<string>.EmptySet; TransitionProperties transitionProperties; while (!frontier.IsEmpty) { IState sourceIState = frontier.Choose(0); frontier = frontier.Remove(sourceIState); foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(sourceIState)) { foreach (CompoundTerm action in this.modelProgram.GetActions(sourceIState, aSymbol)) { //Node targetNode = GetTargetNode(sourceNode, action); IState targetIState = modelProgram.GetTargetState(sourceIState, action, transitionPropertyNames, out transitionProperties); //Console.WriteLine(sourceIState.ToString()); //Console.WriteLine ("--- " + action + " --->"); //Console.WriteLine (targetIState.ToString()); //Console.WriteLine(); //Console.WriteLine(); //if (this.modelProgram.IsAccepting(targetIState)) // this.acceptingNodes = this.acceptingNodes.Add(targetNode); //if (!this.modelProgram.SatisfiesStateInvariant(targetState)) // this.errorNodes = this.errorNodes.Add(targetNode); //IState isomorphicState; //Transition t; transCnt++; if (!visited.Contains(targetIState)) { if (GoalsSatisfied(simpleAndFsmGoals, targetIState)) goto end; frontier = frontier.Add(targetIState); visited = visited.Add(targetIState); stateCount++; //visited.Add(targetIState); //t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); } //else //{ // //if (collapseExcludedIsomorphicStates) // // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, nodeMap[isomorphicState]); // //else // { // Term isoNode = nodeMap[isomorphicState]; // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); // if (!targetNode.Equals(sourceNode) && !targetNode.Equals(isoNode)) // groupingTransitions = groupingTransitions.Add(new Triple<Term, CompoundTerm, Term>(targetNode, new CompoundTerm(new Symbol("IsomorphicTo"), new Sequence<Term>()), isoNode)); // } //} //this.transitions = this.transitions.Add(t); //this.hiddenTransitions = this.hiddenTransitions.Remove(t); } } } } //Console.WriteLine("Checker results"); //Console.WriteLine("Reached states: "+stateCount); //Console.WriteLine("Number of transitions: "+transCnt); ReachabilityResult result = new ReachabilityResult(stateCount, transCnt); return result; end: ReachabilityResult resReached = new ReachabilityResult(stateCount, transCnt); resReached.Goal = goal; resReached.GoalReached = true; return resReached; }
//internal bool collapseExcludedIsomorphicStates; //int initTransitions; //CompoundTerm goal; /// <summary> /// Show all transitions from the given node and from the nodes that are reached from /// the given node etc., until the state space is exhausted or the maximum number /// of transitions is reached. /// </summary> public ReachabilityResult CheckReachability() { uint transCnt = 0; uint stateCount = 0; //(firstExploration ? (initTransitions < 0 ? maxTransitions : initTransitions) : maxTransitions); //firstExploration = false; //excludeIsomorphicStates = false; if (excludeIsomorphicStates) { Set <IState> frontier = new Set <IState>(modelProgram.InitialState); //stateCount++; //Set<IState> visited = Set<IState>.EmptySet; StateContainer <IState> visited = new StateContainer <IState>(this.modelProgram, modelProgram.InitialState); stateCount++; // need to add a check about the initial state. Set <string> transitionPropertyNames = Set <string> .EmptySet; TransitionProperties transitionProperties; while (!frontier.IsEmpty) { IState sourceIState = frontier.Choose(0); frontier = frontier.Remove(sourceIState); foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(sourceIState)) { foreach (CompoundTerm action in this.modelProgram.GetActions(sourceIState, aSymbol)) { //Node targetNode = GetTargetNode(sourceNode, action); IState targetIState = modelProgram.GetTargetState(sourceIState, action, transitionPropertyNames, out transitionProperties); //if (this.modelProgram.IsAccepting(targetIState)) // this.acceptingNodes = this.acceptingNodes.Add(targetNode); //if (!this.modelProgram.SatisfiesStateInvariant(targetState)) // this.errorNodes = this.errorNodes.Add(targetNode); //IState isomorphicState; //Transition t; transCnt++; IState isomorphicState; if (!visited.HasIsomorphic(targetIState, out isomorphicState)) { frontier = frontier.Add(targetIState); visited.Add(targetIState); stateCount++; //visited.Add(targetIState); //t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); } //else //{ // //if (collapseExcludedIsomorphicStates) // // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, nodeMap[isomorphicState]); // //else // { // Term isoNode = nodeMap[isomorphicState]; // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); // if (!targetNode.Equals(sourceNode) && !targetNode.Equals(isoNode)) // groupingTransitions = groupingTransitions.Add(new Triple<Term, CompoundTerm, Term>(targetNode, new CompoundTerm(new Symbol("IsomorphicTo"), new Sequence<Term>()), isoNode)); // } //} //this.transitions = this.transitions.Add(t); //this.hiddenTransitions = this.hiddenTransitions.Remove(t); } } } //Set<IState> frontier = new Set<IState>(stateMap[node]); //StateContainer<IState> visited = new StateContainer<IState>(this.modelProgram, stateMap[node]); //while (!frontier.IsEmpty && this.transitions.Count < transCnt) //{ // IState sourceIState = frontier.Choose(0); // Node sourceNode = nodeMap[sourceIState]; // frontier = frontier.Remove(sourceIState); // foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(sourceIState)) // { // foreach (CompoundTerm action in this.modelProgram.GetActions(sourceIState, aSymbol)) // { // Node targetNode = GetTargetNode(sourceNode, action); // IState targetIState = stateMap[targetNode]; // IState isomorphicState; // Transition t; // if (!visited.HasIsomorphic(targetIState, out isomorphicState)) // { // frontier = frontier.Add(targetIState); // //visited = visited.Add(targetIState); // visited.Add(targetIState); // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); // } // else // { // if (collapseExcludedIsomorphicStates) // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, nodeMap[isomorphicState]); // else // { // Term isoNode = nodeMap[isomorphicState]; // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); // if (!targetNode.Equals(sourceNode) && !targetNode.Equals(isoNode)) // groupingTransitions = groupingTransitions.Add(new Triple<Term, CompoundTerm, Term>(targetNode, new CompoundTerm(new Symbol("IsomorphicTo"), new Sequence<Term>()), isoNode)); // } // } // this.transitions = this.transitions.Add(t); // this.hiddenTransitions = this.hiddenTransitions.Remove(t); // } // } //} ////Console.WriteLine(dashedTransitions.ToString()); ////Console.WriteLine(visited.ToString()); } else { Set <IState> frontier = new Set <IState>(modelProgram.InitialState); stateCount++; // need to add a check about the initial state. Set <IState> visited = new Set <IState>(modelProgram.InitialState); Set <string> transitionPropertyNames = Set <string> .EmptySet; TransitionProperties transitionProperties; while (!frontier.IsEmpty) { IState sourceIState = frontier.Choose(0); frontier = frontier.Remove(sourceIState); foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(sourceIState)) { foreach (CompoundTerm action in this.modelProgram.GetActions(sourceIState, aSymbol)) { //Node targetNode = GetTargetNode(sourceNode, action); IState targetIState = modelProgram.GetTargetState(sourceIState, action, transitionPropertyNames, out transitionProperties); //Console.WriteLine(sourceIState.ToString()); //Console.WriteLine ("--- " + action + " --->"); //Console.WriteLine (targetIState.ToString()); //Console.WriteLine(); //Console.WriteLine(); //if (this.modelProgram.IsAccepting(targetIState)) // this.acceptingNodes = this.acceptingNodes.Add(targetNode); //if (!this.modelProgram.SatisfiesStateInvariant(targetState)) // this.errorNodes = this.errorNodes.Add(targetNode); //IState isomorphicState; //Transition t; transCnt++; if (!visited.Contains(targetIState)) { frontier = frontier.Add(targetIState); visited = visited.Add(targetIState); stateCount++; //visited.Add(targetIState); //t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); } //else //{ // //if (collapseExcludedIsomorphicStates) // // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, nodeMap[isomorphicState]); // //else // { // Term isoNode = nodeMap[isomorphicState]; // t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); // if (!targetNode.Equals(sourceNode) && !targetNode.Equals(isoNode)) // groupingTransitions = groupingTransitions.Add(new Triple<Term, CompoundTerm, Term>(targetNode, new CompoundTerm(new Symbol("IsomorphicTo"), new Sequence<Term>()), isoNode)); // } //} //this.transitions = this.transitions.Add(t); //this.hiddenTransitions = this.hiddenTransitions.Remove(t); } } } } //Console.WriteLine("Checker results"); //Console.WriteLine("Reached states: "+stateCount); //Console.WriteLine("Number of transitions: "+transCnt); ReachabilityResult result = new ReachabilityResult(stateCount, transCnt); return(result); }