override internal void AgentHasArrived(AgentState agentState) { ConcurrentAgent a = Activator.CreateInstance(agentState.AgentType) as ConcurrentAgent; a.LoadState(agentState); a.Name = agentState.Name; Add(a); a.Start(); }
/// <summary> /// Adds an agent to the environment. Its name should be unique. /// </summary> /// <param name="agent">The concurrent agent that will be added</param> /// <param name="name">The name of the agent</param> public void Add(ConcurrentAgent agent, string name) { if (Agents.ContainsKey(name)) { throw new Exception("Trying to add an agent with an existing name: " + name + " (ConcurrentEnvironment.Add(agent, name))"); } agent.Name = name; agent.Environment = this; Agents[name] = agent; }
/// <summary> /// Stops the execution of the agent and removes it from the environment. Use the Remove method instead of Agent.Stop /// when the decision to stop an agent does not belong to the agent itself, but to some other agent or to an external factor. /// </summary> /// <param name="agent">The agent to be removed</param> public void Remove(ConcurrentAgent agent) { if (Agents.ContainsValue(agent)) { Agents.Remove(agent.Name); } else { throw new Exception("Agent " + agent.Name + " does not exist (ConcurrentEnvironment.Remove)"); } }
/// <summary> /// Adds an agent to the environment. The agent should already have a name and its name should be unique. /// </summary> /// <param name="agent">The concurrent agent that will be added</param> public void Add(ConcurrentAgent agent) { if (agent.Name == null || agent.Name == "") { throw new Exception("Trying to add an agent without a name (ConcurrentEnvironment.Add(agent))"); } if (Agents.ContainsKey(agent.Name)) { throw new Exception("Trying to add an agent with an existing name: " + agent.Name + " (ConcurrentEnvironment.Add(Agent))"); } agent.Environment = this; Agents[agent.Name] = agent; }