예제 #1
0
        private static GraphPetriNet CreatePNInhibited()
        {
            var p = new GraphPetriNet(
                "p",
                new Dictionary <int, string> {
                { 0, "p0" },
                { 1, "p1" },
                { 2, "p2" }
            },
                //new Dictionary<int, int> { { 0, 1 }, { 1, 1 } },
                new Dictionary <int, string> {
                { 0, "t0" }
            },
                new Dictionary <int, List <InArc> >()
            {
                { 0, new List <InArc>()
                  {
                      new InArc(0), new InArc(1, 1, true)
                  } }
            },
                new Dictionary <int, List <OutArc> >()
            {
                { 0, new List <OutArc>()
                  {
                      new OutArc(2)
                  } }
            }
                );

            return(p);
        }
예제 #2
0
        private static GraphPetriNet CreatePNTwoInOneOut()
        {
            var p = new GraphPetriNet(
                "p",
                new Dictionary <int, string> {
                { 0, "p0" },
                { 1, "p1" },
                { 2, "p2" }
            },
                new Dictionary <int, string> {
                { 0, "t0" }
            },
                new Dictionary <int, List <InArc> >()
            {
                { 0, new List <InArc>()
                  {
                      new InArc(0), new InArc(1)
                  } }
            },
                new Dictionary <int, List <OutArc> >()
            {
                { 0, new List <OutArc>()
                  {
                      new OutArc(2)
                  } }
            }
                );

            return(p);
        }
        public void TestPrioritySetup()
        {
            var p = new GraphPetriNet("p",
                                      new Dictionary <int, string> {
                { 0, "p0" },
                { 1, "p1" },
                { 2, "p2" }
            },
                                      new Dictionary <int, string>
            {
                { 0, "t1" },
                { 1, "t2" }
            },
                                      new Dictionary <int, List <InArc> >()
            {
                { 0, new List <InArc>()
                  {
                      new InArc(0), new InArc(1)
                  } },
                { 1, new List <InArc>()
                  {
                      new InArc(1), new InArc(2)
                  } }
            },
                                      new Dictionary <int, List <OutArc> >()
            {
            },
                                      new Dictionary <int, int>()
            {
                { 0, 1 }, { 1, 2 }
            });

            Assert.AreEqual(1, p.GetTransitionPriority(0));
            Assert.AreEqual(2, p.GetTransitionPriority(1));
        }
        public void TestDrainTransition()
        {
            var m = new Marking(1, new Dictionary <int, int>
            {
                { 0, 5 }
            });
            var p = new GraphPetriNet("p",
                                      new Dictionary <int, string> {
                { 0, "p0" }
            },
                                      new Dictionary <int, string>
            {
                { 0, "Ti" }
            },
                                      new Dictionary <int, List <InArc> >()
            {
                { 0, new List <InArc>()
                  {
                      new InArc(0)
                  } }
            },
                                      new Dictionary <int, List <OutArc> >()
            {
            });

            for (int i = 5; i >= 0; i--)
            {
                Assert.AreEqual(i, m[0]);
                Assert.AreEqual(i > 0, p.IsEnabled(0, m));
                m = p.Fire(m);
            }
        }
        public void TestInputTransition()
        {
            var m = new Marking(1,
                                new Dictionary <int, int>
            {
                { 0, 0 }
            });
            var p = new GraphPetriNet("p",
                                      new Dictionary <int, string> {
                { 0, "p0" }
            },
                                      new Dictionary <int, string>
            {
                { 0, "Ti" }
            },
                                      new Dictionary <int, List <InArc> >()
            {
            },
                                      new Dictionary <int, List <OutArc> >()
            {
                { 0, new List <OutArc>()
                  {
                      new OutArc(0)
                  } }
            });

            Assert.IsTrue(p.IsEnabled(0, m));
            m = p.Fire(m);
            Assert.AreEqual(1, m[0]);
            Assert.IsTrue(p.IsEnabled(0, m));
            m = p.Fire(m);
            Assert.AreEqual(2, m[0]);
            Assert.IsTrue(p.IsEnabled(0, m));
        }
예제 #6
0

        
        public void TestPrioritySelection2()
        {
            var m = new Marking(4,
                                new Dictionary <int, int>
            {
                { 0, 1 },
                { 1, 1 },
                { 2, 1 },
                { 3, 1 }
            });
            var p = new GraphPetriNet("p",
                                      new Dictionary <int, string> {
                { 0, "p0" },
                { 1, "p1" },
                { 2, "p2" },
                { 3, "p3" }
            },
                                      new Dictionary <int, string>
            {
                { 0, "t1" },
                { 1, "t2" },
                { 2, "t3" }
            },
                                      new Dictionary <int, List <InArc> >()
            {
                { 0, new List <InArc>()
                  {
                      new InArc(0), new InArc(1)
                  } },
                { 1, new List <InArc>()
                  {
                      new InArc(1), new InArc(2)
                  } },
                { 2, new List <InArc>()
                  {
                      new InArc(1), new InArc(2), new InArc(3)
                  } }
            },
                                      new Dictionary <int, List <OutArc> >()
            {
            },
                                      new Dictionary <int, int>()
            {
                { 0, 1 },
                { 1, 1 },
                { 2, 4 }
            });    // t0 will be baseline at 0 and t1 will be 1, therefore next enabled transition should always be 1
            int?transId = p.GetNextTransitionToFire(m);

            Assert.IsTrue(transId.HasValue);
            Assert.AreEqual(2, transId.Value);
        }
        public void TestConflictDetection()
        {
            var m = new Marking(3,
                                new Dictionary <int, int>
            {
                { 0, 1 },
                { 1, 1 },
                { 2, 1 }
            });
            var p = new GraphPetriNet("p",
                                      new Dictionary <int, string> {
                { 0, "p0" },
                { 1, "p1" },
                { 2, "p2" }
            },
                                      new Dictionary <int, string>
            {
                { 0, "t1" },
                { 1, "t2" }
            },
                                      new Dictionary <int, List <InArc> >()
            {
                { 0, new List <InArc>()
                  {
                      new InArc(0), new InArc(1)
                  } },
                { 1, new List <InArc>()
                  {
                      new InArc(1), new InArc(2)
                  } }
            },
                                      new Dictionary <int, List <OutArc> >()
            {
            },
                                      new Dictionary <int, int>()
            {
                { 0, 1 }, { 1, 2 }
            });
            var enabledTransitions = p.AllEnabledTransitions(m);

            Assert.AreEqual(2, enabledTransitions.Count());
            Assert.IsTrue(enabledTransitions.Contains(0));
            Assert.IsTrue(enabledTransitions.Contains(1));
            Assert.IsTrue(p.IsConflicted(m));
        }
예제 #9
0
        public void TestOutgoingWeight()
        {
            var m = new Marking(2, new Dictionary <int, int> {
                { 0, 1 }, { 1, 0 }
            });
            var p = new GraphPetriNet(
                "p",
                new Dictionary <int, string> {
                { 0, "p0" },
                { 1, "p1" }
            },
                new Dictionary <int, string> {
                { 0, "t0" }
            },
                new Dictionary <int, List <InArc> >()
            {
                { 0, new List <InArc>()
                  {
                      new InArc(0)
                  } }
            },
                new Dictionary <int, List <OutArc> >()
            {
                { 0, new List <OutArc>()
                  {
                      new OutArc(1)
                      {
                          Weight = 5
                      }
                  } }
            }
                );

            AssertMarkings(m, new Dictionary <int, int> {
                { 0, 1 },
                { 1, 0 }
            });
            m = p.Fire(m);
            AssertMarkings(m, new Dictionary <int, int> {
                { 0, 0 },
                { 1, 5 }
            });
        }
        public void TestTransitionFunctionExecution()
        {
            var m = new Marking(2,
                                new Dictionary <int, int>
            {
                { 0, 2 },
                { 1, 0 }
            });
            var p = new GraphPetriNet("p",
                                      new Dictionary <int, string> {
                { 0, "p0" },
                { 1, "p1" }
            },
                                      new Dictionary <int, string>
            {
                { 0, "t0" }
            },
                                      new Dictionary <int, List <InArc> >()
            {
                { 0, new List <InArc>()
                  {
                      new InArc(0)
                  } }
            },
                                      new Dictionary <int, List <OutArc> >()
            {
                { 0, new List <OutArc>()
                  {
                      new OutArc(1)
                  } }
            });

            Assert.AreEqual(2, m[0]);
            var someLocal = 0;

            m[0] = 1;
            p.RegisterFunction(0, (t) => someLocal += 1);
            p.Fire(m);
            Assert.AreEqual(1, someLocal);
        }
        public void TestCompareWithOldConstructionTechnique()
        {
            var m = new Marking(3,
                                new Dictionary <int, int>
            {
                { (int)Places.p1, 0 },
                { (int)Places.p2, 0 },
                { (int)Places.p3, 0 }
            });
            var p = new GraphPetriNet("p",
                                      new Dictionary <int, string> {
                { (int)Places.p1, "p1" },
                { (int)Places.p2, "p2" },
                { (int)Places.p3, "p3" }
            },
                                      new Dictionary <int, string>
            {
                { (int)Transitions.t1, "t1" }
            },
                                      new Dictionary <int, List <InArc> >()
            {
                { (int)Transitions.t1, new List <InArc>()
                  {
                      new InArc((int)Places.p1)
                  } }
            },
                                      new Dictionary <int, List <OutArc> >()
            {
                { (int)Transitions.t1, new List <OutArc>()
                  {
                      new OutArc((int)Places.p2),
                      new OutArc((int)Places.p3)
                  } }
            });

            var pnc = CreatePetriNet.Called("p")
                      .WithPlaces("p1",
                                  "p2",
                                  "p3")
                      .AndTransitions("t1")
                      .With("t1").FedBy("p1")
                      .And().With("t1").Feeding("p2",
                                                "p3")
                      .Done();
            var p2 = pnc.CreateNet <GraphPetriNet>();

            m[(int)Places.p1] = 1;

            var m2 = p.Fire(m);
            var m3 = p2.Fire(m);

            AssertMarkings(m2, new Dictionary <int, double> {
                { (int)Places.p1, 0 },
                { (int)Places.p2, 1 },
                { (int)Places.p3, 1 }
            });
            AssertMarkings(m3, new Dictionary <int, double> {
                { (int)Places.p1, 0 },
                { (int)Places.p2, 1 },
                { (int)Places.p3, 1 }
            });
        }