public void RedundantRemoverWithNestedAndNoRemoval()
        {
            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 = false };
            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); //non-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 not removed a relation.
            Assert.IsTrue(newGraph.InRelation(activityE, newGraph.IncludeExcludes));
        }
        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 GetGeneralizationTest()
        {
            var dcrGraph = new DcrGraph();

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

            dcrGraph.AddActivities(activityA, activityB, activityC);

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

            var log = new Log();
            log.AddTrace(new LogTrace('A', 'B'));
            log.AddTrace(new LogTrace('A', 'B', 'C'));
            log.AddTrace(new LogTrace('A', 'B', 'C')); //duplicate trace should not matter
            log.AddTrace(new LogTrace('A', 'B', 'C', 'A')); //illegal execution should count down
            log.AddTrace(new LogTrace('A', 'B', 'C', 'A', 'A')); //this one should not matter, as we've already seen A been illegally executed from this state.

            var log2 = new Log();

            log2.AddTrace(new LogTrace('A', 'B'));

            var qd1 = QualityDimensionRetriever.Retrieve(dcrGraph, log);

            var qd2 = QualityDimensionRetriever.Retrieve(dcrGraph, log2);

            Assert.IsTrue(qd1.Generality > qd2.Generality);
        }
        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);
        }
        public bool AddEvent(string id, string instanceId)
        {
            if (instanceId != _runId)
            { // add the currentRun to dictionary, if not the one we want to work on.
                if(_runId != null)
                    _allRuns[_runId] = _run;
                if (_allRuns.TryGetValue(instanceId, out _run))
                { //get the one we want to work on.
                    _runId = instanceId;
                    _last = _run.Peek();
                }
                else
                { 
                    _run = new Queue<Activity>();
                    _runId = instanceId;
                }
            }

            bool graphAltered;
            Activity currentActivity = Graph.GetActivity(id);
            if (_run.Count == 0)
            {
                currentActivity.Included = true;
                graphAltered = true;

            }
            else
            {
                //last activity now includes the current activity
                graphAltered = Graph.AddIncludeExclude(true, _last.Id, currentActivity.Id);
            }

            //remove ingoing conditions that has not been run before in the current Run.
            //the activities that has the activity as a condition target.
            var conditions = new HashSet<Activity>(Graph.Conditions.Where(a => a.Value.Contains(currentActivity)).Select(a => a.Key));

            //if it has no ingoing condition relations; continue.
            if (conditions.Count > 0)
            {
                //if an element is in conditions and not in the remaining run's stack, remove the condition relation
                var conditionsToRemove = new HashSet<Activity>(conditions.Except(_run));

                if (conditionsToRemove.Count > 0) // A condition is about to be removed
                {
                    graphAltered = true;
                }
                foreach (var con in conditionsToRemove)
                {
                    Graph.RemoveCondition(con.Id, currentActivity.Id);
                }
            }

            _run.Enqueue(currentActivity);
            _last = currentActivity;

            return graphAltered;
        }
        public void AddEventTest()
        {
            var a = new Activity("A", "nameA");

            var exhaust = new ContradictionApproach(new HashSet<Activity>() {a,new Activity("B","nameB")});

            exhaust.AddEvent("A", "1000");

            Assert.IsTrue(exhaust.Graph.GetIncludedActivities().Contains(a));
        }
        public void GetActivityTest()
        {
            var dcrGraph = new DcrGraph();

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

            dcrGraph.AddActivities(activityA, activityB, activityC);

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

            Assert.AreSame(activityB, retrievedActivity);
        }
        public void RetrieveImageWithMilestoneRelationTest()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1") { Included = true };
            var activityB = new Activity("B", "somename2") { Included = false };

            dcrGraph.AddActivities(activityA, activityB);

            dcrGraph.AddMileStone(activityA.Id, activityB.Id);

            var img = GraphImageRetriever.Retrieve(dcrGraph).Result;

            Assert.IsNotNull(img);
        }
        public void ConditionNegativeTest()
        {
            var a = new Activity("A", "nameA");

            var b = new Activity("B", "nameB");

            var exhaust = new ContradictionApproach(new HashSet<Activity>() { a, b });

            exhaust.AddEvent("B", "1000");
            exhaust.Stop();

            HashSet<Activity> con;

            exhaust.Graph.Conditions.TryGetValue(a, out con);

            Assert.IsFalse(con.Contains(b));
        }
        public void CopyTest()
        {
            DcrGraph dcrGraph = new DcrGraph();

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

            dcrGraph.AddActivities(activityA, activityB, activityC);

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

            var copy = dcrGraph.Copy();

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

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

            dcrGraph.Activities.Add(activityA);
            dcrGraph.Activities.Add(activityB);
            dcrGraph.Activities.Add(activityC);

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

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

            //Now either the redundant response relation or A's initial pending state should be removed:");
            Assert.IsFalse(newGraph.InRelation(activityA, newGraph.Responses) && newGraph.GetActivity(activityA.Id).Pending);
        }
        public void CreateNestsTest()
        {
            var dcrGraph = new DcrGraph();

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

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

            dcrGraph.AddResponse(activityB.Id, activityC.Id); //inner nest condition

            //From A to all inner
            dcrGraph.AddIncludeExclude(false, activityA.Id, activityB.Id);
            dcrGraph.AddIncludeExclude(false, activityA.Id, activityC.Id);
            dcrGraph.AddIncludeExclude(false, activityA.Id, activityD.Id);
            dcrGraph.AddIncludeExclude(false, activityA.Id, activityE.Id);
            dcrGraph.AddIncludeExclude(false, activityA.Id, activityB.Id);

            dcrGraph.AddIncludeExclude(false, activityD.Id, activityF.Id); //from in to out
            dcrGraph.AddMileStone(activityF.Id, activityG.Id);

            //From G to all inner and F
            dcrGraph.AddCondition(activityG.Id, activityB.Id);
            dcrGraph.AddCondition(activityG.Id, activityC.Id);
            dcrGraph.AddCondition(activityG.Id, activityD.Id);
            dcrGraph.AddCondition(activityG.Id, activityE.Id);
            dcrGraph.AddCondition(activityG.Id, activityF.Id);

            var exhaust = new ContradictionApproach(dcrGraph.Activities) { Graph = dcrGraph };

            exhaust.Graph = ContradictionApproach.CreateNests(exhaust.Graph);

            Assert.IsTrue(exhaust.Graph.Activities.Any(a => a.IsNestedGraph));
        }
        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 TestResponseAndExcludeRedundantIfNoTargetInclude()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1") { Included = true };
            var activityB = new Activity("B", "somename2") { Included = true };
            dcrGraph.Activities.Add(activityA);
            dcrGraph.Activities.Add(activityB);
            dcrGraph.AddResponse(activityA.Id, activityB.Id);
            dcrGraph.AddIncludeExclude(false, activityA.Id, activityB.Id);

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

            //Now the redundant response relation should be removed:

            Assert.IsFalse(newGraph.InRelation(activityB, newGraph.Responses));
        }
        public void TestActivityCreationLimitations()
        {
            // Shouldn't crash:
            var act = new Activity("A", "somename");
            Console.WriteLine(act);

            // Should fail:
            try
            {
                act = new Activity("A;2", "somename");
            }
            catch
            {
                Console.WriteLine("Fail: " + act);
            }

            // Should work:
            act = new Activity("A323fgfdå", "somename");
            Console.WriteLine(act);

            Console.ReadLine();
        }
        public void TestNonRedundantResponseIsNotRemoved2()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1") { Included = true };
            var activityB = new Activity("B", "somename2") { Included = false };

            dcrGraph.Activities.Add(activityA);
            dcrGraph.Activities.Add(activityB);

            dcrGraph.AddResponse(activityA.Id, activityB.Id);
            dcrGraph.AddIncludeExclude(true, activityA.Id, activityB.Id);

            dcrGraph.AddIncludeExclude(false, activityA.Id, activityA.Id);
            var newGraph = new RedundancyRemover().RemoveRedundancy(dcrGraph);

            Assert.IsTrue(newGraph.InRelation(activityA, newGraph.Responses));
        }
        public void TestRedundantActivityIsRemoved()
        {
            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 };

            dcrGraph.Activities.Add(activityA);
            dcrGraph.Activities.Add(activityB);
            dcrGraph.Activities.Add(activityC);

            dcrGraph.AddResponse(activityB.Id, activityA.Id);
            var newGraph = new RedundancyRemover().RemoveRedundancy(dcrGraph);

            Assert.IsNull(newGraph.GetActivity(activityA.Id));
        }
        public void TestIncludeConditionRedundancy()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1") { Included = true };
            var activityB = new Activity("B", "somename2") { Included = false };
            dcrGraph.Activities.Add(activityA);
            dcrGraph.Activities.Add(activityB);
            dcrGraph.AddCondition(activityA.Id, activityB.Id);
            dcrGraph.AddIncludeExclude(true, activityA.Id, activityB.Id);

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

            //Now the redundant condition relation from A to B should be removed:
            Assert.IsFalse(newGraph.InRelation(activityB, newGraph.Conditions));
        }
        public void TestIncludesToIncludedRedundant()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1") { Included = true };
            var activityB = new Activity("B", "somename2") { Included = true };
            dcrGraph.Activities.Add(activityA);
            dcrGraph.Activities.Add(activityB);
            dcrGraph.AddIncludeExclude(true, activityA.Id, activityB.Id);

            //Now the redundant include relation should be removed:");

            var newGraph = new RedundancyRemover().RemoveRedundancy(dcrGraph);
            Assert.IsFalse(newGraph.InRelation(activityA, newGraph.IncludeExcludes));
        }
        //TODO: move to unit-test
        public void TestUnhealthyInput()
        {
            var dcrGraph = new DcrGraph();

            var activityA = new Activity("A", "somename1");
            var activityB = new Activity("B", "somename2");
            var activityC = new Activity("C", "somename3");
            dcrGraph.Activities.Add(activityA);
            dcrGraph.Activities.Add(activityB);
            dcrGraph.Activities.Add(activityC);
            dcrGraph.AddResponse(activityA.Id, activityB.Id);
            dcrGraph.AddResponse(activityB.Id, activityC.Id);
            dcrGraph.AddResponse(activityC.Id, activityA.Id);

            dcrGraph.SetPending(true,activityA.Id);

            Console.WriteLine(new RedundancyRemover().RemoveRedundancy(dcrGraph));
            Console.ReadLine();
        }
        public void TestConditionMilestoneRedundancy()
        {
            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 };

            dcrGraph.Activities.Add(activityA);
            dcrGraph.Activities.Add(activityB);
            dcrGraph.Activities.Add(activityC);

            dcrGraph.AddCondition(activityA.Id, activityB.Id);
            dcrGraph.AddMileStone(activityA.Id, activityB.Id);
            dcrGraph.AddIncludeExclude(true, activityC.Id, activityA.Id);
            dcrGraph.AddResponse(activityC.Id, activityA.Id);

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

            //Now either the redundant Condition or Milestone relation should be removed:");
            Assert.IsFalse(newGraph.InRelation(activityA, newGraph.Conditions) && newGraph.InRelation(activityA, newGraph.Milestones));
        }
        public void TestActivityAlwaysExcludedRedundant()
        {
            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 };

            dcrGraph.Activities.Add(activityA);
            dcrGraph.Activities.Add(activityB);
            dcrGraph.Activities.Add(activityC);

            dcrGraph.AddCondition(activityA.Id, activityB.Id);
            dcrGraph.AddMileStone(activityA.Id, activityB.Id);
            dcrGraph.AddIncludeExclude(false, activityA.Id, activityC.Id);
            dcrGraph.AddResponse(activityA.Id, activityB.Id);
            dcrGraph.AddResponse(activityB.Id, activityA.Id);

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

            //Now all the relations from or to A should be removed:");
            Assert.IsTrue(!newGraph.InRelation(activityA, newGraph.Conditions)
                && !newGraph.InRelation(activityA, newGraph.IncludeExcludes)
                && !newGraph.InRelation(activityA, newGraph.Responses)
                && !newGraph.InRelation(activityA, newGraph.Milestones));
        }
        public void TestCopyMethod()
        {
            var dcrGraph = new DcrGraph();
            var activityA = new Activity("A", "somename1");
            var activityB = new Activity("B", "somename2");
            var activityC = new Activity("C", "somename3");
            dcrGraph.Activities.Add(activityA);
            dcrGraph.Activities.Add(activityB);
            dcrGraph.Activities.Add(activityC);
            dcrGraph.IncludeExcludes.Add(activityA, new Dictionary<Activity, bool> { { activityB, true }, { activityC, false } });
            dcrGraph.Conditions.Add(activityA, new HashSet<Activity> { activityB, activityC });

            Console.WriteLine(dcrGraph);

            Console.WriteLine("--------------------------------------------------------------------------------");

            var copy = dcrGraph.Copy();
            Console.WriteLine(copy);
            Console.ReadKey();
        }
        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 GetConditionsTest()
        {
            var dcr = new DcrGraph();
            var nested = new DcrGraph();
            nested.AddActivities(new Activity("C", ""), new Activity("D", ""));
            nested.AddCondition("C", "D");
            var nestedAct = new Activity("N", "", nested);
            dcr.AddActivities(new Activity("A", ""), new Activity("B", ""), nestedAct);
            dcr.AddCondition("A", "B");

            var allConditions = dcr.GetConditions();
            Assert.AreEqual(2, allConditions.Count);
        }
        public void AddActivity(Activity a)
        {
            Graph.AddActivity(a.Id, a.Name);

            foreach (var act in Graph.Activities.Except(new List<Activity> {a}))
            {
                // Excludes
                Graph.AddIncludeExclude(false, a.Id, act.Id);
                Graph.AddIncludeExclude(false, act.Id, a.Id);

                // Responses
                Graph.AddResponse(a.Id, act.Id);
                Graph.AddResponse(act.Id, a.Id);
            }
        }
        public bool Stop()
        {


            bool graphAltered = false;

            //set things that have not been run to not pending.
            foreach (var ac in Graph.Activities.Except(_run))
            {
                if (ac.Pending)
                {
                    Graph.SetPending(false, ac.Id);
                    graphAltered = true;
                }
            }

            while (_run.Count > 0)
            {
                var a1 = _run.Dequeue(); //the next element

                HashSet<Activity> responses;

                //if it has no response relations; continue.
                if (!Graph.Responses.TryGetValue(a1, out responses))
                    continue;

                //if an element is in responses and not in the remaining run, remove the element from responses
                var newResponses = new HashSet<Activity>(responses.Intersect(_run));

                if (newResponses.Count != responses.Count) // A response is about to be removed
                {
                    graphAltered = true;
                }

                //we could remove the keyvalue pair, if the resulting set is empty
                //then the elements has no responses
                if (newResponses.Count == 0)
                {
                    Graph.Responses.Remove(a1);
                }
                else
                {
                    Graph.Responses[a1] = newResponses;
                }
            }
            


            _allRuns.Remove(_runId);
            _runId = null;
            _run = new Queue<Activity>();
            _last = null;

            return graphAltered;
        }
        public void TestDictionaryAccessAndAddition()
        {
            var source = new Activity("A", "somename1");
            var target = new Activity("B", "somename2");
            var target2 = new Activity("C", "somename2");
            HashSet<Activity> targets;
            RedundantResponses.TryGetValue(source, out targets);
            if (targets == null)
            {
                RedundantResponses.Add(source, new HashSet<Activity> { target });
            }
            else
            {
                RedundantResponses[source].Add(target);
            }

            foreach (var activity in RedundantResponses[source])
            {
                Console.WriteLine(activity.Id);
            }

            Console.WriteLine("------------");

            RedundantResponses.TryGetValue(source, out targets);
            if (targets == null)
            {
                RedundantResponses.Add(source, new HashSet<Activity> { target2 });
            }
            else
            {
                RedundantResponses[source].Add(target2);
            }

            foreach (var activity in RedundantResponses[source])
            {
                Console.WriteLine(activity.Id);
            }
            //RedundantResponses[source].Add(new Activity {EventId = "C"});
            //Console.WriteLine(".......");
            //foreach (var activity in RedundantResponses[source])
            //{
            //    Console.WriteLine(activity.EventId);
            //}

            Console.ReadLine();

            // Conclusion: HashSet works as intended when adding more activities with already existing activity of same "EventId" value
            // Have to check whether Dictionary entry already exists or not
        }
        public void TestAlwaysIncludeIncludedRedundant()
        {
            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 = false };
            dcrGraph.Activities.Add(activityA);
            dcrGraph.Activities.Add(activityB);
            dcrGraph.Activities.Add(activityC);
            dcrGraph.AddCondition(activityA.Id, activityB.Id);
            dcrGraph.AddIncludeExclude(true, activityB.Id, activityC.Id);
            dcrGraph.AddIncludeExclude(true, activityA.Id, activityC.Id);
            var newDcr = new RedundancyRemover().RemoveRedundancy(dcrGraph);

            //we should now have removed include b -> c. so we are asserting that B no longer has a include relation
            Assert.IsFalse(newDcr.GetIncludeOrExcludeRelation(activityB, true).Contains(activityC));
        }
 public RelationCouple(Activity a1, Activity a2)
 {
     Activity1 = a1.Copy();
     Activity2 = a2.Copy();
 }