//private void infectOtherAgent(int sourceAgentId) //{ // if (this.agents.Count < 2) // { // Trace.TraceInformation("Warning: too litle agents"); // return; // } // // Random: // // int idx = random.Next(0, this.agents.Count - 1); // ContainersCore currentContainer = this.agentLocations[sourceAgentId]; // if (currentContainer == null) // { // Trace.TraceInformation("Warning: no current container for {0}", sourceAgentId); // return; // } // if (currentContainer is Home) // { // // Trace.TraceInformation("Current container for {0} is Home", sourceAgentId); // return; // } // if (currentContainer.AgentCount < 2) // { // Trace.TraceInformation("Warning: noone in container for {0}", sourceAgentId); // return; // } // int destAgentId = sourceAgentId; // while (destAgentId == sourceAgentId) // { // destAgentId = currentContainer.GetRandomAgent(); // } // Guid clientId = this.agents[destAgentId]; // var msg0 = new Message(MessageTransportSystem.Instance.Id, MessageType.Infect); // msg0.data = destAgentId.ToString(); // //Trace.TraceInformation("Infecting: {0} -> {1}", sourceAgentId, destAgentId); // MessageTransportSystem.Instance.SendMessage(msg0, clientId); //} private void gotoContainer(AddAgentMessage amsg, Enums.ContainerType containerType) { //if (agentId == 2) // Trace.TraceInformation("Go: {0} to {1} ; Time: {2}", agentId, containerId, GlobalTime.realTime); List <ContainersCore> containersWithType = Containers.Instance.Values.Where((c) => c.ContainerType == containerType).ToList(); if (containersWithType.Count == 0) { Trace.TraceWarning("Warning: Container with type {0} not found", containerType); return; } int idx = GlobalAgentDescriptorTable.random.Next(0, containersWithType.Count - 1); ContainersCore container = containersWithType[idx]; ContainersCore oldContainer = this.agentLocations[amsg.agentId]; amsg.containerId = container.Id; Guid workerId = this.containers2workers[container.Id]; // MessageTransportSystem.Instance.SendMessage(amsg, workerId); this.addAgentMessages[workerId].Add(amsg); agentLocations[amsg.agentId] = container; }
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); //} }