internal ExploredTransitions(ModelProgram modelProgram, int initTransitions, int maxTransitions) { this.modelProgram = modelProgram; this.transitions = Set <Transition> .EmptySet; this.groupingTransitions = Set <Transition> .EmptySet; Node initNode = new Literal(0); this.initialNode = initNode; this.nodes = new Set <Node>(initNode); this.acceptingNodes = (modelProgram.IsAccepting(modelProgram.InitialState) ? new Set <Node>(initNode) : Set <Node> .EmptySet); //this.errorNodes = (!modelProgram.SatisfiesStateInvariant(modelProgram.InitialState) ? // new Set<Node>(initNode) : // Set<Node>.EmptySet); Dictionary <Node, IState> initialStateMap = new Dictionary <Node, IState>(); initialStateMap[initNode] = modelProgram.InitialState; this.stateMap = initialStateMap; actionsExploredFromNode = new Dictionary <Node, Dictionary <CompoundTerm, Node> >(); Dictionary <IState, Node> initialNodeMap = new Dictionary <IState, Node>(); initialNodeMap[modelProgram.InitialState] = initNode; this.nodeMap = initialNodeMap; this.hiddenTransitions = Set <Transition> .EmptySet; this.maxTransitions = maxTransitions; this.initTransitions = initTransitions; }
internal MapletViewer(Term k, Term t, bool isBagEntry) { this.keyName = "Entry"; this.t = t; this.k = k; this.argumentViewers = new TermViewer[2]; this.argumentViewers[0] = TermViewer.Create((isBagEntry ? "Element" : "Key"), k); this.argumentViewers[1] = TermViewer.Create((isBagEntry ? "Multiplicity" : "Value"), t); }
static Coin GetCoin(Term t) { if (t.ToString().Equals("Coin(\"Nickel\")")) return Coin.Nickel; else if (t.ToString().Equals("Coin(\"Dime\")")) return Coin.Dime; else throw new ArgumentException("Unrecognized coin: " + t.ToString()); }
/// <summary> /// Show all transitions from the given node /// </summary> internal void ShowOutgoing(Node node) { foreach (Symbol aSymbol in this.modelProgram.PotentiallyEnabledActionSymbols(stateMap[node])) { foreach (CompoundTerm a in this.modelProgram.GetActions(stateMap[node], aSymbol)) { this.ShowTransition(node, a); } } }
/// <summary> /// Show the transition with the given action from the given state /// </summary> internal void ShowTransition(Node sourceNode, CompoundTerm action) { Node targetNode; if (TryGetTargetNode(sourceNode, action, out targetNode)) { Transition t = new Triple <Term, CompoundTerm, Term>(sourceNode, action, targetNode); this.transitions = this.transitions.Add(t); this.hiddenTransitions = this.hiddenTransitions.Remove(t); } }
// This method has side effects on this.stateMap, this.nodeMap, this.nodes, this.acceptingNodes, this.actionsExploredFromNode private bool TryGetTargetNode(Node sourceNode, CompoundTerm action, out Node targetNode) { IState targetState; if (this.actionsExploredFromNode.ContainsKey(sourceNode)) { if (!this.actionsExploredFromNode[sourceNode].TryGetValue(action, out targetNode)) { //this action has not been explored yet from the given node TransitionProperties transitionProperties; targetState = this.modelProgram.GetTargetState(stateMap[sourceNode], action, Set <string> .EmptySet, out transitionProperties); if (!this.nodeMap.TryGetValue(targetState, out targetNode)) { targetNode = new Literal(this.nodes.Count); this.stateMap[targetNode] = targetState; this.nodeMap[targetState] = targetNode; this.nodes = this.nodes.Add(targetNode); if (this.modelProgram.IsAccepting(targetState)) { this.acceptingNodes = this.acceptingNodes.Add(targetNode); } //if (!this.modelProgram.SatisfiesStateInvariant(targetState)) // this.errorNodes = this.errorNodes.Add(targetNode); } } else { targetState = this.stateMap[targetNode]; } } else //the state has not yet been explored at all { TransitionProperties transitionProperties; targetState = this.modelProgram.GetTargetState(stateMap[sourceNode], action, Set <string> .EmptySet, out transitionProperties); if (!this.nodeMap.TryGetValue(targetState, out targetNode)) { targetNode = new Literal(this.nodes.Count); this.stateMap[targetNode] = targetState; this.nodeMap[targetState] = targetNode; this.nodes = this.nodes.Add(targetNode); if (this.modelProgram.IsAccepting(targetState)) { this.acceptingNodes = this.acceptingNodes.Add(targetNode); } //if (!this.modelProgram.SatisfiesStateInvariant(targetState)) // this.errorNodes = this.errorNodes.Add(targetNode); } Dictionary <CompoundTerm, Node> actionsFromState = new Dictionary <CompoundTerm, Node>(); actionsFromState[action] = targetNode; this.actionsExploredFromNode[sourceNode] = actionsFromState; } return(this.modelProgram.SatisfiesStateFilter(targetState)); }
/// <summary> /// Hide all previously shown transitions from the given node /// and those that can be reached recursively /// </summary> internal void HideReachable(Node node) { Set <Transition> alltransitions = this.hiddenTransitions.Union(this.transitions); Set <Node> frontier = new Set <Term>(node); Set <Node> visited = frontier; Set <Transition> tobehidden = Set <Transition> .EmptySet; while (!frontier.IsEmpty) { Node n = frontier.Choose(0); frontier = frontier.Remove(n); Set <Transition> toBeHiddenTransitions = alltransitions.Select(delegate(Transition t) { return(t.First.Equals(n)); }); Set <Node> targetStates = toBeHiddenTransitions.Convert <Node>(delegate(Transition t) { return(t.Third); }); frontier = frontier.Union(targetStates.Difference(visited)); visited = visited.Union(targetStates); tobehidden = tobehidden.Union(toBeHiddenTransitions); } this.hiddenTransitions = this.hiddenTransitions.Union(tobehidden); this.transitions = this.transitions.Difference(tobehidden); }
/// <summary> /// Hide all previously shown transitions from the given node /// </summary> /// <param name="node">given node</param> internal void HideOutgoing(Node node) { this.hiddenTransitions = this.hiddenTransitions.Union(this.transitions.Select(delegate(Transition t) { return t.First.Equals(node); })); this.transitions = this.transitions.Difference(this.hiddenTransitions); }
internal IState GetModelState(Node state) { return stateMap[state]; }
internal IEnumerable<CompoundTerm> GetEnabledActions(Node node, Symbol actionSymbol) { IState istate = stateMap[node]; return modelProgram.GetActions(istate, actionSymbol); }
public static Sequence<Sequence<CompoundTerm>> GenerateTestSequences(FSM fa) { //Eliminate dead states from the fa Set<Term> deadStates = GetDeadStates(fa); Set<Term> aliveStates = fa.States.Difference(deadStates); Set<Triple<Term, CompoundTerm, Term>> aliveTransitions = fa.Transitions.Select(delegate(Triple<Term, CompoundTerm, Term> trans) { return aliveStates.Contains(trans.First) && aliveStates.Contains(trans.Third); }); if (aliveTransitions.IsEmpty) //test suite cannot be generated return Sequence<Sequence<CompoundTerm>>.EmptySequence; //Build a graph from the alive transitions Term[] states = new Term[aliveStates.Count]; Dictionary<Term, int> stateToVertexMap = new Dictionary<Term, int>(); states[0] = fa.InitialState; stateToVertexMap[fa.InitialState] = 0; int i = 1; foreach (Term state in aliveStates.Remove(fa.InitialState)) { states[i] = state; stateToVertexMap[state] = i++; } //create edges that must be traversed GraphTraversals.Edge[] mustEdges = new GraphTraversals.Edge[aliveTransitions.Count]; Triple<Term, CompoundTerm, Term>[] mustTransitions = new Triple<Term, CompoundTerm, Term>[aliveTransitions.Count]; i = 0; foreach (Triple<Term, CompoundTerm, Term> trans in aliveTransitions) { GraphTraversals.Edge edge = new GraphTraversals.Edge(stateToVertexMap[trans.First], stateToVertexMap[trans.Third], i); mustEdges[i] = edge; mustTransitions[i++] = trans; } //add an optional edge with label -1 from every accepting state //to the initial state, this corresponds to a reset action GraphTraversals.Edge[] optionalEdges = new GraphTraversals.Edge[fa.AcceptingStates.Count]; i = 0; foreach (Term accState in fa.AcceptingStates) { int accVertex = stateToVertexMap[accState]; optionalEdges[i++] = new GraphTraversals.Edge(accVertex, 0, -1); //-1 = reset } //at this point it is known that g is strongly connected and has no dead states //so a postman tour exists, compute a postman tour GraphTraversals.Graph g = new GraphTraversals.Graph(0, mustEdges, optionalEdges, GraphTraversals.WeakClosureEnum.DoNotClose); List<GraphTraversals.Edge> postmanTour = new List<GraphTraversals.Edge>(g.GetRuralChinesePostmanTour()); #region normalize the tour so that it ends in an accepting state and has a reset at the end as a "watchdog" //if the last edge has not label -1, i.e. the edge leading back //to the initial state is not a reset edge from an accepting state //and the last state is not an accepting state //then extend the path to an accepting state, from the beginning of the path //notice that there must be at least one accepting state, so such an extesion //is indeed possible GraphTraversals.Edge lastEdge = postmanTour[postmanTour.Count - 1]; if (lastEdge.label >= 0) //if the last edge is a reset, we are done { //the last edge leads back to the initial state, because this is a tour if (fa.AcceptingStates.Contains(fa.InitialState)) postmanTour.Add(new GraphTraversals.Edge(0, 0, -1)); //add a watchdog else { //create an extesion to the tour from the initial state to the first accepting state List<GraphTraversals.Edge> extension = new List<GraphTraversals.Edge>(); foreach (GraphTraversals.Edge edge in postmanTour) { extension.Add(edge); if (fa.AcceptingStates.Contains(states[edge.target])) { //the end state of the edge is accepting, so we are done extension.Add(new GraphTraversals.Edge(0, 0, -1)); //add a watchdog break; } } postmanTour.AddRange(extension); } } #endregion #region break up the tour into sequences of transition ids separated by the reset edge List<List<int>> paths = new List<List<int>>(); List<int> path = new List<int>(); for (int k = 0; k < postmanTour.Count; k++) { //presense of the watchdog at the end of the tour is assumed here GraphTraversals.Edge edge = postmanTour[k]; if (edge.label < 0) //encountered reset, end of path { paths.Add(path); path = new List<int>(); } else { path.Add(edge.label); } } #endregion #region map the paths into action sequences Sequence<Sequence<CompoundTerm>> res = Sequence<Sequence<CompoundTerm>>.EmptySequence; foreach (List<int> path1 in paths) { Sequence<CompoundTerm> transSeq = Sequence<CompoundTerm>.EmptySequence; foreach (int transId in path1) transSeq = transSeq.AddLast(mustTransitions[transId].Second); res = res.AddLast(transSeq); } #endregion return res; }
static CompoundTerm GetActionTerm(string actionString, string[] defaultArguments, bool mustUseAllNames, Set<string> optionalArguments) { Set<string> possibleArguments = new Set<string>(defaultArguments).Union(optionalArguments); if (actionString.Contains("(") || actionString.Contains(")")) { try { Term t = Term.Parse(actionString); CompoundTerm ct = t as CompoundTerm; if (null == ct) throw new ModelProgramUserException("invalid action label syntax: " + actionString); Set<string> unusedArguments = GetUnusedArguments(possibleArguments, ct); Set<string> missingArguments = (mustUseAllNames ? unusedArguments.Difference(optionalArguments) : Set<string>.EmptySet); if (mustUseAllNames && !missingArguments.IsEmpty) throw new ModelProgramUserException("action label " + actionString + " is missing required argument(s). Missing value(s) are: " + missingArguments.ToString()); if (mustUseAllNames) CheckForDuplicateArgument(ct); return ct; } catch (ArgumentException e) { throw new ModelProgramUserException("invalid action label syntax: " + actionString + ". Could not parse term: " + e.Message); } } else { int arity = defaultArguments.Length; Term[] args = new Term[arity]; for (int i = 0; i < arity; i += 1) args[i] = new Variable(defaultArguments[i]); return new CompoundTerm(new Symbol(actionString), args); } }
/// <summary> /// Hide the transition with the given action from the given node /// </summary> internal void HideTransition(Node node, CompoundTerm action) { this.hiddenTransitions = this.hiddenTransitions.Union(this.transitions.Select(delegate(Transition t) { return(t.First.Equals(node) && t.Second.Equals(action)); })); this.transitions = this.transitions.Difference(this.hiddenTransitions); }
private void AddNodeLabel(StringBuilder sb, Node node, bool accepting) { sb.Append("\n "); AppendLabel(sb, node); if (this.customStateLabelProvider != null && this.finiteAutomatonContext.stateProvider != null) { sb.Append(" [label = "); AppendLabel(sb, this.customStateLabelProvider(this.finiteAutomatonContext.stateProvider(node))); if (accepting) sb.Append(", peripheries = 2"); sb.Append("]"); } else if (accepting) sb.Append(" [peripheries = 2]"); }
/// <summary> /// Add tooltip with state variables values /// /// </summary> /// <param name="sb"></param> /// <param name="node"></param> private void AddNodeTooltip(StringBuilder sb, Node node) { sb.Append("[tooltip = \""); // Create string for the tooltip StringBuilder sTooltip = new StringBuilder(); if (finiteAutomatonContext.stateProvider != null) sTooltip.Append( DefaultNodeTooltip(finiteAutomatonContext.stateProvider(node)) ); else sTooltip.Append("//Variables in state " + node.ToString() + " are undefined"); // Remove quotes in sTooltip sTooltip.Replace("\"", ""); sb.Append(sTooltip); sb.Append("\"];"); // Remove the last 3 dots at the end of a line in sb //sb.Replace(" . . . \"", "\""); }
static bool IsStartAction(Term action) { CompoundTerm a = action as CompoundTerm; if (a == null) return false; // return Symbol.Kind(a.FunctionSymbol1) == ActionKind.Start; return a.Symbol.Name.EndsWith("_Start"); }
private void AddNodeLabel(StringBuilder sb, Node node) { sb.Append("\n "); AppendLabel(sb, node); if (this.customStateLabelProvider != null && this.finiteAutomatonContext.stateProvider != null) { sb.Append(" [label = "); AppendLabel(sb, this.customStateLabelProvider(this.finiteAutomatonContext.stateProvider(node))); sb.Append("]"); } }
static bool IsFinishAction(Term action, string name) { CompoundTerm a = action as CompoundTerm; if (a == null) return false; return IsFinishAction(action) && a.Symbol.Name == name + "_Finish"; }
static bool IsFinishAction(Term action) { CompoundTerm a = action as CompoundTerm; if (a == null) return false; // return Symbol.Kind(a.FunctionSymbol1) == ActionKind.Finish ; return a.Symbol.Name.EndsWith("_Finish"); }
Term PopStackFrame(Term controlMode) { Sequence<CompoundTerm> stack = (Sequence<CompoundTerm>)context.InterpretTerm(controlMode); if (stack.IsEmpty) throw new ArgumentException("Internal error-- attempt to pop empty control mode stack"); else return AbstractValue.GetTerm(stack.Tail); }
/// <summary> /// Hide the transition with the given action from the given node /// </summary> internal void HideTransition(Node node, CompoundTerm action) { this.hiddenTransitions = this.hiddenTransitions.Union(this.transitions.Select(delegate(Transition t) { return t.First.Equals(node) && t.Second.Equals(action); })); this.transitions = this.transitions.Difference(this.hiddenTransitions); }
Set<Term> GetAutomatonParameterDomain(Term startState, Symbol actionSymbol, int parameterIndex) { Set<Term> result = Set<Term>.EmptySet; Set<Transition> outgoing = this.automaton.OutgoingTransitions(startState); foreach (Transition transition in outgoing) { CompoundTerm ct = transition.Second as CompoundTerm; if (ct == null || parameterIndex >= ActionArity(actionSymbol)) throw new InvalidOperationException("Internal error"); if (actionSymbol.Equals(ct.Symbol)) result = result.Add(ct.Arguments[parameterIndex]); } return result; }
internal IState GetState(Term newControlMode) { Term[] vals = new Term[this.stateFields.Length]; for (int i = 0; i < vals.Length; i++) { IComparable/*?*/ val = this.stateFields[i].GetValue(this.context); vals[i] = AbstractValue.GetTerm(val); } return SimpleState.CreateState(newControlMode, vals, context.IdPool, this.name, this.locationNames); }
/// <summary> /// Hide all previously shown transitions from the given node /// </summary> /// <param name="node">given node</param> internal void HideOutgoing(Node node) { this.hiddenTransitions = this.hiddenTransitions.Union(this.transitions.Select(delegate(Transition t) { return(t.First.Equals(node)); })); this.transitions = this.transitions.Difference(this.hiddenTransitions); }
internal IState GetModelState(Node state) { return(stateMap[state]); }
/// <summary> /// Hide all previously shown transitions with te given action symbol from the given node /// </summary> internal void HideAll(Node node, Symbol actionSymbol) { this.hiddenTransitions = this.hiddenTransitions.Union(this.transitions.Select(delegate(Transition t) { return(t.First.Equals(node) && ((CompoundTerm)t.Second).Symbol.Equals(actionSymbol)); })); this.transitions = this.transitions.Difference(this.hiddenTransitions); }
internal Set <Symbol> GetEnabledActionSymbols(Node node) { IState istate = stateMap[node]; return(modelProgram.PotentiallyEnabledActionSymbols(istate)); }
void viewer_RightClick(object sender, MouseEventArgs e)//+++ { //notice that the context menu is possible only in the root view //i.e. when reduct of the fa in the current context has the empty tree position if (e.Button == MouseButtons.Right && this.finiteAutomatonContext.reductName.treePosition.IsEmpty) { if (viewer.SelectedObject is GraphLayout.Drawing.Node && this.exploredTransitions != null) { GraphLayout.Drawing.Node currentGleeNode = viewer.SelectedObject as GraphLayout.Drawing.Node; //populate the context menu with actions that can be explored Node currentNode = this.nodes[currentGleeNode]; Map <Symbol, Sequence <CompoundTerm> > enabledActions = Map <Symbol, Sequence <CompoundTerm> > .EmptyMap; foreach (Symbol actionSymbol in this.exploredTransitions.GetEnabledActionSymbols(currentNode)) { Sequence <CompoundTerm> actions = new Sequence <CompoundTerm>(this.exploredTransitions.GetEnabledActions(currentNode, actionSymbol)); if (actions.Count > 0) { enabledActions = enabledActions.Add(actionSymbol, actions); } } bool someSymbolIsVisible = false; bool allSymbolsAreFullyVisible = true; //populate and show the expand context menu, one per action symbol List <ToolStripMenuItem> expandItems = new List <ToolStripMenuItem>(enabledActions.Count); foreach (Pair <Symbol, Sequence <CompoundTerm> > entry in enabledActions) { ToolStripMenuItem expandItem = new ToolStripMenuItem(entry.First.FullName); //expandItem.Tag = new Pair<Node, Sequence<CompoundTerm>>(currentNode, entry.Second); //expandItem.Click += new EventHandler(actionSymbol_Click); expandItem.DisplayStyle = ToolStripItemDisplayStyle.Text; //expandItem.CheckOnClick = false; ToolStripMenuItem[] subitems = new ToolStripMenuItem[entry.Second.Count]; bool someActionIsVisible = false; bool allActionsAreVisible = true; for (int i = 0; i < subitems.Length; i++) { subitems[i] = new ToolStripMenuItem(entry.Second[i].ToCompactString()); subitems[i].Tag = new Pair <Node, CompoundTerm>(currentNode, entry.Second[i]); subitems[i].Click += new EventHandler(action_Click); subitems[i].DisplayStyle = ToolStripItemDisplayStyle.Text; subitems[i].CheckOnClick = false; if (this.exploredTransitions.IsActionVisible(currentNode, entry.Second[i])) { subitems[i].Checked = true; subitems[i].ToolTipText = "Uncheck to hide"; someActionIsVisible = true; someSymbolIsVisible = true; } else { subitems[i].Checked = false; subitems[i].ToolTipText = "Check to show"; allActionsAreVisible = false; allSymbolsAreFullyVisible = false; } } if (allActionsAreVisible) { expandItem.CheckState = CheckState.Checked; } else if (someActionIsVisible) { expandItem.CheckState = CheckState.Indeterminate; } else { expandItem.CheckState = CheckState.Unchecked; } //if (expandItem.CheckState == CheckState.Checked) // expandItem.ToolTipText = "Uncheck to hide all " + entry.First.FullName + " transitions from selected state"; //else // expandItem.ToolTipText = "Check to show all " + entry.First.FullName + " transitions from selected state"; //add a menu item to hide all actions #region showAll - menu item to show all actions ToolStripMenuItem showAll = new ToolStripMenuItem("Show All"); showAll.Tag = new Pair <Node, Sequence <CompoundTerm> >(currentNode, entry.Second); showAll.DisplayStyle = ToolStripItemDisplayStyle.Text; showAll.CheckOnClick = false; showAll.Checked = false; showAll.Click += new EventHandler(showAll_Click); #endregion #region hideAll - menu item to hide all actions ToolStripMenuItem hideAll = new ToolStripMenuItem("Hide All"); hideAll.Tag = new Pair <Node, Symbol>(currentNode, entry.First); hideAll.DisplayStyle = ToolStripItemDisplayStyle.Text; hideAll.CheckOnClick = false; hideAll.Checked = false; hideAll.Click += new EventHandler(hideAll_Click); #endregion expandItem.DropDownItems.AddRange(subitems); expandItem.DropDownItems.Add(new ToolStripSeparator()); expandItem.DropDownItems.Add(showAll); expandItem.DropDownItems.Add(hideAll); expandItems.Add(expandItem); } this.expandToolStripMenuItem.DropDownItems.Clear(); this.expandToolStripMenuItem.DropDownItems.AddRange(expandItems.ToArray()); if (allSymbolsAreFullyVisible) { this.expandToolStripMenuItem.CheckState = CheckState.Checked; } else if (someSymbolIsVisible) { this.expandToolStripMenuItem.CheckState = CheckState.Indeterminate; } else { this.expandToolStripMenuItem.CheckState = CheckState.Unchecked; } this.exploreContextMenuStrip.Show(this.viewer, e.Location); } } }
internal IEnumerable <CompoundTerm> GetEnabledActions(Node node, Symbol actionSymbol) { IState istate = stateMap[node]; return(modelProgram.GetActions(istate, actionSymbol)); }
internal ExploredTransitions(ModelProgram modelProgram, int initTransitions, int maxTransitions) { this.modelProgram = modelProgram; this.transitions = Set<Transition>.EmptySet; this.groupingTransitions = Set<Transition>.EmptySet; Node initNode = new Literal(0); this.initialNode = initNode; this.nodes = new Set<Node>(initNode); this.acceptingNodes = (modelProgram.IsAccepting(modelProgram.InitialState) ? new Set<Node>(initNode) : Set<Node>.EmptySet); //this.errorNodes = (!modelProgram.SatisfiesStateInvariant(modelProgram.InitialState) ? // new Set<Node>(initNode) : // Set<Node>.EmptySet); Dictionary<Node, IState> initialStateMap = new Dictionary<Node, IState>(); initialStateMap[initNode] = modelProgram.InitialState; this.stateMap = initialStateMap; actionsExploredFromNode = new Dictionary<Node, Dictionary<CompoundTerm,Node>>(); Dictionary<IState, Node> initialNodeMap = new Dictionary<IState, Node>(); initialNodeMap[modelProgram.InitialState] = initNode; this.nodeMap = initialNodeMap; this.hiddenTransitions = Set<Transition>.EmptySet; this.maxTransitions = maxTransitions; this.initTransitions = initTransitions; }
/// <summary> /// Returns true if the action is a label of a visible transition from the given node /// </summary> internal bool IsActionVisible(Node node, CompoundTerm action) { return(this.transitions.Exists(delegate(Transition t) { return t.First.Equals(node) && t.Second.Equals(action); })); }
internal Set<Symbol> GetEnabledActionSymbols(Node node) { IState istate = stateMap[node]; return modelProgram.PotentiallyEnabledActionSymbols(istate); }
/// <summary> /// Show the transition with the given action from the given state /// </summary> internal void ShowTransition(Node sourceNode, CompoundTerm action) { Node targetNode; if (TryGetTargetNode(sourceNode, action, out targetNode)) { Transition t = new Triple<Term, CompoundTerm, Term>(sourceNode, action, targetNode); this.transitions = this.transitions.Add(t); this.hiddenTransitions = this.hiddenTransitions.Remove(t); } }
/// <summary> /// Hide all previously shown transitions with te given action symbol from the given node /// </summary> internal void HideAll(Node node, Symbol actionSymbol) { this.hiddenTransitions = this.hiddenTransitions.Union(this.transitions.Select(delegate(Transition t) { return t.First.Equals(node) && ((CompoundTerm)t.Second).Symbol.Equals(actionSymbol); })); this.transitions = this.transitions.Difference(this.hiddenTransitions); }
/// <summary> /// Interpret the term as a .NET value in this context /// </summary> public IComparable InterpretTerm(Term term) { Any a = term as Any; if (a != null) { return a; } Literal l = term as Literal; if (l != null) { return l.Value; } //IComparable result; CompoundTerm ct = term as CompoundTerm; if (ct != null) { Symbol sort = ct.Symbol; // Case 1: Quoted term. No evaluation needed if (quoteSymbol.Equals(sort)) { return ct.Arguments.Head; } // Case 2: reconstruct value from sort. else { int arity = ct.Arguments.Count; ValueConstructor ctor = GetValueConstructor(sort, arity); Sequence<IComparable> args = ct.Arguments.Convert<IComparable>(InterpretTerm); return ctor(args); } } throw new ArgumentException("Can't interpret term " + term.ToString()); }
/// <summary> /// Hide all previously shown transitions from the given node /// and those that can be reached recursively /// </summary> internal void HideReachable(Node node) { Set<Transition> alltransitions = this.hiddenTransitions.Union(this.transitions); Set<Node> frontier = new Set<Term>(node); Set<Node> visited = frontier; Set<Transition> tobehidden = Set<Transition>.EmptySet; while (!frontier.IsEmpty) { Node n = frontier.Choose(0); frontier = frontier.Remove(n); Set<Transition> toBeHiddenTransitions = alltransitions.Select(delegate(Transition t) { return t.First.Equals(n); }); Set<Node> targetStates = toBeHiddenTransitions.Convert<Node>(delegate(Transition t) { return t.Third; }); frontier = frontier.Union(targetStates.Difference(visited)); visited = visited.Union(targetStates); tobehidden = tobehidden.Union(toBeHiddenTransitions); } this.hiddenTransitions = this.hiddenTransitions.Union(tobehidden); this.transitions = this.transitions.Difference(tobehidden); }
/// <summary> /// Adds a new coverage point to the current context. /// </summary> /// <param name="coveragePoint">Term denoting a coverage point.</param> public void AddCoveragePoint(Term coveragePoint) { this.coveragePoints = this.coveragePoints.Add(coveragePoint); }
/// <summary> /// Returns true if the action is a label of a visible transition from the given node /// </summary> internal bool IsActionVisible(Node node, CompoundTerm action) { return this.transitions.Exists(delegate(Transition t) { return t.First.Equals(node) && t.Second.Equals(action); }); }
/// <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); } } } } } }
Term PushStackFrame(Term controlMode, CompoundTerm action) { Sequence<CompoundTerm> stack = (Sequence<CompoundTerm>)context.InterpretTerm(controlMode); Sequence<CompoundTerm> newStack = stack.AddFirst(action); return AbstractValue.GetTerm(newStack); }
// This method has side effects on this.stateMap, this.nodeMap, this.nodes, this.acceptingNodes, this.actionsExploredFromNode private bool TryGetTargetNode(Node sourceNode, CompoundTerm action, out Node targetNode) { IState targetState; if (this.actionsExploredFromNode.ContainsKey(sourceNode)) { if (!this.actionsExploredFromNode[sourceNode].TryGetValue(action, out targetNode)) { //this action has not been explored yet from the given node TransitionProperties transitionProperties; targetState = this.modelProgram.GetTargetState(stateMap[sourceNode], action, Set<string>.EmptySet, out transitionProperties); if (!this.nodeMap.TryGetValue(targetState, out targetNode)) { targetNode = new Literal(this.nodes.Count); this.stateMap[targetNode] = targetState; this.nodeMap[targetState] = targetNode; this.nodes = this.nodes.Add(targetNode); if (this.modelProgram.IsAccepting(targetState)) this.acceptingNodes = this.acceptingNodes.Add(targetNode); //if (!this.modelProgram.SatisfiesStateInvariant(targetState)) // this.errorNodes = this.errorNodes.Add(targetNode); } } else { targetState = this.stateMap[targetNode]; } } else //the state has not yet been explored at all { TransitionProperties transitionProperties; targetState = this.modelProgram.GetTargetState(stateMap[sourceNode], action, Set<string>.EmptySet, out transitionProperties); if (!this.nodeMap.TryGetValue(targetState, out targetNode)) { targetNode = new Literal(this.nodes.Count); this.stateMap[targetNode] = targetState; this.nodeMap[targetState] = targetNode; this.nodes = this.nodes.Add(targetNode); if (this.modelProgram.IsAccepting(targetState)) this.acceptingNodes = this.acceptingNodes.Add(targetNode); //if (!this.modelProgram.SatisfiesStateInvariant(targetState)) // this.errorNodes = this.errorNodes.Add(targetNode); } Dictionary<CompoundTerm, Node> actionsFromState = new Dictionary<CompoundTerm, Node>(); actionsFromState[action] = targetNode; this.actionsExploredFromNode[sourceNode] = actionsFromState; } return this.modelProgram.SatisfiesStateFilter(targetState); }
internal static bool TermNeedsNoBrowsing(Term t) { return t is Literal; //|| t.Arguments.Forall(delegate(Term s) { return s is Literal; }); }