Ejemplo n.º 1
0
        /// <summary>
        ///     Start Agent if start is set
        /// </summary>
        /// <param name="agentToStart"></param>
        public static void StartAgent(ReactiveAgent agentToStart)
        {
            if (agentToStart is null)
            {
                throw new ArgumentNullException(nameof(agentToStart));
            }

            agentToStart.Start();
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Stops the execution of the agent identified by name 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.
        ///     Don't call it directly, use WhitePages.RemoveAgent
        /// </summary>
        /// <param name="agent">The agent to be removed</param>
        public void RemoveAgent(ReactiveAgent agent)
        {
            if (agent == null)
            {
                throw new ArgumentNullException(nameof(agent));
            }

            //MetaNetwork.RemoveActor(agent.AgentId);
            Agents.Remove(agent.AgentId);
            StoppedAgents.Add(agent);
        }
Ejemplo n.º 3
0
        /// <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 AddAgent(ReactiveAgent agent)
        {
            if (agent == null || agent.IsNull)
            {
                throw new ArgumentNullException(nameof(agent));
            }

            if (Agents.Exists(agent.AgentId))
            {
                // todo => throw new ArgumentException("Trying to add an agent " + agent.AgentId.ClassId + " with an existing key: " + agent.AgentId);

                //todo should be done only in reference
                Agents.Remove(agent.AgentId);
            }

            Agents.Add(agent);
            //todo should be done only in reference
            if (!_agentsReference.Exists(x => x.AgentId.Equals(agent.AgentId)))
            {
                _agentsReference.Add(agent);
            }
        }