public LogTrace TraceGenerator()
        {
            var trace = new LogTrace();
            trace.Id = Guid.NewGuid().ToString();

            //reset the graph.
            DcrGraph graph = _inputGraph.Copy();
            graph.Running = true;

            var id = 0;
            while (true)
            {

                var runnables = graph.GetRunnableActivities();

                if (runnables.Count == 0)
                    break;
                //run a random activity and add it to the log.
                var name = RunRandomActivity(runnables, graph);
                trace.Add(new LogEvent(name,name) {EventId = id++.ToString()});

                //if we can stop and
                if(graph.IsFinalState() && _rnd.Next(100) < _terminationIndex)
                    break;

                if (trace.Events.Count >= 10000)
                {
                    throw new InvalidDataException("The graph is unhealthy, so it is not possible to generate a log.");
                }
            }
            trace.IsFinished = true;
            return trace;
        }
Ejemplo n.º 2
0
        public static Log ParseLog(LogStandard logStandard, string xml)
        {
            var log = new Log();

            XNamespace ns = logStandard.Namespace;

            XDocument doc = XDocument.Parse(xml);

            int eventId = 0;
            foreach (XElement traceElement in doc.Root.Elements(ns + logStandard.TraceIdentifier).Where(element => element.HasElements))
            {
                var trace = new LogTrace() {Id = traceElement.GetValue(ns, logStandard.TraceIdIdentifier) };

                foreach (XElement eventElement in traceElement.Elements(ns + logStandard.EventIdentifier).Where(element => element.HasElements))
                {
                    trace.Add(new LogEvent(eventElement.GetValue(ns, logStandard.EventIdIdentifier),
                                            eventElement.GetValue(ns, logStandard.EventNameIdentifier))
                    {
                        EventId = eventId++.ToString(),
                        ActorName = string.IsNullOrEmpty(logStandard.ActorNameIdentifier.Name) ? "" : eventElement.GetValue(ns, logStandard.ActorNameIdentifier)
                    });
                }

                log.AddTrace(trace);
            }
            return log;
        }
Ejemplo n.º 3
0
 public void AddTrace(LogTrace trace)
 {
     foreach (var logEvent in trace.Events)
     {
         Alphabet.Add(logEvent);
     }
     Traces.Add(trace);
 }
Ejemplo n.º 4
0
 public LogTrace Copy()
 {
     var copy = new LogTrace { Id = Id, IsFinished = IsFinished };
     foreach (var logEvent in Events)
     {
         copy.Add(new LogEvent(logEvent.IdOfActivity, logEvent.Name)
         {
             EventId = logEvent.EventId,
             ActorName = logEvent.ActorName,
             RoleName = logEvent.RoleName,
             TimeOfExecution = logEvent.TimeOfExecution
         });
     }
     return copy;
 }
        public void ExhaustiveWithBigDataLog()
        {
            var activities = new HashSet<Activity>();

            for (char ch = 'A'; ch <= 'Z'; ch++)
            {
                activities.Add(new Activity("" + ch, "somename " + ch));
            }

            var rnd = new Random();
            var inputLog = new Log();
            var traceId = 1000;
            var currentTrace = new LogTrace() {Id = traceId.ToString()};
            while (inputLog.Traces.Count < 100000)
            {
                currentTrace.Add(new LogEvent(activities.ElementAt(rnd.Next(activities.Count)).Id, ""));

                if (currentTrace.Events.Count == 8)
                {
                    inputLog.AddTrace(currentTrace);
                    traceId++;
                    currentTrace = (new LogTrace() {Id = traceId.ToString()});

                }

            }

            var exAl = new ContradictionApproach(activities);

            foreach (var trace in inputLog.Traces)
            {
                exAl.AddTrace(trace);
            }

            Assert.IsTrue(true);
        }
        //used to add one complete trace.
        public bool AddTrace(LogTrace trace)
        {
            //maybe run stop first-?

            bool graphAltered = false;
            foreach (LogEvent e in trace.Events)
            {
                if (AddEvent(e.IdOfActivity, trace.Id))
                {
                    graphAltered = true;
                }
            }
            var stopAlteredGraph = Stop();
            return graphAltered || stopAlteredGraph;
        }
        public void TestOriginalLog()
        {
            var activities = new HashSet<Activity>();

            for (char ch = 'A'; ch <= 'F'; ch++)
            {
                activities.Add(new Activity("" + ch, "" + ch));
            }

            var exAl = new ContradictionApproach(activities);

            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}};

            exAl.AddLog(log);

            Console.WriteLine(exAl.Graph);
            Console.WriteLine(QualityDimensionRetriever.Retrieve(exAl.Graph,log));
            //Console.WriteLine(exAl.Graph.ExportToXml());
            Console.ReadLine();

            exAl.Graph = new RedundancyRemover().RemoveRedundancy(exAl.Graph);

            Console.WriteLine(exAl.Graph);
            Console.WriteLine(QualityDimensionRetriever.Retrieve(exAl.Graph, log));
            Console.ReadLine();

            exAl.Graph = ContradictionApproach.PostProcessing(exAl.Graph);

            Console.WriteLine(exAl.Graph);
            Console.WriteLine(QualityDimensionRetriever.Retrieve(exAl.Graph, log));

            Console.ReadLine();
            //using (StreamWriter sw = new StreamWriter("C:/Downloads/OrigGraph.xml"))
            //{
            //    sw.WriteLine(exAl.Graph.ExportToXml());
            //}
        }
        public void TestFlowerModel()
        {
            var graph = new DcrGraph();
            var trace = new LogTrace();

            for (char ch = 'A'; ch <= 'D'; ch++)
            {
                graph.Activities.Add(new Activity("" + ch, "somename " + ch) {Included = true});
                trace.AddEventsWithChars(ch);
            }

            var exhaustive =
                new ContradictionApproach(new HashSet<Activity>
                {
                    new Activity("A", "somenameA"),
                    new Activity("B", "somenameB"),
                    new Activity("C", "somenameC"),
                    new Activity("D", "somenameD")
                });
            exhaustive.Graph = graph;
            exhaustive.AddTrace(trace);

            Console.WriteLine(exhaustive.Graph);
            exhaustive.Graph = new RedundancyRemover().RemoveRedundancy(exhaustive.Graph);
            Console.WriteLine(exhaustive.Graph);
            Console.WriteLine(QualityDimensionRetriever.Retrieve(exhaustive.Graph, new Log() {Traces = {trace}}));
            Console.ReadLine();
        }
        public void TestAreTracesEqualSingle()
        {
            var trace1 = new LogTrace('A', 'B', 'C', 'D');
            var trace2 = new LogTrace('A', 'B', 'C', 'D');

            Console.WriteLine(trace1.Equals(trace2));

            Console.ReadLine();

            // Conclusion: Use .Equals() method
        }
        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 ExhaustiveTest()
        {
            var traceId = 1000;
            var activities = new HashSet<Activity>();

            for (char ch = 'A'; ch <= 'G'; ch++)
            {
                activities.Add(new Activity("" + ch, "somename " + ch));
            }
            var inputLog = new Log();
            var currentTrace = new LogTrace() {Id = traceId++.ToString()};
            inputLog.Traces.Add(currentTrace);
            var exAl = new ContradictionApproach(activities);

            int id = 0;

            while (true)
            {
                var input = Console.ReadLine();
                switch (input)
                {
                    case "STOP":
                        exAl.Stop();
                        currentTrace = currentTrace.Copy();
                        currentTrace = new LogTrace() { Id = traceId++.ToString() };
                        inputLog.Traces.Add(currentTrace);
                        break;
                    case "AUTOLOG":
                        Console.WriteLine("Please input a termination index between 0 - 100 : \n");
                        var logGen = new LogGenerator9001(Convert.ToInt32(Console.ReadLine()), exAl.Graph);
                        Console.WriteLine("Please input number of desired traces to generate : \n");
                        List<LogTrace> log = logGen.GenerateLog(Convert.ToInt32(Console.ReadLine()));
                        foreach (var trace in log)
                        {
                            Console.WriteLine(trace);
                        }
                        break;
                    case "REDUNDANCY":
                        exAl.Graph = new RedundancyRemover().RemoveRedundancy(exAl.Graph);
                        break;
                    case "POST":
                        exAl.Graph = ContradictionApproach.PostProcessing(exAl.Graph);
                        break;
                    case "NESTED":
                        exAl.Graph = ContradictionApproach.CreateNests(exAl.Graph);
                        break;
                    case "CHANGE TRACE":
                        inputLog.Traces.Add(currentTrace);
                        var newId = Console.ReadLine();
                        currentTrace = inputLog.Traces.Find(x => x.Id == newId) ?? new LogTrace() { Id = newId};

                        break;

                    default:
                        if (exAl.Graph.GetActivities().Any(a => a.Id == input))
                        {
                            exAl.AddEvent(input, currentTrace.Id);
                            currentTrace.Add(new LogEvent(input, "somename" + input) {EventId = "" + id++});
                        }
                        break;
                }

                Console.WriteLine("Current trace id: " + currentTrace.Id);
                Console.WriteLine(exAl.Graph);

                //the quality probably suffers because the traces contains unfinished traces.
                Console.WriteLine(QualityDimensionRetriever.Retrieve(exAl.Graph, inputLog));
            }
        }
        public List<long> DataTimingTest(int alphabeth, int traces, int traceLength, int timesToRun)
        {
            var activities = new HashSet<Activity>();

            for (int i = 0; i < alphabeth; i++)
            {
                activities.Add(new Activity("" + i, "" + i));
            }

            var times = new List<long>();

            for (int j = 0; j < timesToRun; j++)
            {

                var rnd = new Random();

                var inputLog = new Log();
                var traceId = 1000;
                var currentTrace = new LogTrace() {Id = traceId.ToString()};
                while (inputLog.Traces.Count < traces)
                {
                    currentTrace.Add(new LogEvent(activities.ElementAt(rnd.Next(activities.Count)).Id, ""));

                    if (currentTrace.Events.Count == traceLength)
                    {
                        inputLog.AddTrace(currentTrace);
                        traceId++;
                        currentTrace = (new LogTrace() {Id = traceId.ToString()});

                    }

                }

                //
                var watch = new Stopwatch();
                watch.Start();

                var exAl = new ContradictionApproach(activities);

                foreach (var trace in inputLog.Traces)
                {
                    exAl.AddTrace(trace);
                }

                watch.Stop();

                times.Add(watch.ElapsedMilliseconds);
                Console.Write(".");
            }

            return times;
        }
 private void DisableTraceBuilding()
 {
     IsTraceAdditionAllowed = false;
     SelectedTrace = new LogTrace();
 }
        /// <summary>
        /// Adds a new, empty trace and selects it
        /// </summary>
        public void NewTrace()
        {
            var trace = new LogTrace();
            trace.Id = Guid.NewGuid().ToString();
            trace.EventAdded += RefreshLogTraces; // Register listening for changes to update grid when event added
            EntireLog.Add(trace);

            // Programmatically select trace (focus)
            SelectedTrace = EntireLog[EntireLog.Count - 1]; // last element
            RefreshLogTraces();
            SelectTraceByIndex?.Invoke(EntireLog.Count - 1);
        }
 /// <summary>
 /// Used when adding a full log of traces (All finished from the start)
 /// </summary>
 private void AddFinishedTraceFromLog(LogTrace logTrace) // TODO: Use at AddLog
 {
     if (logTrace.Events.Count == 0) return;
     var trace = logTrace.Copy();
     trace.IsFinished = true;
     if (string.IsNullOrEmpty(trace.Id))
     {
         trace.Id = Guid.NewGuid().ToString();
     }
     EntireLog.Add(trace);
     _contradictionApproach.AddTrace(trace); // Actually adds finished trace (stops it immediately)
 }