public void CopyNestedTest()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1") { Included = true };
            var activityB = new Activity("B", "somename2") { Included = true };
            var activityC = new Activity("C", "somename3") { Included = true };
            var activityD = new Activity("D", "somename4") { Included = false };
            var activityE = new Activity("E", "somename5") { Included = true };
            var activityF = new Activity("F", "somename6") { Included = true };

            dcrGraph.AddActivity(activityC.Id, activityC.Name);
            dcrGraph.AddActivity(activityD.Id, activityD.Name);
            dcrGraph.AddActivity(activityE.Id, activityE.Name);
            dcrGraph.AddIncludeExclude(true, activityC.Id, activityD.Id);
            dcrGraph.AddActivity(activityA.Id, activityA.Name);
            dcrGraph.AddActivity(activityB.Id, activityB.Name);
            dcrGraph.AddActivity(activityF.Id, activityF.Name);
            dcrGraph.AddCondition(activityE.Id, activityF.Id); //outgoing relation
            //ingoing relations
            dcrGraph.AddCondition(activityA.Id, activityC.Id);
            dcrGraph.AddCondition(activityA.Id, activityD.Id);
            dcrGraph.AddCondition(activityA.Id, activityE.Id);

            dcrGraph.MakeNestedGraph(new HashSet<Activity>() { activityC, activityD, activityE });

            var copy = dcrGraph.Copy();

            Assert.AreEqual(dcrGraph.ToString(), copy.ToString());
        }
        public void RedundantRemoverWithNested()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1") { Included = true };
            var activityB = new Activity("B", "somename2") { Included = true };
            var activityC = new Activity("C", "somename3") { Included = true };
            var activityD = new Activity("D", "somename4") { Included = false };
            var activityE = new Activity("E", "somename5") { Included = true };
            var activityF = new Activity("F", "somename6") { Included = true };

            dcrGraph.AddActivities(activityA, activityB, activityC, activityD, activityE, activityF);

            dcrGraph.AddIncludeExclude(true, activityC.Id,activityD.Id);
            dcrGraph.AddIncludeExclude(true, activityC.Id, activityE.Id); //Redundant include
            dcrGraph.AddCondition(activityE.Id,activityF.Id); //outgoing relation
            //ingoing relation
            dcrGraph.AddCondition(activityA.Id,activityC.Id);
            dcrGraph.AddCondition(activityA.Id, activityD.Id);
            dcrGraph.AddCondition(activityA.Id, activityE.Id);

            dcrGraph.MakeNestedGraph(new HashSet<Activity>() {activityC, activityD, activityE});

            var newGraph = new RedundancyRemover().RemoveRedundancy(dcrGraph);

            //we check that the Nested graph has had the redundant relation removed.
            Assert.IsFalse(newGraph.InRelation(activityE,newGraph.IncludeExcludes));
        }
        public void FitnessOnNestedGraph()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1") { Included = true };
            var activityB = new Activity("B", "somename2") { Included = true };
            var activityC = new Activity("C", "somename3") { Included = true };
            var activityD = new Activity("D", "somename4") { Included = false };
            var activityE = new Activity("E", "somename5") { Included = true };
            var activityF = new Activity("F", "somename6") { Included = true };

            dcrGraph.AddActivities(activityA,activityB,activityC,activityD,activityE,activityF);
            dcrGraph.AddIncludeExclude(true, activityC.Id, activityD.Id);
            dcrGraph.AddCondition(activityE.Id, activityF.Id); //outgoing relation
            //ingoing relations
            dcrGraph.AddCondition(activityA.Id, activityC.Id);
            dcrGraph.AddCondition(activityA.Id, activityD.Id);
            dcrGraph.AddCondition(activityA.Id, activityE.Id);

            dcrGraph.MakeNestedGraph(new HashSet<Activity>() { activityC, activityD, activityE });

            var log = new Log();
            log.AddTrace(new LogTrace('A', 'C','D'));
            log.AddTrace(new LogTrace('A', 'B', 'C'));
            log.AddTrace(new LogTrace('A', 'E', 'F'));
            log.AddTrace(new LogTrace('C', 'E','D')); //illegal trace should count down

            //expecting fitness = 75%
            var qd = UlrikHovsgaardAlgorithm.QualityMeasures.QualityDimensionRetriever.Retrieve(dcrGraph, log);

            Assert.AreEqual(75d, qd.Fitness);
        }
예제 #4
0
        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 RedundantRemoverWithNestedRedundantIncludes()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1") { Included = false };
            var activityB = new Activity("B", "somename2") { Included = true };
            var activityC = new Activity("C", "somename3") { Included = true };
            var activityD = new Activity("D", "somename4") { Included = false };

            dcrGraph.AddActivities(activityA, activityB, activityC, activityD);

            dcrGraph.AddIncludeExclude(true, activityA.Id, activityB.Id);
            dcrGraph.AddIncludeExclude(true, activityA.Id, activityC.Id);
            dcrGraph.AddIncludeExclude(true, activityA.Id, activityD.Id);

            dcrGraph.MakeNestedGraph(new HashSet<Activity>() { activityB, activityC, activityD });

            dcrGraph.AddIncludeExclude(true, activityA.Id, activityB.Id); // redundant include

            var newGraph = new RedundancyRemover().RemoveRedundancy(dcrGraph);

            //we check that the (redundant) include to an activity within an included nested graph was removed
            Assert.IsFalse(newGraph.InRelation(activityB, newGraph.IncludeExcludes));
        }
        public void ParseMortgageApplication2()
        {
            var graph = new DcrGraph();

            graph.AddActivities(new Activity("Collect Documents", "Collect Documents") { Included = true, Roles = "Caseworker" });
            graph.AddIncludeExclude(false, "Collect Documents", "Collect Documents");

            graph.AddActivities(new Activity("Irregular neighbourhood", "Irregular neighbourhood") { Included = true, Roles = "it" });
            graph.AddIncludeExclude(false, "Irregular neighbourhood", "Irregular neighbourhood");

            graph.AddActivities(new Activity("Make appraisal appointment", "Make appraisal appointment") { Included = true, Roles = "Mobile consultant" });
            graph.AddIncludeExclude(false, "Make appraisal appointment", "Make appraisal appointment");

            graph.AddActivities(new Activity("Appraisal audit", "Appraisal audit") { Included = true, Roles = "Auditor" });
            graph.AddIncludeExclude(false, "Appraisal audit", "Appraisal audit");

            graph.AddActivities(new Activity("On-site appraisal", "On-site appraisal") { Included = true, Roles = "Mobile consulant" });
            graph.AddIncludeExclude(false, "On-site appraisal", "On-site appraisal");

            graph.AddActivities(new Activity("Submit budget", "Submit budget") { Included = true, Roles = "Customer" });
            graph.AddIncludeExclude(false, "Submit budget", "Submit budget");

            graph.AddActivities(new Activity("Budget screening approve", "Budget screening approve") { Included = true, Pending = true, Roles = "Intern" });
            graph.AddIncludeExclude(false, "Budget screening approve", "Budget screening approve");

            graph.AddActivities(new Activity("Statistical appraisal", "Statistical appraisal") { Included = true, Roles = "Caseworker" });
            graph.AddIncludeExclude(false, "Statistical appraisal", "Statistical appraisal");

            graph.AddActivities(new Activity("Assess loan application", "Assess loan application") { Included = true, Pending = true, Roles = "Caseworker" });
            graph.AddIncludeExclude(false, "Assess loan application", "Assess loan application");

            graph.AddCondition("Collect Documents", "Irregular neighbourhood");
            graph.AddCondition("Collect Documents", "Make appraisal appointment");
            graph.AddCondition("Collect Documents", "On-site appraisal");
            graph.AddCondition("Collect Documents", "Statistical appraisal");

            graph.AddIncludeExclude(false, "Statistical appraisal", "Irregular neighbourhood");
            graph.AddIncludeExclude(false, "Statistical appraisal", "Make appraisal appointment");
            graph.AddIncludeExclude(false, "Statistical appraisal", "On-site appraisal");

            graph.AddIncludeExclude(false, "Irregular neighbourhood","Statistical appraisal");
            graph.AddIncludeExclude(false, "Make appraisal appointment","Statistical appraisal" );
            graph.AddIncludeExclude(false, "On-site appraisal","Statistical appraisal");

            graph.AddCondition("Irregular neighbourhood", "Make appraisal appointment");
            graph.AddCondition("Make appraisal appointment", "On-site appraisal");
            graph.AddCondition("On-site appraisal", "Submit budget");
            graph.AddCondition("Submit budget", "Budget screening approve");
            graph.AddCondition("Budget screening approve", "Assess loan application");
            graph.AddCondition("Assess loan application","Appraisal audit");

            graph.AddCondition("Statistical appraisal", "Submit budget");

            var nested = new HashSet<Activity>();
            nested.Add(graph.GetActivity("Irregular neighbourhood"));
            nested.Add(graph.GetActivity("Make appraisal appointment"));
            nested.Add(graph.GetActivity("On-site appraisal"));

            graph.MakeNestedGraph(nested);

            //LogGenerator9001 logGenerator9001 = new LogGenerator9001(20, graph);

            //Log log = new Log();

            //foreach (var trace in logGenerator9001.GenerateLog(500))
            //{
            //    log.AddTrace(trace);
            //}

            using (StreamWriter sw = new StreamWriter("C:/Downloads/mortgageStrict.xml"))
            {
                sw.WriteLine(graph.ExportToXml());
            }
        }
        public void MakeNestedGraphTest()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1") { Included = false };
            var activityB = new Activity("B", "somename2") { Included = true };
            var activityC = new Activity("C", "somename3") { Included = true };
            var activityD = new Activity("D", "somename4") { Included = false };
            var activityE = new Activity("E", "somename5") { Included = true };
            var activityF = new Activity("F", "somename6") { Included = true };

            dcrGraph.AddActivity(activityC.Id, activityC.Name);
            dcrGraph.AddActivity(activityD.Id, activityD.Name);
            dcrGraph.AddActivity(activityE.Id, activityE.Name);
            dcrGraph.AddIncludeExclude(true, activityC.Id, activityD.Id);
            dcrGraph.AddActivity(activityA.Id, activityA.Name);
            dcrGraph.AddActivity(activityB.Id, activityB.Name);
            dcrGraph.AddActivity(activityF.Id, activityF.Name);
            dcrGraph.AddCondition(activityE.Id, activityF.Id); //outgoing relation
            //ingoing relation
            dcrGraph.AddCondition(activityA.Id, activityC.Id);
            dcrGraph.AddCondition(activityA.Id, activityD.Id);
            dcrGraph.AddCondition(activityA.Id, activityE.Id);

            dcrGraph.MakeNestedGraph(new HashSet<Activity>() { activityC, activityD, activityE });

            //we check that the Nested graph exists
            Assert.IsTrue(dcrGraph.Activities.Any(a => a.IsNestedGraph));
        }
        public void GetNestedActivityTest()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1") { Included = true };
            var activityB = new Activity("B", "somename2") { Included = true };
            var activityC = new Activity("C", "somename3") { Included = true };
            var activityD = new Activity("D", "somename4") { Included = false };
            var activityE = new Activity("E", "somename5") { Included = true };
            var activityF = new Activity("F", "somename6") { Included = true };

            dcrGraph.AddActivities(activityA, activityB, activityC, activityD, activityE, activityF);
            dcrGraph.AddIncludeExclude(true, activityC.Id, activityD.Id);
            dcrGraph.AddCondition(activityE.Id, activityF.Id); //outgoing relation
            //ingoing relations
            dcrGraph.AddCondition(activityA.Id, activityC.Id);
            dcrGraph.AddCondition(activityA.Id, activityD.Id);
            dcrGraph.AddCondition(activityA.Id, activityE.Id);

            dcrGraph.MakeNestedGraph(new HashSet<Activity>() { activityC, activityD, activityE });

            var retrievedActivity = dcrGraph.GetActivity(activityC.Id);

            Assert.AreEqual(activityC.ToString(), retrievedActivity.ToString());
        }
        public void PrecisionOnNestedGraph()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1") { Included = true };
            var activityB = new Activity("B", "somename2") { Included = false };
            var activityC = new Activity("C", "somename3") { Included = true };
            var activityD = new Activity("D", "somename4") { Included = false };
            var activityE = new Activity("E", "somename5") { Included = false };
            var activityF = new Activity("F", "somename6") { Included = false };

            dcrGraph.AddActivities(activityA, activityB, activityC, activityD, activityE, activityF);
            //ingoing relations
            dcrGraph.AddCondition(activityA.Id, activityC.Id);
            dcrGraph.AddCondition(activityA.Id, activityD.Id);
            dcrGraph.AddCondition(activityA.Id, activityE.Id);
            dcrGraph.AddCondition(activityC.Id, activityE.Id);
            dcrGraph.AddIncludeExclude(true, activityC.Id, activityD.Id);
            dcrGraph.AddIncludeExclude(true, activityD.Id, activityE.Id);
            dcrGraph.AddIncludeExclude(true, activityE.Id, activityF.Id); //outgoing relation

            dcrGraph.AddIncludeExclude(false, activityA.Id, activityA.Id);
            dcrGraph.AddIncludeExclude(false, activityC.Id, activityC.Id);
            dcrGraph.AddIncludeExclude(false, activityD.Id, activityD.Id);
            dcrGraph.AddIncludeExclude(false, activityE.Id, activityE.Id);
            //F can be run more than once

            dcrGraph.MakeNestedGraph(new HashSet<Activity>() { activityC, activityD, activityE });

            var log = new Log();
            log.AddTrace(new LogTrace('A', 'C', 'D', 'E', 'F')); // we don't execute 'F' twice

            log.AddTrace(new LogTrace('A', 'C', 'D', 'E', 'E')); //we illegally execute E

            //legal activities executed pr. state = 5
            // divided by illegal executed activities (1) + legal activities that could be executed (5 + 1) (F could be executed again.)

            //expecting precision 5/7
            var qd = UlrikHovsgaardAlgorithm.QualityMeasures.QualityDimensionRetriever.Retrieve(dcrGraph, log);
            Assert.AreEqual((5d/7d)*100, qd.Precision);
        }
        public void SimplicityOnNestedGraph()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1") { Included = true, Pending = true};
            var activityC = new Activity("C", "somename3") { Included = true };
            var activityD = new Activity("D", "somename4") { Included = false };
            var activityE = new Activity("E", "somename5") { Included = false };
            var activityF = new Activity("F", "somename6") { Included = false };

            dcrGraph.AddActivities(activityA, activityC, activityD, activityE, activityF);
            //ingoing relations
            dcrGraph.AddCondition(activityA.Id, activityC.Id);
            dcrGraph.AddCondition(activityA.Id, activityD.Id);
            dcrGraph.AddCondition(activityA.Id, activityE.Id);
            dcrGraph.AddCondition(activityC.Id, activityE.Id); //inside nested relation
            dcrGraph.AddIncludeExclude(true, activityC.Id, activityD.Id);
            dcrGraph.AddIncludeExclude(true, activityD.Id, activityE.Id);
            dcrGraph.AddIncludeExclude(true, activityE.Id, activityF.Id); //outgoing relation

            dcrGraph.AddIncludeExclude(false, activityA.Id, activityA.Id);
            dcrGraph.AddIncludeExclude(false, activityC.Id, activityC.Id);
            dcrGraph.AddIncludeExclude(false, activityD.Id, activityD.Id);
            dcrGraph.AddIncludeExclude(false, activityE.Id, activityE.Id);
            //F can be run more than once

            dcrGraph.MakeNestedGraph(new HashSet<Activity>() { activityC, activityD, activityE });

            var log = new Log();
            log.AddTrace(new LogTrace('A', 'C', 'D', 'E', 'F'));
            log.AddTrace(new LogTrace('A', 'C', 'D', 'E', 'E'));

            //S1 = amount of relations (9) / amount of possible relations n=6 (4n^2 - 3n = 126) = 9/126
            //S2 = amount of coupled relations (9) / possible coupled relations (n^2 = 36) = 0,25
            //S3 = amount of pending activities 1 / all activities (5) = 0,2    (pending activities should not count the nested graph)

            const double totalRelationsPart = (1.0 - 9.0 / 126.0) / 2; // 50 % weight
            const double relationCouplesPart = (1.0 - 9.0 / 21.0) / 2; // 50 % weight
            const double pendingPart = (1.0 / 5.0) * 0.1; // 10 % possible negative weight
            const double nestedPart = (1.0 / 5) * 0.2; // 20 % possible negative weight

            //expecting simplicity: 1 - ((9/126)*0,45 + 0,25*0,45 + 0,2 * 0,10)
            const double expected = (totalRelationsPart + relationCouplesPart - pendingPart - nestedPart) * 100.0;
            var qd = UlrikHovsgaardAlgorithm.QualityMeasures.QualityDimensionRetriever.Retrieve(dcrGraph, log);
            Assert.AreEqual(expected, qd.Simplicity);
        }