/// <summary>
        /// Token replay technique
        /// </summary>
        /// <param name="minedNet">Mined model</param>
        /// <param name="trace_frequencies">Dictionary holding the frequencies from the trance</param>
        /// <returns>Fitness E [0;1]</returns>
        public static double TokenReplayFitness(PetriNet minedNet, Dictionary <List <string>, int> trace_frequencies)
        {
            var result = new TokenReplayInfo();

            foreach (KeyValuePair <List <string>, int> trace in trace_frequencies)
            {
                minedNet.InitializeTokens();
                minedNet.AddMarking(1);
                var sequenceTokenInfo = new TokenReplayInfo(produced: 1);
                foreach (var step in trace.Key)
                {
                    var transitionId = minedNet.TransitionNameToId(step);
                    var isEnabled    = minedNet.IsEnabled(transitionId);

                    if (!isEnabled)
                    {
                        // produce the correct amount of missing tokens
                        var placesBefore = minedNet.GetIdsOfParentPlaces(transitionId);
                        foreach (var placeId in placesBefore)
                        {
                            if (0 == minedNet.GetTokens(placeId))
                            {
                                minedNet.AddMarking(placeId);
                                sequenceTokenInfo.missed++;
                            }
                        }
                    }

                    sequenceTokenInfo.consumed += minedNet.GetNumberOfParents(transitionId);
                    sequenceTokenInfo.produced += minedNet.GetNumberOfChildren(transitionId);
                    minedNet.FireTransition(transitionId);
                }

                var lastTransitionId = minedNet.TransitionNameToId(trace.Key[trace.Key.Count - 1]);
                if (1 != minedNet.GetNumberOfChildren(lastTransitionId))
                {
                    Console.WriteLine("Error, the last transition should have only one out place");
                    return(-1);
                }

                // consume the tokens from the out place
                sequenceTokenInfo.consumed += minedNet.GetTokens(minedNet.GetIdsOfChildPlaces(lastTransitionId)[0]);

                // check if there are any tokens left behind in the net
                foreach (var step in trace.Key)
                {
                    var transitionId = minedNet.TransitionNameToId(step);

                    sequenceTokenInfo.remained += minedNet.GetIdsOfParentPlaces(transitionId)
                                                  .Select(x => minedNet.GetTokens(x)).ToList().Sum();
                }
                sequenceTokenInfo.MultiplyBy(trace.Value);
                result.SumUp(sequenceTokenInfo);
            }
            return(result.ComputeFitness());
        }
Exemple #2
0
        private static void check_enabled(PetriNet p)
        {
            List <string> transitionList = new List <string>()
            {
                "record issue", "inspection",
                "intervention authorization", "action not required", "work mandate",
                "no concession", "work completion", "issue completion"
            };

            foreach (var t in transitionList)
            {
                Console.Write(p.IsEnabled(p.TransitionNameToId(t)).ToString() + " ");
            }
            Console.WriteLine();
        }
Exemple #3
0
        public static void TestPetriNetTest1()
        {
            PetriNet p = new PetriNet();

            p.AddPlace(1);
            p.AddPlace(2);
            p.AddPlace(3);
            p.AddPlace(4);
            p.AddTransition(-1, "A");
            p.AddTransition(-2, "B");
            p.AddTransition(-3, "C");
            p.AddTransition(-4, "D");

            p.AddEdge(1, -1);
            p.AddEdge(-1, 2);
            p.AddEdge(2, -2);
            p.AddEdge(-2, 3);
            p.AddEdge(2, -3);
            p.AddEdge(-3, 3);
            p.AddEdge(3, -4);
            p.AddEdge(-4, 4);

            Console.WriteLine(p.IsEnabled(-1).ToString() + " " + p.IsEnabled(-2).ToString() + " " + p.IsEnabled(-3).ToString() + " " + p.IsEnabled(-4).ToString());

            p.AddMarking(1);  // add one token to place id 1
            Console.WriteLine(p.IsEnabled(-1).ToString() + " " + p.IsEnabled(-2).ToString() + " " + p.IsEnabled(-3).ToString() + " " + p.IsEnabled(-4).ToString());

            p.FireTransition(-1);  // fire transition A
            Console.WriteLine(p.IsEnabled(-1).ToString() + " " + p.IsEnabled(-2).ToString() + " " + p.IsEnabled(-3).ToString() + " " + p.IsEnabled(-4).ToString());

            p.FireTransition(-3);  // fire transition C
            Console.WriteLine(p.IsEnabled(-1).ToString() + " " + p.IsEnabled(-2).ToString() + " " + p.IsEnabled(-3).ToString() + " " + p.IsEnabled(-4).ToString());

            p.FireTransition(-4);  // fire transition D
            Console.WriteLine(p.IsEnabled(-1).ToString() + " " + p.IsEnabled(-2).ToString() + " " + p.IsEnabled(-3).ToString() + " " + p.IsEnabled(-4).ToString());

            p.AddMarking(2);  // add one token to place id 2
            Console.WriteLine(p.IsEnabled(-1).ToString() + " " + p.IsEnabled(-2).ToString() + " " + p.IsEnabled(-3).ToString() + " " + p.IsEnabled(-4).ToString());

            p.FireTransition(-2);  // fire transition B
            Console.WriteLine(p.IsEnabled(-1).ToString() + " " + p.IsEnabled(-2).ToString() + " " + p.IsEnabled(-3).ToString() + " " + p.IsEnabled(-4).ToString());

            p.FireTransition(-4);  // fire transition D
            Console.WriteLine(p.IsEnabled(-1).ToString() + " " + p.IsEnabled(-2).ToString() + " " + p.IsEnabled(-3).ToString() + " " + p.IsEnabled(-4).ToString());

            Console.WriteLine(p.GetTokens(4));
        }