Fire() public method

invokes the first enabled transition in the petri net under the supplied Marking.
This method will not have any side effects on the Marking passed into the function or on the net itself. This method works by choosing the next transition to fire randomly.
public Fire ( Marking m ) : Marking
m Marking The marking under which transition activation is calculated.
return Marking
Ejemplo n.º 1
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 }});
 }
Ejemplo n.º 2
0
 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));
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
        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);
            }
        }