示例#1
0
        private void onInfectMessage(Message message)
        {
            int agentId = Int32.Parse(message.data);
            var agent   = GlobalAgentDescriptorTable.GetAgentById(agentId);

            agent.EventMessage(new CoreAMS.MessageTransportSystem.AgentMessage(Enums.MessageType.Infected.ToString(), -1, -1));
        }
示例#2
0
 private void onClearMessage(Message message)
 {
     AgentManagementSystem.finishFlag = true;
     AgentManagementSystem.NextTimeEvent.Set();
     GlobalAgentDescriptorTable.DeleteAllAgents();
     GlobalTime.Time = 0;;
 }
示例#3
0
        public void MoveContainer(ContainersCore container)
        {
            Trace.TraceInformation("Going to move container {0} ({1})", container.Id, container.ContainerType);

            var agents = GlobalAgentDescriptorTable.PersonsInContainer(container.Id);

            Trace.TraceInformation("Going to move container agents: {0}", String.Join(", ", agents.Select(a => a.GetId())));

            AddContainerMessage msg = new AddContainerMessage(
                this.transportSystem.Id,
                container.ContainerType,
                container.Id,
                container.Area,
                container.Dencity
                );

            msg.agentData.AddRange(agents.Select(a => new AddAgentMessage(
                                                     this.transportSystem.Id,
                                                     a.GetType().Name,
                                                     a.GetId(),
                                                     a.GetHealthState(),
                                                     1
                                                     )));

            this.moveContainerMessage = msg;
        }
示例#4
0
文件: Person.cs 项目: kutemba0580/MAS
 // Отправка сообщения другому агенту
 public override void SendMessage()
 {
     // выбираем случайного агента и отправляем ему сообщение, что он инфицирован
     if (GlobalAgentDescriptorTable.random.NextDouble() <= INFECTION_PROBABILITY)
     {
         // MessageTransfer.Instance.AddInfect(new AgentMessage(Enums.HealthState.Infectious.ToString(), -1, Id));
         AbstractPerson personToInfect = GlobalAgentDescriptorTable.SameLocationPerson(this.Id);
         if (personToInfect != null)
         {
             personToInfect.EventMessage(new AgentMessage(Enums.MessageType.Infected.ToString(), personToInfect.GetId(), this.Id));
         }
     }
 }
示例#5
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); // добавляем созданные агенты в класс, в котором хранятся все агенты
        }
示例#6
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);
            //}
        }
示例#7
0
        public void SendGoto()
        {
            lock (gotoAgents)
            {
                if (gotoAgents.Count != gotoContainers.Count)
                {
                    Trace.TraceWarning("!!! Agent and container count doesn't match");
                }
                //return;

                //if (gotoAgents.Count == 0)
                //    return;

                List <AddAgentMessage> ams = new List <AddAgentMessage>();
                foreach (AbstractPerson a in this.gotoAgents)
                {
                    ams.Add(new AddAgentMessage(
                                this.transportSystem.Id,
                                a.GetType().Name,
                                a.GetId(),
                                a.GetHealthState(),
                                1
                                ));
                }

                GoToContainerMessage msg = new GoToContainerMessage(
                    this.transportSystem.Id,
                    ams.ToArray(),
                    this.gotoContainers.ToArray(),
                    this.infectedAgents.ToArray(),
                    GlobalAgentDescriptorTable.Count
                    );

                if (this.moveContainerMessage != null)
                {
                    msg.containerToMove = this.moveContainerMessage;
                }

                msg.currentResult = this.intermediateResult;

                this.transportSystem.SendMessage(msg);
                foreach (AbstractPerson a in this.gotoAgents)
                {
                    GlobalAgentDescriptorTable.DeleteOneAgent(a);
                }

                if (this.moveContainerMessage != null)
                {
                    foreach (var am in this.moveContainerMessage.agentData)
                    {
                        IAgent a = GlobalAgentDescriptorTable.GetAgentById(am.agentId);
                        if (a != null)
                        {
                            GlobalAgentDescriptorTable.DeleteOneAgent(a);
                        }
                    }
                    Containers.Instance.Remove(this.moveContainerMessage.containerId);
                }

                gotoAgents.Clear();
                gotoContainers.Clear();
                infectedAgents.Clear();
                this.moveContainerMessage = null;
                this.intermediateResult   = null;
            }
        }