示例#1
0
        private static void fillAgents()
        {
            List <IAgent> p = new List <IAgent>(); // создаем пустой список агентов

            p.AddRange(Adolescent.AdolescentList(Enums.HealthState.Infectious, 6, "LocationProbabilities"));
            p.AddRange(Adolescent.AdolescentList(Enums.HealthState.Susceptible, 750, "LocationProbabilities"));
            p.AddRange(Adult.AdultList(Enums.HealthState.Infectious, 6, "LocationProbabilities"));
            p.AddRange(Adult.AdultList(Enums.HealthState.Susceptible, 2450, "LocationProbabilities"));
            p.AddRange(Child.ChildList(Enums.HealthState.Infectious, 6, "LocationProbabilities"));
            p.AddRange(Child.ChildList(Enums.HealthState.Susceptible, 250, "LocationProbabilities"));
            p.AddRange(Elder.ElderList(Enums.HealthState.Infectious, 6, "LocationProbabilities"));
            p.AddRange(Elder.ElderList(Enums.HealthState.Susceptible, 900, "LocationProbabilities"));
            p.AddRange(Youngster.YoungsterList(Enums.HealthState.Infectious, 6, "LocationProbabilities"));
            p.AddRange(Youngster.YoungsterList(Enums.HealthState.Susceptible, 650, "LocationProbabilities"));

            GlobalAgentDescriptorTable.AddAgents(p); // добавляем созданные агенты в класс, в котором хранятся все агенты
        }
示例#2
0
        private void fillContainers()
        {
            int homeCount       = 10000;
            int hospitalCount   = 4;
            int mallCount       = 5;
            int officeCount     = 500;
            int univercityCount = 1;
            int schoolCount     = 23;
            int nurseryCount    = 2;
            //int homeCount = 1;
            //int hospitalCount = 1;
            //int mallCount = 1;
            //int officeCount = 1;
            //int univercityCount = 1;
            //int schoolCount = 1;
            //int nurseryCount = 1;

            List <Message> messagesToSend = new List <Message>();
            int            currentId      = 0;

            // Messages for home containers creation
            List <AddContainerMessage> homes = new List <AddContainerMessage>();

            for (int i = 0; i < homeCount; i++)
            {
                homes.Add(new AddContainerMessage(MessageTransportSystem.Instance.Id, Enums.ContainerType.Home, currentId, 50, 12));
                Containers.Instance.Add(currentId, new Home(currentId, 50, 12));
                currentId++;
            }
            // Everyone at home at the beginning
            List <Person> p = new List <Person>();

            p.AddRange(Adolescent.AdolescentList(Enums.HealthState.Infectious, 4, "LocationProbabilities"));
            p.AddRange(Adolescent.AdolescentList(Enums.HealthState.Susceptible, 4534, "LocationProbabilities"));
            p.AddRange(Adult.AdultList(Enums.HealthState.Infectious, 4, "LocationProbabilities"));
            p.AddRange(Adult.AdultList(Enums.HealthState.Susceptible, 14812, "LocationProbabilities"));
            p.AddRange(Child.ChildList(Enums.HealthState.Infectious, 4, "LocationProbabilities"));
            p.AddRange(Child.ChildList(Enums.HealthState.Susceptible, 1511, "LocationProbabilities"));
            p.AddRange(Elder.ElderList(Enums.HealthState.Infectious, 4, "LocationProbabilities"));
            p.AddRange(Elder.ElderList(Enums.HealthState.Susceptible, 5441, "LocationProbabilities"));
            p.AddRange(Youngster.YoungsterList(Enums.HealthState.Infectious, 4, "LocationProbabilities"));
            p.AddRange(Youngster.YoungsterList(Enums.HealthState.Susceptible, 3930, "LocationProbabilities"));
            for (int i = 0; i < p.Count; i++)
            {
                int    homeNum = i % homeCount;
                Person a       = p[i];
                homes[homeNum].agentData.Add(new AddAgentMessage(MessageTransportSystem.Instance.Id, a.GetType().Name, a.GetId(), a.GetHealthState(), 1));
                this.agentLocations[a.GetId()] = Containers.Instance[homes[homeNum].containerId];
            }
            messagesToSend.AddRange(homes);

            this.totalAgents = p.Count;

            // Messages for hospital containers creation
            List <AddContainerMessage> hospitals = new List <AddContainerMessage>();

            for (int i = 0; i < hospitalCount; i++)
            {
                hospitals.Add(new AddContainerMessage(MessageTransportSystem.Instance.Id, Enums.ContainerType.Hospital, currentId, 237, 19));
                Containers.Instance.Add(currentId, new Hospital(currentId, 237, 19));
                currentId++;
            }
            messagesToSend.AddRange(hospitals);

            // Messages for mall containers creation
            List <AddContainerMessage> malls = new List <AddContainerMessage>();

            for (int i = 0; i < mallCount; i++)
            {
                malls.Add(new AddContainerMessage(MessageTransportSystem.Instance.Id, Enums.ContainerType.Mall, currentId, 578, 90));
                Containers.Instance.Add(currentId, new Mall(currentId, 578, 90));
                currentId++;
            }
            messagesToSend.AddRange(malls);

            // Messages for office containers creation
            List <AddContainerMessage> offices = new List <AddContainerMessage>();

            for (int i = 0; i < officeCount; i++)
            {
                offices.Add(new AddContainerMessage(MessageTransportSystem.Instance.Id, Enums.ContainerType.Office, currentId, 236, 20));
                Containers.Instance.Add(currentId, new Office(currentId, 236, 20));
                currentId++;
            }
            messagesToSend.AddRange(offices);

            // Messages for univercity containers creation
            List <AddContainerMessage> univercities = new List <AddContainerMessage>();

            for (int i = 0; i < univercityCount; i++)
            {
                univercities.Add(new AddContainerMessage(MessageTransportSystem.Instance.Id, Enums.ContainerType.University, currentId, 300, 25));
                Containers.Instance.Add(currentId, new University(currentId, 300, 25));
                currentId++;
            }
            messagesToSend.AddRange(univercities);

            // Messages for school containers creation
            List <AddContainerMessage> schools = new List <AddContainerMessage>();

            for (int i = 0; i < schoolCount; i++)
            {
                schools.Add(new AddContainerMessage(MessageTransportSystem.Instance.Id, Enums.ContainerType.School, currentId, 237, 19));
                Containers.Instance.Add(currentId, new School(currentId, 237, 19));
                currentId++;
            }
            messagesToSend.AddRange(schools);

            // Messages for nursery containers creation
            List <AddContainerMessage> nurseries = new List <AddContainerMessage>();

            for (int i = 0; i < nurseryCount; i++)
            {
                nurseries.Add(new AddContainerMessage(MessageTransportSystem.Instance.Id, Enums.ContainerType.Nursery, currentId, 60, 23));
                Containers.Instance.Add(currentId, new Nursery(currentId, 60, 23));
                currentId++;
            }
            messagesToSend.AddRange(nurseries);

            // Now sending all messages equally spread to all CS workers and saving what container on what worker
            this.containers2workers.Clear();
            Dictionary <Message, Guid> res = MessageTransportSystem.Instance.SendSpread(messagesToSend);

            foreach (var r in res)
            {
                AddContainerMessage message = (AddContainerMessage)r.Key;
                Guid workerId = r.Value;
                this.containers2workers[message.containerId] = workerId;
            }
        }
示例#3
0
        private void onAddAgentMessage(Message message, ContainersCore container = null)
        {
            AddAgentMessage aaMessage = (AddAgentMessage)message;
            List <IAgent>   ags       = new List <IAgent>();

            GlobalAgentDescriptorTable.GetNewId = aaMessage.agentId;
            switch (aaMessage.agentType)
            {
            case "Adolescent":
                ags.AddRange(Adolescent.AdolescentList(aaMessage.state, aaMessage.count, "LocationProbabilities"));
                break;

            case "Adult":
                ags.AddRange(Adult.AdultList(aaMessage.state, aaMessage.count, "LocationProbabilities"));
                break;

            case "Child":
                ags.AddRange(Child.ChildList(aaMessage.state, aaMessage.count, "LocationProbabilities"));
                break;

            case "Elder":
                ags.AddRange(Elder.ElderList(aaMessage.state, aaMessage.count, "LocationProbabilities"));
                break;

            case "Youngster":
                ags.AddRange(Youngster.YoungsterList(aaMessage.state, aaMessage.count, "LocationProbabilities"));
                break;
            }
            foreach (IAgent a in ags)
            {
                if (container == null)
                {
                    int containerId = aaMessage.containerId;
                    if (containerId > 0)
                    {
                        if (Containers.Instance.ContainsKey(containerId))
                        {
                            var foundContainer = Containers.Instance[containerId];

                            AbstractPerson ap = (AbstractPerson)a;
                            ap.currentContainerId   = containerId;
                            ap.currentContainerType = foundContainer.ContainerType;
                        }
                        else
                        {
                            Trace.TraceWarning("Agent was added to moved to another node container. Moving him again");
                            CoreAMS.MessageTransportSystem.MessageTransfer.Instance.AddToGoto((AbstractPerson)a, Enums.ContainerType.Home);
                        }
                    }
                }
                else
                {
                    AbstractPerson ap = (AbstractPerson)a;
                    ap.currentContainerId   = container.Id;
                    ap.currentContainerType = container.ContainerType;
                }
            }
            GlobalAgentDescriptorTable.AddAgents(ags);
            //foreach (var ag in ags) {
            //    Trace.TraceInformation("Added agent with id {0} (check: {1})", ag.GetId(), aaMessage.agentId);
            //}
        }