예제 #1
0
        /// <summary>
        /// Sends a cell to the tissue with the specified address.
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="toAddress"></param>
        protected void SendCell(Cell cell, Address toAddress)
        {
            if (Agents.Contains(cell))
            {
                RemoveCell(cell);
            }

            // TODO: the send delay is dummy
            Mediator.Send(AddCell, toAddress, 0.01, cell);
            Log(cell.Type + " was sent to tissue " + toAddress, LogLevel.Minor);
        }
예제 #2
0
 /// <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(TurnBasedAgent agent)
 {
     if (Agents.Contains(agent))
     {
         Agents.Remove(agent);
         AgentsDict.Remove(agent.Name);
     }
     else
     {
         throw new Exception("Agent " + agent.Name + " does not exist (TurnBasedAgent.Remove)");
     }
 }
예제 #3
0
        private void RunTurn(int turn)
        {
            int[] agentOrder = null;
            if (_randomOrder)
            {
                agentOrder = RandomPermutation(this.NoAgents);
            }
            else
            {
                agentOrder = SortedPermutation(this.NoAgents);
            }

            // address situations when the agent list changes during the turn

            TurnBasedAgent[] agentsCopy = new TurnBasedAgent[this.NoAgents];
            Agents.CopyTo(agentsCopy);

            for (int i = 0; i < agentsCopy.Length; i++)
            {
                int aoi = agentOrder[i];
                if (agentsCopy[aoi] != null && Agents.Contains(agentsCopy[aoi])) // agent not stopped
                {
                    if (agentsCopy[aoi].MustRunSetup)                            // first turn runs Setup
                    {
                        agentsCopy[aoi].Setup();
                        agentsCopy[aoi].MustRunSetup = false;
                    }
                    else
                    {
                        agentsCopy[aoi].InternalAct();
                    }
                }
            }

            Thread.Sleep(_delayAfterTurn);

            TurnFinished(turn);
        }
예제 #4
0
        internal IEnumerable <ValidationResult> Validate()
        {
            var agentValidationResults = new List <ValidationResult>(6);

            if (Agents?.Any() == true)
            {
                if (Agents.Contains(AgentType.BankPayingAgent) ||
                    Agents.Contains(AgentType.BankPayingSubagent) ||
                    Agents.Contains(AgentType.PayingAgent) ||
                    Agents.Contains(AgentType.PayingSubagent))
                {
                    if (PayingAgent == null)
                    {
                        agentValidationResults.Add(new ValidationResult(string.Format(
                                                                            ErrorStrings.ResourceManager.GetString("RequiredError"),
                                                                            this.GetType().GetProperty(nameof(PayingAgent)).GetDisplayName())));
                    }
                }
                else
                {
                    if (PayingAgent != null)
                    {
                        agentValidationResults.Add(new ValidationResult(string.Format(
                                                                            ErrorStrings.ResourceManager.GetString("MustBeNullError"),
                                                                            this.GetType().GetProperty(nameof(PayingAgent)).GetDisplayName())));
                    }
                }

                if (Agents.Contains(AgentType.BankPayingAgent) ||
                    Agents.Contains(AgentType.BankPayingSubagent))
                {
                    if (MoneyTransferOperator == null)
                    {
                        agentValidationResults.Add(new ValidationResult(string.Format(
                                                                            ErrorStrings.ResourceManager.GetString("RequiredError"),
                                                                            this.GetType().GetProperty(nameof(MoneyTransferOperator)).GetDisplayName())));
                    }
                }
                else
                {
                    if (MoneyTransferOperator != null)
                    {
                        agentValidationResults.Add(new ValidationResult(string.Format(
                                                                            ErrorStrings.ResourceManager.GetString("MustBeNullError"),
                                                                            this.GetType().GetProperty(nameof(MoneyTransferOperator)).GetDisplayName())));
                    }
                }

                if (Agents.Contains(AgentType.PayingAgent) ||
                    Agents.Contains(AgentType.PayingSubagent))
                {
                    if (ReceivePaymentsOperator == null)
                    {
                        agentValidationResults.Add(new ValidationResult(string.Format(
                                                                            ErrorStrings.ResourceManager.GetString("RequiredError"),
                                                                            this.GetType().GetProperty(nameof(ReceivePaymentsOperator)).GetDisplayName())));
                    }
                }
                else
                {
                    if (ReceivePaymentsOperator != null)
                    {
                        agentValidationResults.Add(new ValidationResult(string.Format(
                                                                            ErrorStrings.ResourceManager.GetString("MustBeNullError"),
                                                                            this.GetType().GetProperty(nameof(ReceivePaymentsOperator)).GetDisplayName())));
                    }
                }
            }

            return(agentValidationResults);
        }