/// <summary> /// pass the index to make sure the current step is removed from the CurrentEnableEventList /// </summary> /// <param name="step"></param> private void MakeOneMove(EventStepSim step, int stepIndex) { if (WarningFlag) { if ( MessageBox.Show( Resources.The_execution_of_the_step_will_destroy_the_current_trace__Do_you_want_to_continue_, Resources.Warning, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } WarningFlag = false; int index = this.ListView_Trace.SelectedIndices[0]; while (this.ListView_Trace.Items.Count - 1 > index) { Traces.RemoveAt(this.ListView_Trace.Items.Count - 1); ListView_Trace.Items.RemoveAt(this.ListView_Trace.Items.Count - 1); } } if (this.ListView_Trace.SelectedIndices.Count > 0) { this.ListView_Trace.SelectedItems[0].Selected = false; } if(displayAllEnabledStatesToolStripMenuItem.Checked) { CurrentEnableEventList.RemoveAt(stepIndex); } else { CurrentEnableEventList.Clear(); } //CurrentEnableEventList.RemoveAt(stepIndex); //.Remove(step); //change all nodes to white node! foreach (Node mapN in g.NodeMap.Values) { mapN.Attr.FillColor = Color.White; } string stepString; //string nextState = step.ToFullString(); if (displayAllEnabledStatesToolStripMenuItem.Checked) { for (int i = 0; i < CurrentEnableEventList.Count; i++) { EventStepSim simStep = CurrentEnableEventList[i]; simStep.IsCurrentEvent = false; CurrentEnableEventList[i] = simStep; } } if (step.StepVisited(visited, out stepString)) { //Edge edge = g.AddEdge(step.SourceProcess, step.Event, stepString); //(g.NodeMap[stepString] as Node).Attr.FillColor = Color.Red; Node srcNode = g.FindNode(step.SourceProcess); Edge edge = null; foreach (Edge outEdge in srcNode.OutEdges) { if (outEdge.LabelText == step.Event && outEdge.Target == stepString) { //duplicate edge is found edge = outEdge; break; } } if (edge == null) { foreach (Edge outEdge in srcNode.SelfEdges) { if (outEdge.LabelText == step.Event && outEdge.Target == stepString) { //duplicate edge is found edge = outEdge; break; } } } if (edge == null) { edge = g.AddEdge(step.SourceProcess, step.Event, stepString); } edge.TargetNode.Attr.FillColor = Color.Red; AddToTrace(edge.SourceNode.LabelText, step, edge.TargetNode.LabelText, stepString); if (displayAllEnabledStatesToolStripMenuItem.Checked) { for (int i = 0; i < CurrentEnableEventList.Count; i++) { EventStepSim simStep = CurrentEnableEventList[i]; if (simStep.SourceProcess == stepString) { simStep.IsCurrentEvent = true; CurrentEnableEventList[i] = simStep; } } } List<EventStepSim> list = step.MakeOneMove(HideTauTransition); for (int i = 0; i < list.Count; i++) { EventStepSim s = list[i]; s.SourceProcess = stepString; s.IsUnvisitedStep = true; foreach (Edge outEdge in edge.TargetNode.OutEdges) { if (outEdge.LabelText == s.Event && outEdge.Target == s.StepID) { s.IsUnvisitedStep = false; break; } } if (s.IsUnvisitedStep) { foreach (Edge outEdge in edge.TargetNode.SelfEdges) { if (outEdge.LabelText == s.Event && outEdge.Target == stepString) { s.IsUnvisitedStep = false; break; } } } list[i] = s; } CurrentEnableEventList.AddRange(list); } else { visited.Add(stepString, null); //add the new node and set it to red. Node n = g.AddNode(stepString); n.LabelText = (g.NodeCount - 1).ToString(); n.UserData = step; // nextState; n.Attr.FillColor = Color.Red; Edge edge = g.AddEdge(step.SourceProcess, step.Event, stepString); AddToTrace(edge.SourceNode.LabelText, step, n.LabelText, stepString); List<EventStepSim> list = step.MakeOneMove(HideTauTransition); for (int i = 0; i < list.Count; i++) { EventStepSim s = list[i]; s.SourceProcess = stepString; s.IsUnvisitedStep = true; foreach (Edge outEdge in edge.TargetNode.OutEdges) { if (outEdge.LabelText == s.Event && outEdge.Target == s.StepID) { s.IsUnvisitedStep = false; break; } } if (s.IsUnvisitedStep) { foreach (Edge outEdge in edge.TargetNode.SelfEdges) { if (outEdge.LabelText == s.Event && outEdge.Target == stepString) { s.IsUnvisitedStep = false; break; } } } list[i] = s; } CurrentEnableEventList.AddRange(list); } SimulatorViewer.Graph = g; SimulatorViewer.Invalidate(); string key = GetTraceEvent(this.ListView_Trace.Items.Count) + stepString; if (!Mapping.ContainsKey(key)) { Mapping.Add(key, new ProcessData(step, CloneGraph(g), CloneEnabledEvent())); } UpdateStore(step); FillCurrentEnabledList(); }
private void AddCounterExamplePrefixPathNode(ref string sourceProcess, ConfigurationBase stepOld, bool firstSCC) { Node n = null; Edge edge = null; //EventStepSim fromStep = CounterExampleTrace[j-1]; EventStepSim step = new EventStepSim(stepOld); step.SourceProcess = sourceProcess; //change all nodes to white node! foreach (Node mapN in g.NodeMap.Values) { if (mapN.Attr.FillColor == Color.Red) { mapN.Attr.FillColor = Color.White; } } string stepString; ////string nextState = step.ToFullString(); if (step.StepVisited(visited, out stepString)) { Node srcNode = g.FindNode(step.SourceProcess); edge = null; foreach (Edge outEdge in srcNode.OutEdges) { if (outEdge.LabelText == step.Event && outEdge.Target == stepString) { //duplicate edge is found edge = outEdge; break; } } if (edge == null) { edge = g.AddEdge(step.SourceProcess, step.Event, stepString); } n = edge.TargetNode; // g.NodeMap[stepString] as Node; AddToTrace(edge.SourceNode.LabelText, step, edge.TargetNode.LabelText, stepString); } else { visited.Add(stepString, null); //add the new node and set it to red. n = g.AddNode(stepString); n.LabelText = (g.NodeCount - 1).ToString(); n.UserData = step; //// nextState; edge = g.AddEdge(step.SourceProcess, step.Event, stepString); AddToTrace(edge.SourceNode.LabelText, step, n.LabelText, stepString); } if (firstSCC) { n.Attr.FillColor = Color.LightGreen; } else { n.Attr.FillColor = Color.Red; } sourceProcess = stepString; string key = GetTraceEvent(this.ListView_Trace.Items.Count) + stepString; if (!Mapping.ContainsKey(key)) { Mapping.Add(key, new ProcessData(step, CloneGraph(g), CloneEnabledEvent())); } UpdateStore(step); }
private void DisplayCounterExample() { if (CanGrabLock()) { DisableControls(); try { int LoopIndex = 0; if (Assertion is AssertionLTL && Assertion.VerificationOutput.LoopIndex >= 0) { LoopIndex = Assertion.VerificationOutput.LoopIndex; } SimulationInitialize(false); this.CurrentEnableEventList.Clear(); this.ListView_EnabledEvents.Items.Clear(); if (Button_DisplayCounterexample.Checked) { string sourceProcess = InitialState; for (int j = 1; j < Assertion.VerificationOutput.CounterExampleTrace.Count; j++) { Node n = null; Edge edge = null; //EventStepSim fromStep = CounterExampleTrace[j-1]; ConfigurationBase stepOld = Assertion.VerificationOutput.CounterExampleTrace[j]; EventStepSim step = new EventStepSim(stepOld); step.SourceProcess = sourceProcess; string stepString; if (step.StepVisited(visited, out stepString)) { //take out the duplicated edges //bool hasMatch = false; Edge matchEdge = null; foreach (Edge e1 in g.Edges) { if (e1.Source == step.SourceProcess && e1.Target == stepString && e1.LabelText == step.Event && e1.Attr.Color == Color.DarkOrange) { //hasMatch = true; matchEdge = e1; break; } } if (matchEdge == null) { edge = g.AddEdge(step.SourceProcess, step.Event, stepString); n = g.NodeMap[stepString] as Node; AddToTrace(edge.SourceNode.LabelText, step, edge.TargetNode.LabelText, stepString); } else { edge = matchEdge; n = edge.TargetNode; AddToTrace(edge.SourceNode.LabelText, step, edge.TargetNode.LabelText, stepString); sourceProcess = stepString; //continue; } } else { visited.Add(stepString, null); //add the new node and set it to red. n = g.AddNode(stepString); n.LabelText = (g.NodeCount - 1).ToString(); n.UserData = step; //// step.ToFullString(); edge = g.AddEdge(step.SourceProcess, step.Event, stepString); AddToTrace(edge.SourceNode.LabelText, step, n.LabelText, stepString); } sourceProcess = stepString; string key = GetTraceEvent(this.ListView_Trace.Items.Count) + stepString; //states in SCC are yellow colored. if (LoopIndex > 0 && j >= LoopIndex) { edge.Label.FontColor = Color.DarkOrange; edge.Attr.Color = Color.DarkOrange; n.Attr.FillColor = Color.Yellow; } else { //change all nodes to white node! foreach (Node mapN in g.NodeMap.Values) { if (mapN.Attr.FillColor == Color.Red) { mapN.Attr.FillColor = Color.White; } } //the last node of the path is inside SCC, which should be in yellow color! if (LoopIndex > 0 && j == LoopIndex - 1) { n.Attr.FillColor = Color.Yellow; } else { n.Attr.FillColor = Color.Red; } } if (!Mapping.ContainsKey(key)) { Mapping.Add(key, new ProcessData(step, CloneGraph(g), CloneEnabledEvent())); } UpdateStore(step); } SimulatorViewer.Graph = g; SimulatorViewer.Invalidate(); } //else //{ // List<string> FairSCC = (Assertion as AssertionLTL).FairSCC; // Dictionary<int, EventBAPair> SCC2EventStepMapping = (Assertion as AssertionLTL).SCC2EventStepMapping; // Dictionary<int, List<int>> OutgoingTransitionTable = // (Assertion as AssertionLTL).OutgoingTransitionTable; // string sourceProcess = InitialState; // //print out the prefix path, and mark the last node as green color (inside SCC) // for (int j = 1; j < LoopIndex; j++) // { // AddCounterExamplePrefixPathNode(ref sourceProcess, Assertion.VerificationOutput.CounterExampleTrace[j], // j == LoopIndex - 1); // } // for (int i = 0; i < FairSCC.Count; i++) // { // Node n = null; // Edge edge = null; // //get sourceProcess of the current SCC node // ConfigurationBase stepSJ = SCC2EventStepMapping[FairSCC[i]].configuration; // EventStepSim stepSJSJ = new EventStepSim(stepSJ); // stepSJSJ.StepVisited(visited, out sourceProcess); // //check all the transitions // List<int> outgoing = OutgoingTransitionTable[FairSCC[i]]; // for (int j = 0; j < outgoing.Count; j++) // { // int w = outgoing[j]; // if (FairSCC.Contains(w)) // { // ConfigurationBase stepOld = SCC2EventStepMapping[w].configuration; // EventStepSim step = new EventStepSim(stepOld); //.Process, stepOld.Event, stepOld.HidenEvent, stepOld.GlobalEnv // step.SourceProcess = sourceProcess; // string stepString; // //string nextState = step.StepToString; // if (step.StepVisited(visited, out stepString)) // { // //ignore the transition which is in side the graph already! // bool hasMatch = false; // foreach (Edge e1 in g.Edges) // { // if (e1.Source == sourceProcess && e1.Target == stepString && // e1.LabelText == step.Event && e1.Attr.Color == Color.DarkGreen) // { // hasMatch = true; // break; // } // } // if (!hasMatch) // { // //liuyang added code for the bug start // //this is really a special case, where the hidden events are different for the last tau step // if (step.Config.Event == Constants.TAU) // { // //ConfigurationBase[] steps = CounterExampleTrace[i - 1].MakeOneMove(); // List<EventStepSim> steps = ((g.NodeMap[sourceProcess] as Node).UserData as EventStepSim).MakeOneMove(false); // foreach (EventStepSim istep in steps) // { // if (istep.StepID == stepString) // { // step = istep; // break; // } // } // } // edge = g.AddEdge(sourceProcess, step.Event, stepString); // //liuyang added code for the bug end // n = g.NodeMap[stepString] as Node; // AddToTrace(edge.SourceNode.LabelText, step, edge.TargetNode.LabelText, stepString); // } // else // { // continue; // } // } // else // { // visited.Add(stepString, null); // //add the new node and set it to red. // n = g.AddNode(stepString); // n.LabelText = (g.NodeCount - 1).ToString(); // n.UserData = step; //// nextState; // edge = g.AddEdge(sourceProcess, step.Event, stepString); // AddToTrace(edge.SourceNode.LabelText, step, n.LabelText, stepString); // } // //set the current node to be Green // edge.Label.FontColor = Color.DarkGreen; // edge.Attr.Color = Color.DarkGreen; // n.Attr.FillColor = Color.LightGreen; // string key = GetTraceEvent(this.ListView_Trace.Items.Count) + stepString; // if (!Mapping.ContainsKey(key)) // { // Mapping.Add(key, // new ProcessData(step, CloneGraph(g), CloneEnabledEvent())); // } // UpdateStore(step); // } // } // } // SimulatorViewer.Graph = g; // SimulatorViewer.Invalidate(); //} StatusLabel.Text = string.Format(Resources.Graph_Generated___0__Nodes___1__Edges, (g.NodeCount - 1), (g.EdgeCount - 1)); this.CurrentEnableEventList.Clear(); this.ListView_EnabledEvents.Items.Clear(); EnableControls(); } catch (Exception ex) { PrintErrorMsg(ex); } } }