Example #1
0
        }                                                   // Constructor

        public void BuildGA(Petri p)
        {
            if (PROJECT)
            {
                p.UpdateLogs("Couldn't set GrauA up, because Project is already active");
                return;
            }
            p.CreateSlot("L1", 0);         // 0
            p.CreateSlot("L2", 0);         // 1
            p.CreateSlot("L3", 0);         // 2
            p.CreateSlot("L4", 0);         // 3
            p.CreateSlot("L5", 0);         // 4
            p.CreateSlot("L6", 0);         // 5
            p.CreateSlot("L7", 0);         // 6

            p.CreateTransition("T1");      // 0
            p.CreateTransition("T2");      // 1

            p.CreateConnectionST(0, 0, 2); // L1 to T1, weight 2
            p.CreateConnectionST(1, 0);    //  L2 to T1, weight 1
            p.CreateConnectionST(2, 0);    //  L3 to T1, weight 1

            p.CreateConnectionTS(4, 0, 3); // T1 to L5, weight 3
            p.CreateConnectionTS(6, 0);    //  T1 to L7, weight 1

            p.CreateConnectionST(3, 1);    // L4 to T2, weight 1
            p.CreateConnectionST(4, 1, 6); // L5 to T2, weight 6

            p.CreateConnectionTS(5, 1);    // T2 to L6, weight 1
            p.CreateConnectionTS(6, 1, 2); // T2 to L7, wight 2

            GA = true;
        }
Example #2
0
        public void GATokens(Petri p)
        {
            if (GA)
            {
                p.AddTokensToSlot(0, 20);
                p.AddTokensToSlot(1, 20);
                p.AddTokensToSlot(2, 20);
                p.AddTokensToSlot(3, 20);

                string l = "Gave 20 tokens to L1, L2, L3 and L4";
                p.UpdateLogs(l);
                p.listStr = "";
            }
            else
            {
                p.UpdateLogs("Couldn't add tokens, because the GrauA net isn't active. Use the 'GrauA' command first to set it up");
            }
        }
Example #3
0
        public void EvolexNet(Petri p)
        {
            if (GA)
            {
                p.UpdateLogs("Couldn't set Project up, because GrauA is already active");
                return;
            }
            p.CreateSlot("Carnivore Creatures", 0);                  // 0
            p.CreateSlot("Herbivore Creatures", 0);                  // 1
            p.CreateSlot("Prey", 0);                                 // 2
            p.CreateSlot("Fruit Trees", 0);                          // 3
            p.CreateSlot("Available Fruit", 0);                      // 4
            p.CreateSlot("Targeted Fruit", 0);                       // 5

            p.CreateTransition("Look For Prey");                     // 0
            p.CreateTransition("Look For Fruit");                    // 1
            p.CreateTransition("Move On (Carnivore)");               // 2
            p.CreateTransition("Attempt Escape (Herbivore)");        // 3
            p.CreateTransition("Spawn Fruits");                      // 4
            p.CreateTransition("Hunt Prey");                         // 5
            p.CreateTransition("Eat Fruit");                         // 6

            p.CreateConnectionST(0, 0);                              // Carnivore Creature to Look For Prey
            p.CreateConnectionST(0, 2);                              // Carnivore Creature to Idle (Carnivore)
            p.CreateConnectionST(1, 0);                              // Herbivore Creature to Look For Prey
            p.CreateConnectionST(1, 2, 1, ConnectionType.Inhibitor); // Herbivore Creature to Move On (Carnivore) - Inhibitor
            p.CreateConnectionST(1, 1);                              // Herbivore Creature to Look For Fruit
            p.CreateConnectionST(1, 3);                              // Herbivore Creature to Attempt Escape (Herbivore)
            p.CreateConnectionST(3, 4, 2);                           // Fruit Trees to Spawn Fruits - Weight 2
            p.CreateConnectionST(4, 1);                              // Available Fruit to Look For Fruit
            p.CreateConnectionST(4, 3, 1, ConnectionType.Inhibitor); // Available Fruit to Attempt Escape (Herbivore) - Inhibitor
            p.CreateConnectionST(2, 5);                              // Prey to Hunt Prey
            p.CreateConnectionST(5, 6);                              // Targeted Fruit to Eat Fruit

            p.CreateConnectionTS(2, 0);                              // Look For Prey to Prey
            p.CreateConnectionTS(0, 5);                              // Hunt Prey to Carnivore Creatures
            p.CreateConnectionTS(4, 4, 5);                           // Spawn Fruits to Available Fruits - Weight 5
            p.CreateConnectionTS(3, 4);                              // Spawn Fruits to Fruit Trees
            p.CreateConnectionTS(5, 1);                              // Look For Fruit to Targeted Fruit
            p.CreateConnectionTS(1, 6);                              // Eat Fruit to Herbivore Creatures

            PROJECT = true;
        }
Example #4
0
        public void EvolexTokens(Petri p)
        {
            if (PROJECT)
            {
                p.AddTokensToSlot(1, 25);
                p.AddTokensToSlot(0, 2);
                p.AddTokensToSlot(3, 20);
                p.AddTokensToSlot(4, 100);

                p.UpdateLogs("Spawning 25 herbivore creatures");
                p.UpdateLogs("Spawning 2 carnivore creatures");
                p.UpdateLogs("Spawning 20 fruit trees");
                p.UpdateLogs("Spawning 100 available fruits");

                p.listStr = "";
            }
            else
            {
                p.UpdateLogs("Couldn't add tokens, because the Project net isn't active. Use the 'Project' command first to set it up");
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            Petri     p    = new Petri();
            SampleNet sn   = new SampleNet();
            bool      exit = false;

            while (exit == false)
            {
                Console.Clear();
                if (p.listStr != "")
                {
                    Console.Write(p.listStr + "\n");
                }
                Console.WriteLine("=====");
                Console.WriteLine("POSSIBLE ACTIONS: ");
                Console.WriteLine("Run: Runs the net once; Alias: r");
                Console.WriteLine("RunAll: Runs until transitions are all disabled; Alias: ra\n");
                Console.WriteLine("CreateSlot: Creates a new slot; Alias: cs ");
                Console.WriteLine("ListSlots: Lists all existing slots; Alias: ls \n");
                Console.WriteLine("AddTokens: Adds tokens to a slot; Alias: at");
                Console.WriteLine("RemoveTokens: Removes tokens to a slot; Alias: rt \n");
                Console.WriteLine("ClearTokens: Removes all tokens to a slot; Alias: crt \n");
                Console.WriteLine("CreateTransition: Creates a new transition; Alias: ct");
                Console.WriteLine("ListTransitions: Lists all existing transitions; Alias: lt \n");
                Console.WriteLine("ConnectSlotToTransition: Connects slot to a transition; Alias: cst");
                Console.WriteLine("ConnectTransitionToSlot: Connects a transition to a slot; Alias: cts");
                Console.WriteLine("ListConnections: Lists all existing connections; Alias: lc \n");
                Console.WriteLine("ListAll: Lists everything; Alias: la ");
                Console.WriteLine("Logs: Lists all logs; Alias: lg \n");

                Console.WriteLine("GrauA: Builds Grau A's sample; Alias: ga");
                Console.WriteLine("TokensGA: Gives 20 tokens to L1, L2, L3 and L4; Alias: tga\n");

                Console.WriteLine("Project: Builds Project's sample; Alias: pj");
                Console.WriteLine("TokensProject: Spawns some things for the project's net; Alias: tpj\n");

                Console.WriteLine("Nuke: Clears everything; Alias: nk");
                Console.WriteLine("Exit: Exits the program; Alias: x");
                Console.WriteLine("=====");
                Console.WriteLine("HISTORY\n");
                if (!p.allLogs)
                {
                    for (int i = 0; i < 5 && i < p.log.ToArray().Length; i++)
                    {
                        Console.WriteLine(p.log[p.log.ToArray().Length - 1 - i]);
                    }
                }
                else
                {
                    foreach (string log in p.log)
                    {
                        Console.WriteLine(log);
                    }
                    p.allLogs = false;
                }
                Console.WriteLine("=====");

                p.listStr = "";

                Console.Write("Command: ");
                string input;
                input = Console.ReadLine();
                input = input.ToLower();


                if (input == "run" || input == "r")
                {
                    p.Run();
                }
                else if (input == "runall" || input == "ra")
                {
                    p.RunAll();
                }

                else if (input == "createslot" || input == "cs")
                {
                    p.CreateSlotLoop();
                }
                else if (input == "listslots" || input == "ls")
                {
                    p.ListSlots();
                }

                else if (input == "addtokens" || input == "at")
                {
                    p.AddTokenManually();
                }
                else if (input == "removetokens" || input == "rt")
                {
                    p.AddTokenManually();
                }
                else if (input == "cleartokens" || input == "crt")
                {
                    p.AddTokenManually();
                }

                else if (input == "createtransition" || input == "ct")
                {
                    p.CreateTransitionLoop();
                }
                else if (input == "listtransitions" || input == "lt")
                {
                    p.ListTransitions();
                }

                else if (input == "connectlottotransition" || input == "cst")
                {
                    p.CreateConnectionSTLoop();
                }
                else if (input == "connecttransitiontoslot" || input == "cts")
                {
                    p.CreateConnectionTSLoop();
                }
                else if (input == "listconnections" || input == "lc")
                {
                    p.ListConnections();
                }

                else if (input == "listall" || input == "la")
                {
                    p.ListSlots();
                    p.ListTransitions();
                    p.ListConnections();
                }

                else if (input == "logs" || input == "lg")
                {
                    p.allLogs = true;
                }

                else if (input == "graua" || input == "ga")
                {
                    sn.BuildGA(p);
                }
                else if (input == "tokensga" || input == "tga")
                {
                    sn.GATokens(p);
                }

                else if (input == "project" || input == "pj")
                {
                    sn.EvolexNet(p);
                }
                else if (input == "tokensproject" || input == "tpj")
                {
                    sn.EvolexTokens(p);
                }

                else if (input == "nuke" || input == "nk")
                {
                    p  = new Petri();
                    sn = new SampleNet();
                }

                else if (input == "exit" || input == "x")
                {
                    exit = true;
                }


                else
                {
                    p.listStr = "(!)INVALID COMMAND(!)";
                }
            }
        }