Exemplo n.º 1
0
        private void onAddContainerMessage(Message message)
        {
            AddContainerMessage acm = (AddContainerMessage)message;

            Trace.TraceInformation("Added containter. Type: {0}; Id: {1}.", acm.containerType, acm.containerId);

            ContainersCore container = null;
            switch(acm.containerType)
            {
                case Enums.ContainerType.Home:
                    container = new Home(acm.containerId, acm.area, acm.dencity);
                    break;
                case Enums.ContainerType.Hospital:
                    container = new Hospital(acm.containerId, acm.area, acm.dencity);
                    break;
                case Enums.ContainerType.Mall:
                    container = new Mall(acm.containerId, acm.area, acm.dencity);
                    break;
                case Enums.ContainerType.Nursery:
                    container = new Nursery(acm.containerId, acm.area, acm.dencity);
                    break;
                case Enums.ContainerType.Office:
                    container = new Office(acm.containerId, acm.area, acm.dencity);
                    break;
                case Enums.ContainerType.School:
                    container = new School(acm.containerId, acm.area, acm.dencity);
                    break;
                case Enums.ContainerType.University:
                    container = new University(acm.containerId, acm.area, acm.dencity);
                    break;
            }

            if (container != null)
            {
                if (!Containers.Instance.ContainsKey(container.Id))
                {
                    Containers.Instance.Add(container.Id, container);
                }

                foreach (AddAgentMessage aam in acm.agentData)
                {
                    this.onAddAgentMessage(aam, container);
                }
            }
        }
Exemplo n.º 2
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);
            //}
        }
Exemplo n.º 3
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));
 }
Exemplo n.º 4
0
        private void onStartMessage(Message message)
        {
            ThreadPool.QueueUserWorkItem((obj) =>
            {
                StartMessage smessage = (StartMessage)message;
                AgentManagementSystem.finishFlag = false;
                Trace.TraceInformation("Started. System Info: Agents: {0}; Containers: {1}; Workers: {2}", smessage.totalAgents, smessage.totalContainers, smessage.totalWorkers);
                AgentManagementSystem.totalAgents = smessage.totalAgents;
                AgentManagementSystem.totalContainers = smessage.totalContainers;
                AgentManagementSystem.totalWorkers = smessage.totalWorkers;
                AgentManagementSystem.RunAgents();
                if (!AgentManagementSystem.finishFlag) // Process was stopped manually. No need for result sending
                {                    
                    Trace.TraceInformation("Results:\nSusceptible: {0}\nRecovered: {3}\nInfectious: {5}\nFuneral: {1}\nDead: {2}\nTime: {4}", AgentManagementSystem.susceptibleAgentsCount, AgentManagementSystem.funeralAgentsCount,
                            AgentManagementSystem.deadAgentsCount, AgentManagementSystem.recoveredAgentsCount, GlobalTime.Time, AgentManagementSystem.infectiousAgentsCount);

                    ResultsMessage msg = new ResultsMessage(
                        MessageTransportSystem.Instance.Id,
                        AgentManagementSystem.susceptibleAgentsCount,
                        AgentManagementSystem.recoveredAgentsCount,
                        AgentManagementSystem.infectiousAgentsCount,
                        AgentManagementSystem.funeralAgentsCount,
                        AgentManagementSystem.deadAgentsCount,
                        AgentManagementSystem.exposedAgentsCount,
                        GlobalTime.Time
                    );
                    MessageTransportSystem.Instance.SendMessage(msg);
                }
                else
                {
                    Trace.TraceInformation("Process was stopped manually. No need for result sending");
                }

                AgentManagementSystem.finishFlag = false;
                isFinished = true;
            });
        }
Exemplo n.º 5
0
 private void onClearMessage(Message message)
 {
     AgentManagementSystem.finishFlag = true;
     AgentManagementSystem.NextTimeEvent.Set();
     GlobalAgentDescriptorTable.DeleteAllAgents();
     GlobalTime.Time = 0; ;
 }
Exemplo n.º 6
0
        private void onTickMessage(Message message)
        {
            TickMessage tmessage = (TickMessage)message;

            foreach (AddAgentMessage aam in tmessage.agents)
            {
                this.onAddAgentMessage(aam);
            }

            AgentManagementSystem.NextTimeEvent.Set();
        }
Exemplo n.º 7
0
 private void onTickEndMessage(Message message)
 {
     if (isStarted)
         this.waiters[message.senderId].Set();
 }
Exemplo n.º 8
0
 private void onRegistrationMessage(Message message)
 {
     this.workers.Add(message.senderId);
     this.waiters.Add(message.senderId, new AutoResetEvent(false));
     this.results.Add(message.senderId, null);
     this.intermediateResults.Add(message.senderId, null);
     this.addAgentMessages.Add(message.senderId, new List<AddAgentMessage>());
     this.agentCounters.Add(message.senderId, 0);
 }
Exemplo n.º 9
0
        private void onResultsMessage(Message message)
        {
            if (isStarted)
            {
                this.results[message.senderId] = (message as ResultsMessage).result;
                if (this.results.Values.All((res) => res != null))
                {
                    this.isStarted = false;

                    this.calculateResult();

                    this.restart();
                }
            }
        }
Exemplo n.º 10
0
 private void onInfectMessage(Message message)
 {
     //if (isStarted)
     //    this.infectOtherAgent(Int32.Parse(message.data));
 }
Exemplo n.º 11
0
        private void onGotoMessage(Message message)
        {
            if (isStarted && this.workers.Contains(message.senderId))
            {
                GoToContainerMessage gtMessage = (GoToContainerMessage)message;

                //foreach (int agentId in gtMessage.infectionSourceAgentIds)
                //{
                //    this.infectOtherAgent(agentId);
                //}

                lock (this.addAgentMessages)
                {
                    for (int i = 0; i < gtMessage.agents.Length; i++)
                    {
                        this.gotoContainer(gtMessage.agents[i], gtMessage.containerTypes[i]);
                    }
                }

                if (gtMessage.containerToMove != null)
                {
                    moveContainer(gtMessage.containerToMove);
                }

                this.agentCounters[message.senderId] = gtMessage.agentCount;

                if (gtMessage.currentResult != null) {
                    lock (this.intermediateResults)
                    {
                        this.intermediateResults[message.senderId] = gtMessage.currentResult;
                    }
                }

                this.waiters[message.senderId].Set();
            }
        }
Exemplo n.º 12
0
 public void SendMessage(Message message, Guid clientId)
 {
     throw new NotImplementedException("MessageTransportSystem.SendMessage is not implemented");
 }
Exemplo n.º 13
0
 public void SendMessage(Message message)
 {
     var msg = new BrokeredMessage(message);
     msg.ContentType = message.GetType().Name;
     msg.Properties["receiverId"] = new Guid(GLOBAL_DESCRIPTOR_QUEUE_NAME).ToString();
     this.globalDescriptorClient.Send(msg);
 }
Exemplo n.º 14
0
 public void SendMessage(Message message, Guid workerId)
 {
     var msg = new BrokeredMessage(message);
         msg.ContentType = message.GetType().Name;
         msg.Properties["receiverId"] = workerId.ToString();
         this.sendClient.Send(msg);
 }
Exemplo n.º 15
0
 public void SendEveryone(Message message)
 {
     foreach (Guid c in this.workers)
     {
         var msg = new BrokeredMessage(message);
         msg.ContentType = message.GetType().Name;
         msg.Properties["receiverId"] = c.ToString();
         sendClient.Send(msg);
     }
 }