Example #1
0
        public void CreateConnectionTSLoop()
        {
            int            slotID  = 0;
            int            transID = 0;
            int            weight  = 1;
            ConnectionType type    = ConnectionType.Normal;

            Console.WriteLine("=====");
            ListTransitions();
            Console.WriteLine("=====");

            Console.Write("Transition's ID: ");
            Int32.TryParse(Console.ReadLine(), out transID);

            if (transID < 0)
            {
                Console.WriteLine("Failed");
                return;
            }

            Console.WriteLine("=====");
            ListSlots();
            Console.WriteLine("=====");

            Console.Write("Slot's ID: ");
            Int32.TryParse(Console.ReadLine(), out slotID);

            if (slotID < 0)
            {
                Console.WriteLine("Failed");
                return;
            }

            Console.Write("Connection's Weight: ");
            Int32.TryParse(Console.ReadLine(), out weight);

            if (weight < 0)
            {
                Console.WriteLine("Forcing value of 1 to the connection");
                weight = 1;
                return;
            }



            PetriConnection c = new PetriConnection(connectionsList.ToArray().Length, slotID, transID, true, weight, type);

            transitionsList[transID].outputs.Add(c);
            slotsList[slotID].inputs.Add(c);
            connectionsList.Add(c);

            PetriTransition trans = transitionsList[transID];
            PetriSlot       slot  = slotsList[slotID];
            string          l     = "Created a connection from the transition [" + trans.name + "(" + trans.id + ")" + "] to the slot [" + slot.name + "(" + slot.id + ")]" + "Id: " + c.id;

            UpdateLogs(l);
            listStr = "";
        }
Example #2
0
        public void CreateTransition(string transName)
        {
            string name = transName;

            PetriTransition t = new PetriTransition(transitionsList.ToArray().Length, name);

            transitionsList.Add(t);

            string l = "Created a transition. Id: " + (transitionsList.ToArray().Length - 1) + "; Name: " + name + ";";

            UpdateLogs(l);
        }
Example #3
0
        public void CreateTransitionLoop()
        {
            Console.Write("Transition's name: ");
            string name = Console.ReadLine();

            PetriTransition t = new PetriTransition(transitionsList.ToArray().Length, name);

            transitionsList.Add(t);

            string l = "Created a transition. Id: " + (transitionsList.ToArray().Length - 1) + "; Name: " + name + ";";

            UpdateLogs(l);
        }
Example #4
0
        public void ListConnections()
        {
            foreach (PetriConnection c in connectionsList)
            {
                PetriSlot       slot  = slotsList[c.s];
                PetriTransition trans = transitionsList[c.t];

                if (c.output)
                {
                    listStr += "Connection " + c.id + ": " + "From the transition [" + trans.name + "(" + trans.id + ")" + "] to the slot [" + slot.name + "(" + slot.id + ")]; " + "Weight: " + c.weight + "\n";
                    Console.WriteLine("Connection " + c.id + ": " + "From the transition [" + trans.name + "(" + trans.id + ")" + "] to the slot [" + slot.name + "(" + slot.id + ")]; " + "Weight: " + c.weight + "\n");
                }
                else
                {
                    listStr += "Connection " + c.id + ": " + "From the slot [" + slot.name + "(" + slot.id + ")" + "] to the transition [" + trans.name + "(" + trans.id + ")]; " + "Weight: " + c.weight + "\n";
                    Console.WriteLine("Connection " + c.id + ": " + "From the slot [" + slot.name + "(" + slot.id + ")" + "] to the transition [" + trans.name + "(" + trans.id + ")]; " + "Weight: " + c.weight + "\n");
                }
            }
        }
Example #5
0
        public void CreateConnectionTS(int slot, int transition, int w = 1)
        {
            int            slotID  = slot;
            int            transID = transition;
            int            weight  = w;
            ConnectionType type    = ConnectionType.Normal;

            PetriConnection c = new PetriConnection(connectionsList.ToArray().Length, slotID, transID, true, weight, type);

            transitionsList[transID].outputs.Add(c);
            slotsList[slotID].inputs.Add(c);
            connectionsList.Add(c);

            PetriTransition trans = transitionsList[transID];
            PetriSlot       pslot = slotsList[slotID];
            string          l     = "Created a connection from the transition [" + trans.name + "(" + trans.id + ")" + "] to the slot [" + pslot.name + "(" + pslot.id + ")]" + "Id: " + c.id;

            UpdateLogs(l);
            listStr = "";
        }
Example #6
0
        public void CreateConnectionSTLoop()
        {
            int            slotID  = 0;
            int            transID = 0;
            int            weight  = 1;
            string         inputType;
            ConnectionType type = ConnectionType.Normal;

            bool testing = false;

            while (testing == false)
            {
                Console.WriteLine("=====");
                ListSlots();
                Console.WriteLine("=====");

                Console.Write("Slot's ID: ");
                Int32.TryParse(Console.ReadLine(), out slotID);

                if (slotID < 0 || slotID >= slotsList.ToArray().Length)
                {
                    Console.WriteLine("Failed");
                }
                else
                {
                    testing = true;
                }
            }

            testing = false;

            while (testing == false)
            {
                Console.WriteLine("=====");
                ListTransitions();
                Console.WriteLine("=====");

                Console.Write("Transition's ID: ");
                Int32.TryParse(Console.ReadLine(), out transID);
                if (transID < 0 || transID >= transitionsList.ToArray().Length)
                {
                    Console.WriteLine("Failed");
                }
                else
                {
                    testing = true;
                }
            }
            testing = false;

            if (weight < 0)
            {
                Console.WriteLine("Forcing value of 1 to the connection");
                weight = 1;
                return;
            }

            Console.WriteLine("=====");
            Console.WriteLine("Possible Types: ");
            Console.WriteLine("- Normal");
            Console.WriteLine("- Inhibitor");
            Console.WriteLine("- Reset");
            Console.WriteLine("=====");


            while (!testing)
            {
                Console.Write("Connection Type: ");
                inputType = Console.ReadLine().ToLower();

                if (inputType == "normal" || inputType == "n")
                {
                    type    = ConnectionType.Normal;
                    testing = true;
                }
                else if (inputType == "inhibitor" || inputType == "i")
                {
                    type    = ConnectionType.Inhibitor;
                    testing = true;
                }
                else if (inputType == "reset" || inputType == "r")
                {
                    type    = ConnectionType.Reset;
                    testing = true;
                }
                else
                {
                    Console.WriteLine("Incorrect type");
                }
            }

            if (type == ConnectionType.Normal)
            {
                Console.Write("Connection's Weight: ");
                Int32.TryParse(Console.ReadLine(), out weight);
            }
            else
            {
                weight = 0;
            }



            PetriConnection c = new PetriConnection(connectionsList.ToArray().Length, slotID, transID, false, weight, type);

            transitionsList[transID].inputs.Add(c);
            slotsList[slotID].outputs.Add(c);
            connectionsList.Add(c);


            PetriTransition trans = transitionsList[transID];
            PetriSlot       slot  = slotsList[slotID];
            string          l     = "Created a connection from the slot [" + slot.name + "(" + slot.id + ")" + "] to the transition [" + trans.name + "(" + trans.id + ")]" + "Id: " + c.id;;

            UpdateLogs(l);
            listStr = "";
        }