Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            var env = new EnvironmentMas(delayAfterTurn: 10, randomOrder: false, parallel: false);

            var gridAgent = new GridAgent();

            gridAgent.UsingObservables = true;
            env.Add(gridAgent, "GridAgent");

            int size = 25;

            env.Memory["Size"] = size;

            var sr = new StreamReader("patterns.txt");

            for (int y = 0; y < size; y++)
            {
                string[] lineToks = sr.ReadLine().Split();

                for (int x = 0; x < size; x++)
                {
                    string state = (lineToks[x] == "x") ? "Living" : "Dead";
                    var    a     = new CellAgent(state, x, y);
                    a.UsingObservables = true;
                    env.Add(a, $"Agent-{x}-{y}");
                }
            }

            sr.Close();

            env.Start();
        }
Ejemplo n.º 2
0
        public override void RunMas(EnvironmentMas env)
        {
            string home = env.ContainerName;

            if (home == "")
            {
                Global.Rtb.AppendText("Container not activated.\r\n");
                return;
            }

            Global.Rtb.AppendText($"This is {home}\r\n");

            switch (home)
            {
            case "Container1":
                var m = new PingAgent();
                env.Add(m, "ping-agent");
                break;

            case "Container2":
                var a = new PongAgent();
                env.Add(a, "pong-agent");
                break;

            default:
                break;
            }

            env.Start();
        }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            var env = new EnvironmentMas(1000);

            for (int i = 1; i <= 3; i++) // MaxLevel
            {
                for (int j = 1; j <= 3; j++)
                {
                    for (int k = 1; k <= 3; k++)
                    {
                        var workerAgent = new WorkerAgent(i, j, k);
                        env.Add(workerAgent, $"worker{i}{j}{k}");
                    }
                }
            }

            var calculatorAgent = new CalculatorAgent();

            env.Add(calculatorAgent, "shapley");

            var managerAgent = new ManagerAgent();

            env.Add(managerAgent, "manager");

            env.Memory.Add("NoAttributes", 3);
            env.Memory.Add("MaxLevel", 3);
            env.Memory.Add("NoTasks", 100);
            env.Memory.Add("NoBids", 3);

            env.Start();
        }
Ejemplo n.º 4
0
        private static void Main(string[] args)
        {
            int    n   = 5;
            double sum = 0;

            Global.MyStopWatch = new Stopwatch();

            for (int t = 0; t < n; t++)
            {
                Console.WriteLine($"Trial {t + 1}");
                Global.NoMessages = 0;

                Global.MyStopWatch.Restart();

                //var env = new EnvironmentMas(noTurns: 10000, parallel: true);  // 10 mil msg, ~1516 ms => 6462.079 msg / ms
                var env = new EnvironmentMas(noTurns: 10000, parallel: false);  // ~1351129 msg, ~394 ms => 3395.464 msg / ms

                for (int i = 0; i < Global.NoAgents; i++)
                {
                    var a = new MyAgent(i);
                    env.Add(a, $"a{i}");
                }

                env.Start();

                Global.MyStopWatch.Stop();

                Console.WriteLine($"{Global.NoMessages} msg");
                Console.WriteLine($"{Global.MyStopWatch.ElapsedMilliseconds} ms\n");

                sum += (double)Global.NoMessages / (double)Global.MyStopWatch.ElapsedMilliseconds;
            }

            Console.WriteLine($"{sum / n:F3} msg/ms");
        }
Ejemplo n.º 5
0
        private static void Main(string[] args)
        {
            var env = new EnvironmentMas(100);

            var brokerAgent = new BrokerAgent(); env.Add(brokerAgent, "broker");

            ProviderAgent pa1 = new ProviderAgent(ServiceType.Add); env.Add(pa1, "provider1");
            ProviderAgent pa2 = new ProviderAgent(ServiceType.Add); env.Add(pa2, "provider2");
            ProviderAgent pa3 = new ProviderAgent(ServiceType.Sub); env.Add(pa3, "provider3");
            ProviderAgent pa4 = new ProviderAgent(ServiceType.Sub); env.Add(pa4, "provider4");

            ClientAgent ca1 = new ClientAgent(ServiceType.Add); env.Add(ca1, "client1");
            ClientAgent ca2 = new ClientAgent(ServiceType.Add); env.Add(ca2, "client2");
            ClientAgent ca3 = new ClientAgent(ServiceType.Sub); env.Add(ca3, "client3");
            ClientAgent ca4 = new ClientAgent(ServiceType.Sub); env.Add(ca4, "client4");

            env.Start();

            pa1.Send("provider1", "force-unregister");

            ProviderAgent pa5 = new ProviderAgent(ServiceType.Sub); env.Add(pa5, "provider5");

            env.Continue(100);

            ClientAgent ca5 = new ClientAgent(ServiceType.Add); env.Add(ca5, "client5");
            ClientAgent ca6 = new ClientAgent(ServiceType.Sub); env.Add(ca6, "client6");

            env.Continue(100);
        }
Ejemplo n.º 6
0
        private static void Main(string[] args)
        {
            var env = new EnvironmentMas();
            var a1  = new Agent1(); env.Add(a1, "a1");
            var a2  = new Agent2(); env.Add(a2, "a2");

            env.Start();
        }
Ejemplo n.º 7
0
        private static void Main(string[] args)
        {
            var env = new EnvironmentMas(noTurns: 100, parallel: false);
            var a1  = new MyAgent1(); env.Add(a1, "agent1");
            var a2  = new MyAgent2(); env.Add(a2, "agent2");

            env.Start();
        }
Ejemplo n.º 8
0
        private static void Main(string[] args)
        {
            var env = new EnvironmentMas(noTurns: 100);
            var a1  = new MyAgent(); env.Add(a1, "agent1");
            var a2  = new MyAgent(); env.Add(a2, "agent2");
            var m   = new MonitorAgent(); env.Add(m, "monitor");

            env.Start();
        }
Ejemplo n.º 9
0
        private static void Main(string[] args)
        {
            var env         = new EnvironmentMas();
            var mapAgent    = new MapAgent(); env.Add(mapAgent, "map");
            var searchAgent = new SearchAgent(); env.Add(searchAgent, "agent1");

            env.Memory.Add("MapName", "Pendulum");
            //env.Memory.Add("MapName", "StrangeHeuristic");
            env.Memory.Add("Delay", 100);

            env.Start();
        }
Ejemplo n.º 10
0
        private static void Main(string[] args)
        {
            var env    = new EnvironmentMas(randomOrder: false, parallel: false);
            var agent1 = new BargainingAgent(); env.Add(agent1, "agent1");
            var agent2 = new BargainingAgent(); env.Add(agent2, "agent2");

            env.Memory["Eps"]      = 0.1;
            env.Memory["Utility1"] = (Func <double, double>)((double deal) => 5.0 - deal);
            env.Memory["Utility2"] = (Func <double, double>)((double deal) => 2.0 / 3.0 * deal);

            env.Start();
        }
Ejemplo n.º 11
0
        private static void Main(string[] args)
        {
            int noAgents = 5;

            var env = new EnvironmentMas(noTurns: 5, delayAfterTurn: 1000);

            env.Add(new WriterAgent(), "writer");
            for (int i = 1; i <= noAgents; i++)
            {
                env.Add(new MyAgent(), $"a{i}");
            }
            env.Start();
        }
Ejemplo n.º 12
0
        public override void RunMas(EnvironmentMas env)
        {
            string home = env.ContainerName;

            if (home == "")
            {
                Global.Rtb.AppendText("Container not activated.\r\n");
                return;
            }

            Global.Rtb.AppendText($"This is {home}\r\n");

            switch (home)
            {
            case "Container1":
                var m = new MobileAgent();
                env.Add(m, "mobile-k1");

                for (int i = 1; i <= 1; i++)
                {
                    var a = new StaticAgent();
                    env.Add(a, $"a{i}-k1");
                }
                break;

            case "Container2":
                for (int i = 1; i <= 2; i++)
                {
                    var a = new StaticAgent();
                    env.Add(a, $"b{i}-k2");
                }
                break;

            case "Container3":
                for (int i = 1; i <= 3; i++)
                {
                    var a = new StaticAgent();
                    env.Add(a, $"c{i}-k3");
                }
                break;

            default:
                break;
            }

            env.Start();
        }
Ejemplo n.º 13
0
        private static void Main(string[] args)
        {
            var sw = new Stopwatch();

            sw.Start();

            var env = new EnvironmentMas();  // 10000 => 3800 ms
            //var env = new EnvironmentMas(parallel: false);  // 10000 => 600 ms, 100000 => 92 s

            var a = new MyAgent(0, -1);

            env.Add(a, "a0");  // the root agent

            env.Start();

            sw.Stop();
            Console.WriteLine($"{sw.ElapsedMilliseconds:F3} ms");
        }
Ejemplo n.º 14
0
        private static void Main(string[] args)
        {
            int noWorkers = 5;

            var env = new EnvironmentMas(noTurns: 20, parallel: true);

            ManagerAgent manager = new ManagerAgent();

            env.Add(manager, "Manager");

            for (int i = 0; i < noWorkers; i++)
            {
                WorkerAgent worker = new WorkerAgent();
                env.Add(worker, $"Worker{i}");
            }

            env.Start();
        }
Ejemplo n.º 15
0
        private static void Main(string[] args)
        {
            var env = new EnvironmentMas(delayAfterTurn: 100); // no turn limit, run in parallel

            var planetAgent = new PlanetAgent();

            env.Add(planetAgent, "planet");

            for (int i = 1; i <= 5; i++) // 5 explorers
            {
                var explorerAgent = new ExplorerAgent();
                env.Add(explorerAgent, $"explorer{i}");
            }

            env.Memory.Add("Size", 11);
            env.Memory.Add("NoResources", 10);

            env.Start();
        }
Ejemplo n.º 16
0
        private static void Main(string[] args)
        {
            var env = new EnvironmentMas();
            //var env = new EnvironmentMas(parallel: false, randomOrder: true);

            var rand = new Random();

            for (int i = 1; i <= Settings.NoBidders; i++)
            {
                int agentValuation = Settings.MinPrice + rand.Next(Settings.MaxPrice - Settings.MinPrice);
                var bidderAgent    = new BidderAgent(agentValuation);
                env.Add(bidderAgent, $"bidder{i:D2}");
            }

            var auctioneerAgent = new AuctioneerAgent();

            env.Add(auctioneerAgent, "auctioneer");

            env.Start();
        }
Ejemplo n.º 17
0
        private static void Main(string[] args)
        {
            // inefficient, uses broadcast to simulate public open-cry auction

            var env = new EnvironmentMas(randomOrder: false, parallel: false);

            var auctioneerAgent = new AuctioneerAgent();

            env.Add(auctioneerAgent, "auctioneer");

            var rand = new Random();

            for (int i = 1; i <= Settings.NoBidders; i++)
            {
                int agentValuation = Settings.MinPrice + rand.Next(Settings.MaxPrice - Settings.MinPrice);
                var bidderAgent    = new BidderAgent(agentValuation);
                env.Add(bidderAgent, $"bidder{i:D2}");
            }

            env.Start();
        }
Ejemplo n.º 18
0
        private static void Main(string[] args)
        {
            // more efficient, each bidder only talks to the auctioneer

            var env = new EnvironmentMas();

            var rand = new Random();

            for (int i = 1; i <= Settings.NoBidders; i++)
            {
                int agentValuation = Settings.MinPrice + rand.Next(Settings.MaxPrice - Settings.MinPrice);
                var bidderAgent    = new BidderAgent(agentValuation);
                env.Add(bidderAgent, $"bidder{i:D2}");
            }

            var auctioneerAgent = new AuctioneerAgent();

            env.Add(auctioneerAgent, "auctioneer");

            env.Start();
        }
Ejemplo n.º 19
0
        public static void Main(string[] args)
        {
            var env = new EnvironmentMas(noTurns: 10, randomOrder: false, parallel: false);

            var a1 = new Agent1();

            a1.UsingObservables = true;
            env.Add(a1, "Agent1");

            var a2 = new Agent2();

            a2.UsingObservables = true;
            env.Add(a2, "Agent2");

            var a3 = new Agent3();

            a3.UsingObservables = true;
            env.Add(a3, "Agent3");

            env.Start();
        }
Ejemplo n.º 20
0
        private static void Main(string[] args)
        {
            var env = new EnvironmentMas(noTurns: 100, randomOrder: false);

            Settings.AisLying = false;
            var agentA  = new BeneficiaryAgent(); env.Add(agentA, "a");
            var agentB  = new BeneficiaryAgent(); env.Add(agentB, "b");
            var agentC  = new BeneficiaryAgent(); env.Add(agentC, "c");
            var dmAgent = new DecisionMakerAgent(); env.Add(dmAgent, "dm");

            env.Start();

            Console.WriteLine("\r\n--------------------------------------------\r\n");

            env = new EnvironmentMas(noTurns: 100, randomOrder: false);

            Settings.AisLying = true;
            agentA            = new BeneficiaryAgent(); env.Add(agentA, "a");
            agentB            = new BeneficiaryAgent(); env.Add(agentB, "b");
            agentC            = new BeneficiaryAgent(); env.Add(agentC, "c");
            dmAgent           = new DecisionMakerAgent(); env.Add(dmAgent, "dm");

            env.Start();
        }