public void PostStep(Agent agent, Model model)
        {
            Agent.AgentID id = model.getSimulation().getViewableAgent();

            /* only update the selected agent or all agents if selected */

            Node currentNode = model.getMap().getNodeAtLocation(agent.getNode(Agent.NodeType.Current).getPosition());

            Color backColor = agent.getColor(Agent.ColorType.BackColor);
            Color foreColor = agent.getColor(Agent.ColorType.ForeColor);

            if (currentNode.isEqual(agent.getNode(Agent.NodeType.Finish)))
                currentNode.repaintNode(backColor, foreColor, "F");
            else
            {
                if (model.getSimulation().getVisualizations() == View.Visualizations.Enabled)
                    currentNode.repaintNode(backColor, foreColor, currentNode.Text);
                else
                    currentNode.repaintNode(backColor, foreColor, "");
            }

            if (agent.getNode(Agent.NodeType.Current).getParent() != null)
            {
                Node parentNode = model.getMap().getNodeAtLocation(agent.getNode(Agent.NodeType.Current).getParent().getPosition());

                if (model.getSimulation().getPersistenceEnabled() == View.PathPersistence.Disabled | !agent.isActive())
                {
                    if (model.isSpecialNode(parentNode))
                    {
                        Agent specialAgent = model.getSpecialNodeAgent(parentNode);
                        backColor = specialAgent.getColor(Agent.ColorType.BackColor);
                        foreColor = specialAgent.getColor(Agent.ColorType.ForeColor);
                        parentNode.repaintNode(backColor, foreColor, "");
                    }
                    else
                    {
                        if (agent.isActive())
                            if (parentNode.getFlag(Node.Flag.IsWalkable))
                                parentNode.repaintNode(Color.White, Color.White, "");
                            else
                                parentNode.repaintNode(Color.Gray, Color.Gray, "");
                        else
                        {
                            /* is node visible on active agent's map */
                            Agent viewAgent = model.getAgent(model.getSimulation().getViewableAgent());
                            bool isVisibleOnActiveAgentsMap = viewAgent.getMap().isNodeFlag(parentNode, Node.Flag.IsVisible);

                            if (isVisibleOnActiveAgentsMap)
                            {
                                /* is node special */
                                bool isSpecial = viewAgent.getMap().isNodeFlag(parentNode, Node.Flag.IsSpecial);
                                if (isSpecial)
                                {
                                    if (parentNode.isEqual(viewAgent.getNode(Agent.NodeType.Start)))
                                        parentNode.repaintNode(viewAgent.getColor(Agent.ColorType.BackColor), viewAgent.getColor(Agent.ColorType.ForeColor), "S");
                                    else
                                        parentNode.repaintNode(viewAgent.getColor(Agent.ColorType.BackColor), viewAgent.getColor(Agent.ColorType.ForeColor), "F");
                                }
                                else
                                {
                                    /* is node walkable on active agent's map */
                                    bool isWalkable = viewAgent.getMap().isNodeFlag(parentNode, Node.Flag.IsWalkable);
                                    if (isWalkable)
                                    {
                                        bool isPathNode = viewAgent.getMap().isNodeFlag(parentNode,Node.Flag.IsPath);
                                        if (isPathNode)
                                        {
                                            if (model.getSimulation().getPersistenceEnabled() == View.PathPersistence.Enabled)
                                            {
                                                /* non active agent's parent node is also the active agent's path node */
                                                Color b = viewAgent.getColor(Agent.ColorType.BackColor);
                                                Color f = viewAgent.getColor(Agent.ColorType.ForeColor);
                                                parentNode.repaintNode(b, f, "");
                                            }
                                            else
                                            {
                                                /* non active agent's walkable path node with persistence disabled */
                                                parentNode.repaintNode(Color.White, Color.White, "");
                                            }
                                        }
                                        else
                                        {
                                            /* non active agent's parent node is just a visible walkable node */
                                            parentNode.repaintNode(Color.White, Color.White, "");
                                        }
                                    }
                                    else
                                    {
                                        /* non active agent's parent node is just a visible non-walkable node */
                                        parentNode.repaintNode(Color.Gray, Color.Gray, "");
                                    }
                                }
                            }
                            else
                            {
                                /* node is not visible on active agent's map therefore we can just paint it black */
                                parentNode.repaintNode(Color.Black, Color.Black, "");
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        public bool UpdateAgentMap(Agent agent)
        {
            int nonWalkableNonVisibleCount = 0;
            List<Node> sharedMapFovNodes;

            /* get viewable shared map nodes based on the agent's current location */
            sharedMapFovNodes = map.getNodesWithinDistance(
                agent.getNode(Agent.NodeType.Current),
                simulation.getFieldOfViewMethod(),
                simulation.get(View.ViewNumericUpDown.FieldOfView));

            foreach (Node sharedMapNode in sharedMapFovNodes)
            {
                /* update the agent's map */
                bool isWalkable = sharedMapNode.getFlag(Node.Flag.IsWalkable);
                Node agentMapNode = agent.getMap().getNodeAtLocation(sharedMapNode.getPosition());
                agentMapNode.setFlag(Node.Flag.IsVisible, true);
                agentMapNode.setFlag(Node.Flag.IsWalkable, isWalkable);

                /* count the nodes that are not already visible and non walkable in order to reset the algorithm for the next step */
                if (!sharedMapNode.getFlag(Node.Flag.IsVisible) && !sharedMapNode.getFlag(Node.Flag.IsWalkable))
                    nonWalkableNonVisibleCount++;

                /* only paint the shared map if the agent is active */
                if (agent.isActive())
                {
                    bool isPathNode = map.isNodeFlag(sharedMapNode, Node.Flag.IsPath);
                    bool isSpecialNode = this.isSpecialNode(sharedMapNode);
                    bool isVisualizations = (simulation.getVisualizations() == View.Visualizations.Enabled) ? true : false;

                    /* dont repaint if its the start node, finish node, or a path node */
                    if (!isSpecialNode && !isPathNode)
                    {
                        if (isWalkable)
                        {
                            if (isVisualizations)
                                sharedMapNode.repaintNode(Color.White, Color.Black, sharedMapNode.Text);
                            else
                                sharedMapNode.repaintNode(Color.White, Color.White, "");
                        }
                        else
                            sharedMapNode.repaintNode(Color.Gray, Color.Gray, "");
                    }
                }
            }

            return (nonWalkableNonVisibleCount == 0) ? false : true;
        }
 protected bool visualizationPaintOK(Node node, Agent agent, Model model)
 {
     bool isActive = agent.isActive();
     View.Visualizations visualizations = model.getSimulation().getVisualizations();
     bool notSpecial = !model.isSpecialNode(node);
     bool notPath = !model.isPathNode(node);
     if (isActive && visualizations == View.Visualizations.Enabled && notSpecial && notPath)
         return true;
     else
         return false;
 }
Example #4
0
        public bool SetAgentTarget(Agent agent)
        {
            Agent agentInView = this.isAgentInView(agent);

            /* check if agent is in view */
            if (agentInView != null && (simulation.getAgentCooperation() == View.AgentCooperation.Enabled))
            {
                /* agent in view, check if meeting has already occurred */
                if (agent.meetingListCheck(agentInView.getId()))
                {
                    /* meeting has already occurred so set the target node to finish */
                    agent.setNode(Agent.NodeType.Target, agent.getNode(Agent.NodeType.Finish));
                }
                else
                {
                    /* agent in view, check if both agents occupy the same same node or adjacent node */
                    if (agentInView.getNode(Agent.NodeType.Current).isEqual(agent.getNode(Agent.NodeType.Current)) ||
                        agentInView.getNode(Agent.NodeType.Current).isAdjacent(agent.getNode(Agent.NodeType.Current), simulation.get(View.ViewNumericUpDown.MapSize)))
                    {
                        /* agent in view & agents are in sharing distance, therefore update the visible flags */
                        int sharedNodeCount = 0;

                        foreach (Node agentInViewMapNode in agentInView.getMap().getNodes())
                        {
                            /* get the agent map node */
                            Node agentMapNode = agent.getMap().getNodeAtLocation(agentInViewMapNode.getPosition());

                            /* skip nodes that are not visible */
                            if (!agentInViewMapNode.getFlag(Node.Flag.IsVisible))
                                continue;

                            /* skip nodes that are already visible in the agent's map */
                            if (agentMapNode.getFlag(Node.Flag.IsVisible))
                                continue;

                            /* don't share shared nodes (IsShared flag is cleared after both agents complete the sharing) */
                            if (agentInViewMapNode.getFlag(Node.Flag.IsShared))
                                continue;

                            /* set flags flags */
                            agentMapNode.setFlag(Node.Flag.IsVisible, true);
                            agentMapNode.setFlag(Node.Flag.IsWalkable, agentInViewMapNode.getFlag(Node.Flag.IsWalkable));
                            agentMapNode.setFlag(Node.Flag.IsShared, true);

                            /* increment the shared node counter */
                            sharedNodeCount++;

                            /* paint the shared map if the agent is active */
                            if (agent.isActive())
                            {
                                /* get the shared map node */
                                Node sharedMapNode = map.getNodeAtLocation(agentMapNode.getPosition());

                                bool isWalkable = agentMapNode.getFlag(Node.Flag.IsWalkable);
                                bool isPathNode = map.isNodeFlag(sharedMapNode, Node.Flag.IsPath);
                                bool isSpecialNode = this.isSpecialNode(sharedMapNode);
                                bool isVisualizations = (simulation.getVisualizations() == View.Visualizations.Enabled) ? true : false;

                                /* dont repaint if its the start node, finish node, or a path node */
                                if (!isSpecialNode && !isPathNode)
                                {
                                    if (isWalkable)
                                    {
                                        if (isVisualizations)
                                            sharedMapNode.repaintNode(Color.White, Color.Black, sharedMapNode.Text);
                                        else
                                            sharedMapNode.repaintNode(Color.White, Color.White, "");
                                    }
                                    else
                                        sharedMapNode.repaintNode(Color.Gray, Color.Gray, "");
                                }
                            }
                        }

                        agent.meetingListAdd(agentInView.getId());
                        agent.getCounters().incNodesShared(sharedNodeCount);

                        /* set the target node to the finish node */
                        agent.setNode(Agent.NodeType.Target, agent.getNode(Agent.NodeType.Finish));

                        /* indicate that an algorithm reset is required because the target node was changed */
                        return true;
                    }
                    else
                    {
                        /* agent in view but both agents are not occupying the same node yet */
                        /* set the agent target node to the agent in view's current node */

                        Node target = agent.getMap().getNodeAtLocation(agentInView.getNode(Agent.NodeType.Current).getPosition());
                        agent.setNode(Agent.NodeType.Target, target);

                        /* indicate that an algorithm reset is required because a new target node has been set */
                        return true;
                    }
                }
            }
            else
            {
                /* agent not in view so just keep going to the agents finish node */
                agent.setNode(Agent.NodeType.Target, agent.getNode(Agent.NodeType.Finish));
            }

            /* indicate that an algorithm reset is not required because the target node was not changed */
            return false;
        }