Exemplo n.º 1
0
        public bool Iterate()
        {
            if (shuffleRequested)
            {
                DoShuffle();
            }

            for (int i = 0; i < AgentsToCreate; i++)
            {
                if (ModelConfiguration.AgentDestructionModel.CreateNew)
                {
                    CreateAgent();
                }
            }

            Iteration++;
            Stopwatch.Start();
            Goals.OnIterationStarted(Agents);
            Plugin.OnIterationStarted(Agents);
            Space.Interact(Agents);
            Plugin.OnInteractionCompleted(Agents);
            Goals.OnInteractionCompleted(Agents);
            AgentsToCreate = Agents.Count(agent => agent.Interaction.ActionResult == InteractionResult.Collision);

            if (ModelConfiguration.AgentDestructionModel.RemoveDestoryed)
            {
                Agents.Where(agent => agent.Fitness.IsDestroyed).ForEach(agent => AgentRemoved?.Invoke(agent));
                Agents.RemoveAll(agent => agent.Fitness.IsDestroyed);
            }

            Plugin.OnIterationCompleted(Agents);
            Stopwatch.Stop();
            ConsumedTime.Add(Stopwatch.Elapsed.TotalSeconds);
            return(Iteration < ModelConfiguration.IterationLimit);
        }
Exemplo n.º 2
0
        public void RemoveAgent(Agent agent)
        {
            if (agent == null)
            {
                return;
            }

            if (_allAgents.ContainsKey(agent.Name))
            {
                if (_allAgents.TryRemove(agent.Name, out var agentModel))
                {
                    AgentRemoved.Invoke(this, new RemovedAgentEventArgs(agentModel));
                }
            }
        }