public DcrGraph RemoveRedundancy(DcrGraph inputGraph, BackgroundWorker worker = null) { _worker = worker; #if DEBUG Console.WriteLine("Started redundancy removal:"); #endif //TODO: use an algorithm to check if the graph is connected and if not then recursively remove redundancy on the subgraphs. //temporarily remove flower activities. var copy = inputGraph.Copy(); var removedActivities = copy.GetActivities().Where(x => (x.Included && !copy.ActivityHasRelations(x))).ToList(); foreach (var a in removedActivities) { copy.RemoveActivity(a.Id); } var byteDcrGraph = new ByteDcrGraph(copy); _uniqueTraceFinder = new UniqueTraceFinder(byteDcrGraph); _originalInputDcrGraph = copy.Copy(); OutputDcrGraph = copy; // Remove relations and see if the unique traces acquired are the same as the original. If so, the relation is clearly redundant and is removed immediately // All the following calls potentially alter the OutputDcrGraph RemoveRedundantRelations(RelationType.Response); RemoveRedundantRelations(RelationType.Condition); RemoveRedundantRelations(RelationType.InclusionExclusion); RemoveRedundantRelations(RelationType.Milestone); foreach (var activity in OutputDcrGraph.GetActivities()) { var graphCopy = new ByteDcrGraph(byteDcrGraph); graphCopy.RemoveActivity(activity.Id); ReportProgress?.Invoke("Removing Activity " + activity.Id); // Compare unique traces - if equal activity is redundant if (_uniqueTraceFinder.CompareTraces(graphCopy)) { // The relation is redundant, replace copy with current copy (with the relation removed) OutputDcrGraph.RemoveActivity(activity.Id); } } foreach (var a in removedActivities) { OutputDcrGraph.AddActivity(a.Id, a.Name); OutputDcrGraph.SetIncluded(true, a.Id); OutputDcrGraph.SetPending(a.Pending, a.Id); } var nested = OutputDcrGraph.ExportToXml(); return OutputDcrGraph; }
private static Activity ParseActivity(DcrGraph graph, XDocument doc, XElement eve) { var nestedEvents = eve.Descendants("event").Where(element => element.HasElements).ToList(); //Only takes event elements in events! bool isNestedGraph = nestedEvents.Count > 0; // Retrieve Id var id = eve.Attribute("id").Value; // Retrieve Name: var name = (from labelMapping in doc.Descendants("labelMapping") where labelMapping.Attribute("eventId").Value.Equals(id) select labelMapping.Attribute("labelId").Value).FirstOrDefault(); // Check to see if Activity was already parsed if (graph.GetActivities().ToList().Exists(x => x.Id == id && x.Name == name)) return null; Activity activityToReturn; if (isNestedGraph) { var nestedActivities = new HashSet<Activity>(); foreach (var nestedEvent in nestedEvents) { nestedActivities.Add(ParseActivity(graph, doc, nestedEvent)); } activityToReturn = graph.MakeNestedGraph(id, name, nestedActivities); } else // Not a nested graph --> Treat as single activity { // Add activity to graph activityToReturn = graph.AddActivity(id, name); // Assigning Roles: var roles = eve.Descendants("role"); var rolesList = new List<string>(); foreach (var role in roles) { if (role.Value != "") graph.AddRolesToActivity(id,role.Value); } // Mark Included if ((from includedEvent in doc.Descendants("included").Elements() select includedEvent.FirstAttribute.Value).Contains(id)) graph.SetIncluded(true, id); // Mark Pending: if ((from pendingEvent in doc.Descendants("pendingResponses").Elements() select pendingEvent.FirstAttribute.Value).Contains(id)) graph.SetPending(true, id); // Mark Executed: if ((from executedEvent in doc.Descendants("executed").Elements() select executedEvent.FirstAttribute.Value).Contains(id)) graph.SetExecuted(true, id); } return activityToReturn; }
public void TestExportDcrGraphToXml() { var activities = new HashSet<Activity> { new Activity("A", "somename1"), new Activity("B", "somename2"), new Activity("C", "somename3") }; var graph = new DcrGraph(); foreach (var a in activities) { graph.AddActivity(a.Id, a.Name); } graph.SetIncluded(true, "A"); // Start at A graph.AddIncludeExclude(true, "A", "B"); graph.AddIncludeExclude(true, "A", "C"); graph.AddIncludeExclude(true, "B", "C"); graph.AddIncludeExclude(false, "C", "B"); graph.AddIncludeExclude(false, "A", "A"); graph.AddIncludeExclude(false, "B", "B"); graph.AddIncludeExclude(false, "C", "C"); Console.WriteLine(graph); var xml = graph.ExportToXml(); Console.WriteLine(xml); File.WriteAllText("E:/DCR2XML.xml", xml); Console.ReadLine(); }
public void TestFinalStateMisplacement() { var graph = new DcrGraph(); graph.AddActivity("A", "somename1"); graph.AddActivity("B", "somename2"); graph.AddActivity("C", "somename3"); graph.SetIncluded(true, "A"); // Start at A graph.AddIncludeExclude(true, "A", "B"); graph.AddIncludeExclude(true, "B", "C"); graph.AddIncludeExclude(false, "C", "B"); graph.AddResponse("B", "C"); // Self-excludes graph.AddIncludeExclude(false, "A", "A"); graph.AddIncludeExclude(false, "B", "B"); graph.AddIncludeExclude(false, "C", "C"); Console.WriteLine(graph); var graph2 = new RedundancyRemover().RemoveRedundancy(graph); Console.WriteLine(graph2); Console.ReadLine(); }
public void SomeTestForFindingTracesBeforeAfterStuff() { var dcr = new DcrGraph(); dcr.AddActivities(new Activity("A", "A"), new Activity("B", "B"), new Activity("C", "C")); dcr.AddCondition("A", "B"); dcr.AddCondition("A", "C"); dcr.AddCondition("B", "C"); dcr.SetIncluded(true, "A"); dcr.SetIncluded(true, "B"); dcr.SetIncluded(true, "C"); dcr.SetPending(true, "C"); var traceFinder = new UniqueTraceFinder(new ByteDcrGraph(dcr)); dcr = dcr.Copy(); dcr.RemoveCondition("A", "B"); traceFinder = new UniqueTraceFinder(new ByteDcrGraph(dcr)); }
public void TestCanActivityEverBeIncluded() { var graph = new DcrGraph(); graph.AddActivity("A", "somename1"); graph.AddActivity("B", "somename2"); graph.AddActivity("C", "somename3"); graph.AddActivity("D", "somename3"); graph.SetIncluded(true, "A"); // Start at A graph.AddIncludeExclude(true, "A", "B"); graph.AddIncludeExclude(true, "B", "C"); graph.AddIncludeExclude(false, "C", "B"); graph.AddResponse("B", "C"); // Self-excludes graph.AddIncludeExclude(false, "A", "A"); graph.AddIncludeExclude(false, "B", "B"); graph.AddIncludeExclude(false, "C", "C"); Console.WriteLine(graph); foreach (var activity in graph.Activities) { Console.WriteLine(activity.Id + " includable: " + graph.CanActivityEverBeIncluded(activity.Id)); } Console.ReadLine(); }
public void GetQualityMeasuresOnStatisticsOriginalGraph() { var trace1 = new LogTrace { Id = "1" }; trace1.AddEventsWithChars('A', 'B', 'E'); var trace2 = new LogTrace { Id = "2" }; trace2.AddEventsWithChars('A', 'C', 'F', 'A', 'B', 'B', 'F'); var trace3 = new LogTrace { Id = "3" }; trace3.AddEventsWithChars('A', 'C', 'E'); var trace4 = new LogTrace { Id = "4" }; trace4.AddEventsWithChars('A', 'D', 'F'); var trace5 = new LogTrace { Id = "5" }; trace5.AddEventsWithChars('A', 'B', 'F', 'A', 'B', 'E'); var trace6 = new LogTrace { Id = "6" }; trace6.AddEventsWithChars('A', 'C', 'F'); var trace7 = new LogTrace { Id = "7" }; trace7.AddEventsWithChars('A', 'B', 'F', 'A', 'C', 'F', 'A', 'C', 'E'); var trace8 = new LogTrace { Id = "8" }; trace8.AddEventsWithChars('A', 'B', 'B', 'B', 'F'); var trace9 = new LogTrace { Id = "9" }; trace9.AddEventsWithChars('A', 'B', 'B', 'E'); var trace10 = new LogTrace { Id = "10" }; trace10.AddEventsWithChars('A', 'C', 'F', 'A', 'C', 'E'); Log log = new Log() { Traces = { trace1, trace2, trace3, trace4, trace5, trace6, trace7, trace8, trace9, trace10 } }; var graph = new DcrGraph(); for (char ch = 'A'; ch <= 'F'; ch++) { if (ch == 'D') continue; graph.AddActivity(ch.ToString(), "somename" + ch); } graph.SetIncluded(true, "A"); // Self-excludes graph.AddIncludeExclude(false, "A", "A"); graph.AddIncludeExclude(false, "C", "C"); graph.AddIncludeExclude(false, "E", "E"); graph.AddIncludeExclude(false, "F", "F"); // Includes graph.AddIncludeExclude(true, "A", "B"); graph.AddIncludeExclude(true, "A", "C"); graph.AddIncludeExclude(true, "B", "E"); graph.AddIncludeExclude(true, "B", "F"); graph.AddIncludeExclude(true, "C", "E"); graph.AddIncludeExclude(true, "C", "F"); graph.AddIncludeExclude(true, "F", "A"); // Excludes graph.AddIncludeExclude(false, "E", "B"); graph.AddIncludeExclude(false, "B", "C"); graph.AddIncludeExclude(false, "C", "B"); graph.AddIncludeExclude(false, "F", "B"); graph.AddIncludeExclude(false, "E", "F"); graph.AddIncludeExclude(false, "F", "E"); //var redundRemoved = new RedundancyRemover().RemoveRedundancy(graph); Console.WriteLine(QualityDimensionRetriever.Retrieve(graph, log)); Console.ReadLine(); }
public void OriginalLogStatisticsGraphMeasures() { var originalLog = new List<LogTrace> { new LogTrace('A', 'B', 'E'), new LogTrace('A', 'C', 'F', 'A', 'B', 'B', 'F'), new LogTrace('A', 'C', 'E'), new LogTrace('A', 'D', 'F'), new LogTrace('A', 'B', 'F', 'A', 'B', 'E'), new LogTrace('A', 'C', 'F'), new LogTrace('A', 'B', 'F', 'A', 'C', 'F', 'A', 'C', 'E'), new LogTrace('A', 'B', 'B', 'B', 'F'), new LogTrace('A', 'B', 'B', 'E'), new LogTrace('A', 'C', 'F', 'A', 'C', 'E') }; var apriori = new DcrGraph(); apriori.AddActivities(new Activity("A", "nameA"), new Activity("B", "nameB"), new Activity("C", "nameC"), new Activity("E", "nameE"), new Activity("F", "nameF")); apriori.SetIncluded(true, "A"); apriori.SetIncluded(false, "B"); apriori.SetIncluded(false, "C"); apriori.SetIncluded(false, "E"); apriori.SetIncluded(false, "F"); apriori.AddResponse("A", "B"); apriori.AddResponse("A", "C"); apriori.AddResponse("A", "E"); apriori.AddResponse("A", "F"); apriori.AddResponse("B", "E"); // self-excludes apriori.AddIncludeExclude(false, "A", "A"); apriori.AddIncludeExclude(false, "C", "C"); apriori.AddIncludeExclude(false, "E", "E"); apriori.AddIncludeExclude(false, "F", "F"); apriori.AddIncludeExclude(true, "A", "B"); apriori.AddIncludeExclude(true, "A", "C"); apriori.AddIncludeExclude(true, "F", "A"); apriori.AddIncludeExclude(true, "B", "E"); apriori.AddIncludeExclude(true, "B", "F"); apriori.AddIncludeExclude(true, "C", "E"); apriori.AddIncludeExclude(true, "C", "F"); apriori.AddIncludeExclude(false, "B", "C"); apriori.AddIncludeExclude(false, "C", "B"); apriori.AddIncludeExclude(false, "E", "B"); apriori.AddIncludeExclude(false, "E", "F"); apriori.AddIncludeExclude(false, "F", "E"); apriori.AddIncludeExclude(false, "F", "B"); Console.WriteLine(QualityDimensionRetriever.Retrieve(apriori, new Log { Traces = originalLog })); Console.ReadLine(); }
public void TestSimpleGraph() { var graph = new DcrGraph(); graph.AddActivity("A", "somename1"); graph.AddActivity("B", "somename2"); graph.SetIncluded(true, "A"); // Start at A graph.SetIncluded(true, "B"); Console.WriteLine(graph); var graph2 = new RedundancyRemover().RemoveRedundancy(graph); Console.WriteLine(graph2); Console.ReadLine(); }
public void TestRedundancyRemoverLimited() { var graph = new DcrGraph(); graph.AddActivity("A", "somename1"); graph.SetIncluded(true, "A"); // Start at A graph.AddIncludeExclude(false, "A", "A"); Console.WriteLine(graph); //graph.Running = true; //graph.Execute(graph.GetActivity("A")); //graph.Execute(graph.GetActivity("C")); //Console.WriteLine(graph); Console.WriteLine("------------------"); Console.WriteLine(new RedundancyRemover().RemoveRedundancy(graph)); Console.ReadLine(); // Conclusion: Edits made to not see self-exclusion as redundant }
public void TestRedundancyRemoverExcludes() { var graph = new DcrGraph(); graph.AddActivity("A", "somename1"); graph.AddActivity("B", "somename2"); graph.SetIncluded(true, "A"); // Start at A graph.SetIncluded(true, "B"); // Start at B // If you choose A - cannot do B, if you choose B, can still do A. graph.AddIncludeExclude(false, "A", "B"); // Self-excludes //graph.AddIncludeExclude(false, "A", "A"); //graph.AddIncludeExclude(false, "B", "B"); Console.WriteLine(graph); //graph.Running = true; //graph.Execute(graph.GetActivity("A")); //graph.Execute(graph.GetActivity("C")); //Console.WriteLine(graph); Console.WriteLine("------------------"); Console.WriteLine(new RedundancyRemover().RemoveRedundancy(graph)); Console.ReadLine(); // Conclusion: Edits made to not see self-exclusion as redundant }
//public void TestCompareTracesWithSupplied() //{ // var activities = new HashSet<Activity> { new Activity("A", "somename1"), new Activity("B", "somename2"), new Activity("C", "somename3") }; // var graph = new DcrGraph(); // foreach (var a in activities) // { // graph.AddActivity(a.Id, a.Name); // } // graph.SetIncluded(true, "A"); // Start at A // graph.AddIncludeExclude(true, "A", "B"); // graph.AddIncludeExclude(true, "A", "C"); // graph.AddIncludeExclude(true, "B", "C"); // graph.AddIncludeExclude(false, "C", "B"); // graph.AddIncludeExclude(false, "A", "A"); // graph.AddIncludeExclude(false, "B", "B"); // graph.AddIncludeExclude(false, "C", "C"); // var unique = new UniqueTraceFinder(graph); // var copy = graph.Copy(); // Verified Copy works using Activity level copying // // Remove B -->+ C (Gives same traces :) ) // var activityB = copy.GetActivity("B"); // Dictionary<Activity, bool> targets; // if (copy.IncludeExcludes.TryGetValue(activityB, out targets)) // { // targets.Remove(copy.GetActivity("C")); // } // // Remove A -->+ C (Gives different traces :) ) // //var activityA = copy.GetActivity("A"); // //Dictionary<Activity, bool> targets; // //if (copy.IncludeExcludes.TryGetValue(activityA, out targets)) // //{ // // targets.Remove(copy.GetActivity("C")); // //} // Console.WriteLine(unique.CompareTracesFoundWithSupplied3(copy)); // Console.ReadLine(); // // Conclusion: I do believe it works! //} public void TestRedundancyRemover() { var activities = new HashSet<Activity> { new Activity("A", "somename1"), new Activity("B", "somename2"), new Activity("C", "somename3") }; var graph = new DcrGraph(); foreach (var a in activities) { graph.AddActivity(a.Id, a.Name); } graph.SetIncluded(true, "A"); // Start at A graph.AddIncludeExclude(true, "A", "B"); graph.AddIncludeExclude(true, "A", "C"); graph.AddIncludeExclude(true, "B", "C"); graph.AddIncludeExclude(false, "C", "B"); graph.AddIncludeExclude(false, "A", "A"); graph.AddIncludeExclude(false, "B", "B"); graph.AddIncludeExclude(false, "C", "C"); Console.WriteLine(graph); //graph.Running = true; //graph.Execute(graph.GetActivity("A")); //graph.Execute(graph.GetActivity("C")); //Console.WriteLine(graph); Console.WriteLine("------------------"); Console.WriteLine(new RedundancyRemover().RemoveRedundancy(graph)); Console.ReadLine(); }
public void TestQualityDimensionsRetriever() { var graph = new DcrGraph(); graph.AddActivity("A", "somename1"); graph.AddActivity("B", "somename2"); graph.AddActivity("C", "somename3"); //graph.AddActivity("D", "somename3"); graph.SetIncluded(true, "A"); // Start at A graph.AddIncludeExclude(true, "A", "B"); graph.AddIncludeExclude(true, "B", "C"); graph.AddIncludeExclude(false, "C", "B"); graph.AddResponse("B", "C"); // Self-excludes graph.AddIncludeExclude(false, "A", "A"); graph.AddIncludeExclude(false, "B", "B"); graph.AddIncludeExclude(false, "C", "C"); graph.AddCondition("A", "B"); graph.AddMileStone("A", "B"); var someLog = new Log() { Traces = new List<LogTrace> { new LogTrace('A', 'B', 'C'), new LogTrace('A', 'C') } }; var res = QualityDimensionRetriever.Retrieve(graph, someLog); Console.WriteLine(graph); Console.WriteLine(res); var graph2 = new DcrGraph(); graph2.AddActivity("A", "somename1"); graph2.AddActivity("B", "somename2"); graph2.AddActivity("C", "somename3"); graph2.SetIncluded(true, "A"); graph2.SetIncluded(true, "B"); graph2.SetIncluded(true, "C"); res = QualityDimensionRetriever.Retrieve(graph2, someLog); Console.WriteLine(graph2); Console.WriteLine(res); var graph3 = new DcrGraph(); graph3.AddActivity("A", "somename1"); graph3.AddActivity("B", "somename2"); graph3.AddActivity("C", "somename3"); graph3.AddIncludeExclude(false, "A", "A"); graph3.AddIncludeExclude(false, "B", "B"); graph3.AddIncludeExclude(false, "C", "C"); graph3.AddIncludeExclude(false, "A", "B"); graph3.AddIncludeExclude(false, "B", "A"); graph3.AddIncludeExclude(false, "C", "A"); graph3.AddIncludeExclude(false, "C", "B"); graph3.AddIncludeExclude(false, "A", "C"); graph3.AddIncludeExclude(false, "B", "C"); graph3.AddResponse("A", "B"); graph3.AddResponse("A", "C"); graph3.AddResponse("B", "A"); graph3.AddResponse("B", "C"); graph3.AddResponse("C", "A"); graph3.AddResponse("C", "B"); graph3.AddCondition("A", "B"); graph3.AddCondition("A", "C"); graph3.AddCondition("B", "A"); graph3.AddCondition("B", "C"); graph3.AddCondition("C", "A"); graph3.AddCondition("C", "B"); graph3.AddMileStone("A", "B"); graph3.AddMileStone("A", "C"); graph3.AddMileStone("B", "A"); graph3.AddMileStone("B", "C"); graph3.AddMileStone("C", "A"); graph3.AddMileStone("C", "B"); res = QualityDimensionRetriever.Retrieve(graph3, someLog); Console.WriteLine(graph3); Console.WriteLine(res); // "Original" test log var activities = new HashSet<Activity>(); for (char ch = 'A'; ch <= 'F'; ch++) { activities.Add(new Activity("" + ch, "somename " + ch)); } var exAl = new ContradictionApproach(activities); var originalLog = new List<LogTrace>(); originalLog.Add(new LogTrace('A', 'B', 'E')); originalLog.Add(new LogTrace('A', 'C', 'F', 'A', 'B', 'B', 'F')); originalLog.Add(new LogTrace('A', 'C', 'E')); originalLog.Add(new LogTrace('A', 'D', 'F')); originalLog.Add(new LogTrace('A', 'B', 'F', 'A', 'B', 'E')); originalLog.Add(new LogTrace('A', 'C', 'F')); originalLog.Add(new LogTrace('A', 'B', 'F', 'A', 'C', 'F', 'A', 'C', 'E')); originalLog.Add(new LogTrace('A', 'B', 'B', 'B', 'F')); originalLog.Add(new LogTrace('A', 'B', 'B', 'E')); originalLog.Add(new LogTrace('A', 'C', 'F', 'A', 'C', 'E')); exAl.AddTrace(originalLog[0]); exAl.AddTrace(originalLog[1]); exAl.AddTrace(originalLog[2]); exAl.AddTrace(originalLog[3]); exAl.AddTrace(originalLog[4]); exAl.AddTrace(originalLog[5]); exAl.AddTrace(originalLog[6]); exAl.AddTrace(originalLog[7]); exAl.AddTrace(originalLog[8]); exAl.AddTrace(originalLog[9]); var log = new Log() {Traces = originalLog}; res = QualityDimensionRetriever.Retrieve(exAl.Graph, log); Console.WriteLine(exAl.Graph); Console.WriteLine(res); Console.WriteLine("Removing redundancy::::::::::::::::::::::::::::::::::"); exAl.Graph = new RedundancyRemover().RemoveRedundancy(exAl.Graph); res = QualityDimensionRetriever.Retrieve(exAl.Graph, log); Console.WriteLine(exAl.Graph); Console.WriteLine(res); Console.ReadLine(); }