Inheritance: PetriNetBase
Esempio n. 1
0
        public T CreateNet <T>() where T : class
        {
            T result = null;

            if (typeof(T).Equals(typeof(GraphPetriNet)))
            {
                var tmp = new GraphPetriNet(
                    Name,
                    Places,
                    Transitions,
                    InArcs,
                    OutArcs);
                foreach (var capacity in PlaceCapacities)
                {
                    tmp.PlaceCapacities[PlaceIndex(capacity.Key)] = capacity.Value;
                }
                result = tmp as T;
            }
            if (typeof(T).Equals(typeof(MatrixPetriNet)))
            {
                result = new MatrixPetriNet(
                    Name,
                    Places,
                    Transitions,
                    InArcs,
                    OutArcs) as T;
            }
            if (result == null)
            {
                throw new ApplicationException("Unrecognised petri net type requested");
            }
            return(result);
        }
Esempio n. 2
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;
 }
Esempio n. 3
0
 private static GraphPetriNet CreatePNTwoInTwoOut()
 {
     var p = new GraphPetriNet(
         "p",
         new Dictionary<int, string> {
             {0, "p0"},
             {1, "p1"},
             {2, "p2"},
             {3, "p3"}
         },
         //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)}}
         },
         new Dictionary<int, List<OutArc>>(){
             {0, new List<OutArc>(){new OutArc(2),new OutArc(3)}}
         }
       );
     return p;
 }
 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));
 }
Esempio n. 5
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 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 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 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));
 }
Esempio n. 10
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);
            }
        }