コード例 #1
0
        public static Dictionary <string, double> ComputeDurations(FuzzyNode fn)
        {
            Dictionary <string, double> durations = new Dictionary <string, double>();
            List <double> nodeDurations           = fn.GetDurationsList();

            if (nodeDurations.Count > 0)
            {
                double totalDuration = 0;
                foreach (double f in nodeDurations)
                {
                    totalDuration += f;
                }
                double meanDuration = totalDuration / nodeDurations.Count;

                nodeDurations.Sort();
                double minDuration = nodeDurations[0];
                double maxDuration = nodeDurations[nodeDurations.Count - 1];

                int    m = nodeDurations.Count / 2;
                double medianDuration = 0;
                if (nodeDurations.Count % 2 != 0)
                {
                    medianDuration = nodeDurations[m];
                }
                else
                {
                    medianDuration = (nodeDurations[m] + nodeDurations[m + 1]) / 2;
                }

                durations.Add("TotalDuration", totalDuration);
                durations.Add("MeanDuration", meanDuration);
                durations.Add("MedianDuration", medianDuration);
                durations.Add("MinDuration", minDuration);
                durations.Add("MaxDuration", maxDuration);
            }
            else
            {
                durations.Add("TotalDuration", 0);
                durations.Add("MeanDuration", 0);
                durations.Add("MedianDuration", 0);
                durations.Add("MinDuration", 0);
                durations.Add("MaxDuration", 0);
            }

            return(durations);
        }
コード例 #2
0
        public static FuzzyModel parseLogFile(string file)
        {
            FuzzyModel    fm     = new FuzzyModel();
            List <XTrace> traces = getTracesXES(file);

            string root = "start_node";
            string end  = "end_node";

            fm.AddNode(root);

            foreach (XTrace xt in traces)
            {
                fm.GetNode(root).IncreaseFrequencySignificance();
                var xamTrace = xt.GetAttributes();
                foreach (string key in xamTrace.Keys)
                {
                    if (key != "concept:name")
                    {
                        fm.GetNode(root).AddSignificantAttribute(key, xamTrace[key].ToString());
                    }
                }
                string previousEvent = root;
                string previousState = "";
                double eventDuration = 0;
                double traceDuration = 0;
                double previousTime  = 0;
                foreach (XEvent xe in xt)
                {
                    // find event name
                    XAttributeMap xam = (XAttributeMap)xe.GetAttributes();
                    string        currentEvent;
                    string        currentState = "";
                    if (xam.Keys.Contains <string>("lifecycle:transition"))
                    {
                        currentState = xam["lifecycle:transition"].ToString();
                    }
                    double currentTime = 0;
                    if (xam.Keys.Contains <string>("time:timestamp"))
                    {
                        currentTime = Convert.ToDateTime(xam["time:timestamp"].ToString()).ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
                    }
                    currentEvent = xam["concept:name"].ToString();

                    // if the event is new, add it to the graph
                    if (!fm.GetEvents().Contains(currentEvent))
                    {
                        FuzzyNode node = new FuzzyNode(currentEvent);
                        fm.AddNode(node);

                        // if it is not the first event in the trace, add edges
                        if (previousEvent != null)
                        {
                            FuzzyEdge e = new FuzzyEdge(fm.GetNode(previousEvent), node);
                            // if the edge is new add it to the list
                            if (!fm.GetNode(previousEvent).GetOutEdges().Contains(e))
                            {
                                fm.AddEdge(e);
                            }
                            // if it's not the start node, compute the duration of the transition
                            if (previousEvent != "start_node")
                            {
                                fm.GetEdge(e).AddDuration(currentTime - previousTime);
                                traceDuration += currentTime - previousTime;
                            }
                            fm.GetEdge(e).IncreaseFrequencySignificance();
                        }
                        fm.GetNode(currentEvent).IncreaseFrequencySignificance();
                    }
                    else
                    {
                        // if it is not the first event in the trace, add edges
                        if (previousEvent != null)
                        {
                            FuzzyEdge e = new FuzzyEdge(fm.GetNode(previousEvent), fm.GetNode(currentEvent));
                            // if the edge is new add it to the list
                            if (!fm.GetNode(previousEvent).GetOutEdges().Contains(e))
                            {
                                fm.AddEdge(e);
                            }
                            // if it's not the start node, compute the duration of the transition
                            if (previousEvent != "start_node")
                            {
                                fm.GetEdge(e).AddDuration(currentTime - previousTime);
                                traceDuration += currentTime - previousTime;
                            }
                            fm.GetEdge(e).IncreaseFrequencySignificance();
                        }
                        // if the event is the same but the state is different, compute the event duration
                        if (previousEvent == currentEvent && previousState != currentState)
                        {
                            if (previousState == "complete" && currentState == "start")
                            {
                                fm.GetNode(currentEvent).IncreaseFrequencySignificance();
                            }
                            eventDuration += currentTime - previousTime;
                        }
                        else
                        {
                            fm.GetNode(currentEvent).IncreaseFrequencySignificance();
                        }
                    }
                    // if the event is complete add its duration to the node
                    if (currentState == "complete")
                    {
                        fm.GetNode(currentEvent).AddDuration(eventDuration);
                        traceDuration += eventDuration;
                        eventDuration  = 0;
                    }
                    // add the event attributes to the node
                    foreach (string key in xam.Keys)
                    {
                        if (key != "concept:name" && key != "lifecycle:transition")
                        {
                            if (key != "time:timestamp" && key.IndexOf("id", StringComparison.OrdinalIgnoreCase) < 0)
                            {
                                fm.GetNode(currentEvent).AddSignificantAttribute(key, xam[key].ToString());
                            }
                            fm.GetNode(currentEvent).AddAttribute(key, xam[key].ToString());
                        }
                    }
                    previousEvent = currentEvent;
                    previousState = currentState;
                    previousTime  = currentTime;
                }
                if (!fm.GetEvents().Contains(end))
                {
                    fm.AddNode(end);
                    fm.GetNode(end).IncreaseFrequencySignificance();
                }
                else
                {
                    fm.GetNode(end).IncreaseFrequencySignificance();
                }
                FuzzyEdge fe = new FuzzyEdge(fm.GetNode(previousEvent), fm.GetNode(end));
                if (!fm.GetEdges().Contains(fe))
                {
                    fm.AddEdge(fe);
                    fm.GetEdge(fe).IncreaseFrequencySignificance();
                }
                else
                {
                    fm.GetEdge(fe).IncreaseFrequencySignificance();
                }

                fm.GetNode(root).AddDuration(traceDuration);
            }

            foreach (XTrace xt in traces)
            {
                foreach (FuzzyNode fn in fm.GetNodes())
                {
                    foreach (XEvent xe in xt)
                    {
                        if (xe.GetAttributes()["concept:name"].ToString().Equals(fn.GetLabel()))
                        {
                            fn.IncreaseCaseFrequencySignificance();
                            break;
                        }
                    }
                }
                foreach (FuzzyEdge fe in fm.GetEdges())
                {
                    string previousEvent = "";
                    foreach (XEvent xe in xt)
                    {
                        string currentEvent = xe.GetAttributes()["concept:name"].ToString();
                        if (previousEvent.Equals(fe.GetFromNode().GetLabel()) && currentEvent.Equals(fe.GetToNode().GetLabel()))
                        {
                            fe.IncreaseCaseFrequencySignificance();
                            break;
                        }
                        previousEvent = currentEvent;
                    }
                }
            }
            return(fm);
        }
コード例 #3
0
ファイル: FuzzyMining.cs プロジェクト: muccelli/FuzzyMiner
        private static void BuildClusters(FuzzyModel fm, float nodeCutoff)
        {
            // TODO normalize significance
            // find victims
            HashSet <FuzzyNode> victims = new HashSet <FuzzyNode>();

            foreach (FuzzyNode fn in fm.GetNodes())
            {
                if (fn.GetFrequencySignificance() < nodeCutoff)
                {
                    victims.Add(fn);
                }
            }

            // build clusters
            foreach (FuzzyNode fn in victims)
            {
                // find the most correlated neighbor
                float     max       = 0;
                FuzzyNode chosenOne = null;
                foreach (FuzzyEdge fe in fn.GetInEdges())
                {
                    if ((fe.GetEndpointCorrelation() + fe.GetProximityCorrelation()) > max)
                    {
                        max       = fe.GetEndpointCorrelation() + fe.GetProximityCorrelation();
                        chosenOne = fe.GetFromNode();
                    }
                }
                foreach (FuzzyEdge fe in fn.GetOutEdges())
                {
                    if ((fe.GetEndpointCorrelation() + fe.GetProximityCorrelation()) > max)
                    {
                        max       = fe.GetEndpointCorrelation() + fe.GetProximityCorrelation();
                        chosenOne = fe.GetToNode();
                    }
                }

                // if it is a cluster, then add the victim to it
                if (fm.IsCluster(fm.GetCluster(chosenOne)))
                {
                    FuzzyNodeCluster fnc = fm.GetCluster(chosenOne);
                    fnc.AddNodeToCluster(fn);
                    List <FuzzyEdge> toRemove = new List <FuzzyEdge>();
                    List <FuzzyEdge> toAdd    = new List <FuzzyEdge>();
                    foreach (FuzzyEdge fe in fn.GetInEdges())
                    {
                        FuzzyEdge newFe = new FuzzyEdge(fe.GetFromNode(), fnc);
                        toRemove.Add(fe);
                        toAdd.Add(newFe);
                    }
                    foreach (FuzzyEdge fe in fn.GetOutEdges())
                    {
                        FuzzyEdge newFe = new FuzzyEdge(fnc, fe.GetToNode());
                        toRemove.Add(fe);
                        toAdd.Add(newFe);
                    }
                    foreach (FuzzyEdge fe in toRemove)
                    {
                        fm.RemoveEdge(fe);
                    }
                    foreach (FuzzyEdge fe in toAdd)
                    {
                        if (fe.GetFromNode() != fe.GetToNode())
                        {
                            fm.AddEdge(fe);
                        }
                    }
                    fm.RemoveNode(fn);
                }
                else
                {
                    FuzzyNodeCluster fnc = new FuzzyNodeCluster(fn, "Cluster " + (fm.GetClusters().Count() + 1));
                    fm.AddCluster(fnc);
                    //Console.WriteLine(fnc.GetLabel());
                    List <FuzzyEdge> toRemove = new List <FuzzyEdge>();
                    List <FuzzyEdge> toAdd    = new List <FuzzyEdge>();
                    foreach (FuzzyEdge fe in fn.GetInEdges())
                    {
                        FuzzyEdge newFe = new FuzzyEdge(fe.GetFromNode(), fnc);
                        //Console.WriteLine(newFe.ToString());
                        toRemove.Add(fe);
                        toAdd.Add(newFe);
                    }
                    foreach (FuzzyEdge fe in fn.GetOutEdges())
                    {
                        FuzzyEdge newFe = new FuzzyEdge(fnc, fe.GetToNode());
                        //Console.WriteLine(newFe.ToString());
                        toRemove.Add(fe);
                        toAdd.Add(newFe);
                    }
                    foreach (FuzzyEdge fe in toRemove)
                    {
                        fm.RemoveEdge(fe);
                    }
                    foreach (FuzzyEdge fe in toAdd)
                    {
                        fm.AddEdge(fe);
                    }
                    fm.RemoveNode(fn);
                }
            }
        }
コード例 #4
0
ファイル: FuzzyMining.cs プロジェクト: muccelli/FuzzyMiner
        public static void ConflictResolution(FuzzyModel fm, float preserveThr, float ratioThr)
        {
            List <FuzzyEdge> toRemove = new List <FuzzyEdge>();

            foreach (FuzzyEdge AB in fm.GetEdges())
            {
                FuzzyEdge BA    = fm.GetEdge(AB.GetToNode(), AB.GetFromNode());
                float     relAB = 0;
                float     relBA = 0;
                if (BA != null)
                {
                    if (AB.Equals(BA))
                    {
                        toRemove.Add(AB);
                    }
                    if (toRemove.Contains(AB) || toRemove.Contains(BA))
                    {
                        continue;
                    }
                    FuzzyNode A = AB.GetFromNode();
                    FuzzyNode B = AB.GetToNode();
                    // compute relative significance of edge A->B
                    float sigAB = AB.GetFrequencySignificance();
                    float sigAX = 0;
                    foreach (FuzzyEdge AX in A.GetOutEdges())
                    {
                        sigAX += AX.GetFrequencySignificance();
                    }
                    float sigXB = 0;
                    foreach (FuzzyEdge XB in B.GetInEdges())
                    {
                        sigXB += XB.GetFrequencySignificance();
                    }
                    relAB = (0.5F * (sigAB / sigAX)) + (0.5F * (sigAB / sigXB));
                    Console.WriteLine("{0}, Relative significance: {1}", AB.ToString(), relAB);

                    // compute relative significance of edge B->A
                    float sigBA = BA.GetFrequencySignificance();
                    float sigBX = 0;
                    foreach (FuzzyEdge BX in B.GetOutEdges())
                    {
                        sigBX += BX.GetFrequencySignificance();
                    }
                    float sigXA = 0;
                    foreach (FuzzyEdge XA in A.GetInEdges())
                    {
                        sigXA += XA.GetFrequencySignificance();
                    }
                    relBA = (0.5F * (sigBA / sigBX)) + (0.5F * (sigBA / sigXA));
                    Console.WriteLine("{0}, Relative significance: {1}", BA.ToString(), relBA);


                    // Decide preservation
                    if (relAB < preserveThr || relBA < preserveThr)
                    {
                        float ofsAB = Math.Abs(relAB - relBA);
                        if (ofsAB < ratioThr)
                        {
                            toRemove.Add(AB);
                            toRemove.Add(BA);
                        }
                        else
                        {
                            if (relAB > relBA)
                            {
                                toRemove.Add(BA);
                            }
                            else
                            {
                                toRemove.Add(AB);
                            }
                        }
                    }
                }
            }

            foreach (FuzzyEdge fe in toRemove)
            {
                fm.RemoveEdge(fe);
            }
        }