/** * <summary>Builds an agent k-D tree.</summary> */ internal void buildAgentTree(Simulator sim) { sim_ = sim; if (agents_ == null || agents_.Length != sim_.agents_.Count) { agents_ = new Agent[sim_.agents_.Count]; for (int i = 0; i < agents_.Length; ++i) { agents_[i] = sim_.agents_[i]; } agentTree_ = new AgentTreeNode[2 * agents_.Length]; for (int i = 0; i < agentTree_.Length; ++i) { agentTree_[i] = new AgentTreeNode(); } } if (agents_.Length != 0) { buildAgentTreeRecursive(0, agents_.Length, 0); } }
public void BuildAgentTree () { //Dummy to avoid compiler warnings obstacleRoot = new ObstacleTreeNode(); obstacleRoot.right = obstacleRoot; obstacleRoot.left = obstacleRoot; obstacleRoot = null; List<Agent> ag = simulator.GetAgents (); if (agents == null || agents.Count != ag.Count || rebuildAgents) { rebuildAgents = false; if (agents == null) agents = new List<Agent>(ag.Count); else agents.Clear (); agents.AddRange (simulator.GetAgents()); } if (agentTree.Length != agents.Count*2) { agentTree = new AgentTreeNode[agents.Count*2]; for (int i=0;i<agentTree.Length;i++) agentTree[i] = new AgentTreeNode(); } if (agents.Count != 0) { BuildAgentTreeRecursive (0,agents.Count, 0); } }
/** * <summary>Builds an agent k-D tree.</summary> */ internal void buildAgentTree() { if (agents_ == null || agents_.Length != Simulator.Instance.agents_.Count) { agents_ = new Agent[Simulator.Instance.agents_.Count]; var keys = Simulator.Instance.getAgentsKeysArray(); for (int i = 0; i < agents_.Length; ++i) { agents_[i] = Simulator.Instance.agents_[keys[i]]; } agentTree_ = new AgentTreeNode[2 * agents_.Length]; for (int i = 0; i < agentTree_.Length; ++i) { agentTree_[i] = new AgentTreeNode(); } } if (agents_.Length != 0) { buildAgentTreeRecursive(0, agents_.Length, 0); } }
/** * <summary>Builds an agent k-D tree.</summary> */ internal void buildAgentTree() { if (agents_ == null || dirty) // agents_.Length != simulator_.agents_.Count) { agents_ = new Agent[simulator_.agents_.Count]; for (int i = 0; i < agents_.Length; ++i) { agents_[i] = simulator_.agents_[i]; } agentTree_ = new AgentTreeNode[2 * agents_.Length]; for (int i = 0; i < agentTree_.Length; ++i) { agentTree_[i] = new AgentTreeNode(); } } dirty = false; if (agents_.Length != 0) { buildAgentTreeRecursive(0, agents_.Length, 0); } }
public void BuildAgentTree() { List <Agent> ag = simulator.GetAgents(); if (agents == null || agents.Count != ag.Count || rebuildAgents) { rebuildAgents = false; if (agents == null) { agents = new List <Agent>(ag.Count); } else { agents.Clear(); } agents.AddRange(simulator.GetAgents()); } if (agentTree.Length != agents.Count * 2) { agentTree = new AgentTreeNode[agents.Count * 2]; for (int i = 0; i < agentTree.Length; i++) { agentTree[i] = new AgentTreeNode(); } } if (agents.Count != 0) { BuildAgentTreeRecursive(0, agents.Count, 0); } }
/** * <summary>Builds an agent k-D tree.</summary> */ internal void buildAgentTree() { //if (agents_ == null || agents_.Length != Simulator.Instance.agents_.Count) { agents_ = new Agent[Simulator.Instance.agents_.Count]; uint j = 0; foreach (var agentsKey in Simulator.Instance.agents_.Keys) { agents_[j++] = Simulator.Instance.agents_[agentsKey]; } agentTree_ = new AgentTreeNode[2 * agents_.Length]; for (int i = 0; i < agentTree_.Length; ++i) { agentTree_[i] = new AgentTreeNode(); } } if (agents_.Length != 0) { buildAgentTreeRecursive(0, agents_.Length, 0); } }
private void resetAgentTree(int v) { agentTree_ = new AgentTreeNode[v]; for (int i = 0; i < v; i++) { agentTree_[i] = new AgentTreeNode(3); } }
//public AgentTreeNode[] AgentTree { get { return agentTree_} }; internal void getTree() { for (int i = 0; i < agentTree_.Length; i++) { AgentTreeNode item = (AgentTreeNode)agentTree_.GetValue(i); System.Console.Out.WriteLine(string.Format("{0};{1};{2};{3};{4};{5};{6};{7};", item.begin_, item.end_, item.left_, item.right_, item.maxX_, item.maxY_, item.minX_, item.minY_)); } }
public void BuildAgentTree () { List<Agent> ag = simulator.GetAgents (); if (agents == null || agents.Count != ag.Count || rebuildAgents) { rebuildAgents = false; if (agents == null) agents = new List<Agent>(ag.Count); else agents.Clear (); agents.AddRange (simulator.GetAgents()); } if (agentTree.Length != agents.Count*2) { agentTree = new AgentTreeNode[agents.Count*2]; for (int i=0;i<agentTree.Length;i++) agentTree[i] = new AgentTreeNode(); } if (agents.Count != 0) { BuildAgentTreeRecursive (0,agents.Count, 0); } }
internal void buildAgentTree() { if (agents_==null || agents_.Length != Simulator.Instance.agents_.Count) { agents_ = new Agent[Simulator.Instance.agents_.Count]; for (int i = 0; i < agents_.Length; ++i) { agents_[i] = Simulator.Instance.agents_[i]; } agentTree_ = new AgentTreeNode[2 * agents_.Length]; for (int i = 0; i < agentTree_.Length; ++i) { agentTree_[i] = new AgentTreeNode(); } } if (agents_.Length != 0) { buildAgentTreeRecursive(0, agents_.Length, 0); } }
public void BuildAgentTree() { //Dummy to avoid compiler warnings obstacleRoot = new ObstacleTreeNode(); obstacleRoot.right = obstacleRoot; obstacleRoot.left = obstacleRoot; obstacleRoot = null; List <Agent> ag = simulator.GetAgents(); if (agents == null || agents.Count != ag.Count || rebuildAgents) { rebuildAgents = false; if (agents == null) { agents = new List <Agent>(ag.Count); } else { agents.Clear(); } agents.AddRange(simulator.GetAgents()); } if (agentTree.Length != agents.Count * 2) { agentTree = new AgentTreeNode[agents.Count * 2]; for (int i = 0; i < agentTree.Length; i++) { agentTree[i] = new AgentTreeNode(); } } if (agents.Count != 0) { BuildAgentTreeRecursive(0, agents.Count, 0); } }
/** * <summary>Builds an agent k-D tree.</summary> */ internal void buildAgentTree(IList <Agent> Agents) { if (agents_ == null || agents_.Length != Agents.Count) { agents_ = new Agent[Agents.Count]; for (int i = 0; i < agents_.Length; ++i) { agents_[i] = Agents[i]; } agentTree_ = new AgentTreeNode[2 * agents_.Length]; for (int i = 0; i < agentTree_.Length; ++i) { agentTree_[i] = new AgentTreeNode(); } } if (agents_.Length != 0) { buildAgentTreeRecursive(0, agents_.Length, 0); } }
/** * <summary>Builds an agent k-D tree.</summary> */ internal void buildAgentTree() { if (agents == null || agents.Length != Simulator.Instance.agents.Count) { agents = new Agent[Simulator.Instance.agents.Count]; for (int i = 0; i < agents.Length; ++i) { agents[i] = Simulator.Instance.agents[i]; } agentTree = new AgentTreeNode[2 * agents.Length]; for (int i = 0; i < agentTree.Length; ++i) { agentTree[i] = new AgentTreeNode(); } } if (agents.Length != 0) { buildAgentTreeRecursive(0, agents.Length, 0); } }
/** * <summary>Builds an agent k-D tree.</summary> */ internal void BuildAgentTree() { if (_agents == null || _agents.Length != Simulator.Instance.Agents.Count) { _agents = new Agent[Simulator.Instance.Agents.Count]; for (int i = 0; i < _agents.Length; ++i) { _agents[i] = Simulator.Instance.Agents[i]; } _agentTree = new AgentTreeNode[2 * _agents.Length]; for (int i = 0; i < _agentTree.Length; ++i) { _agentTree[i] = new AgentTreeNode(); } } if (_agents.Length != 0) { BuildAgentTreeRecursive(0, _agents.Length, 0); } }
/** * <summary>Builds an agent k-D tree.</summary> */ internal void buildAgentTree() { if (agents_ == null || agents_.Length != simulator.agents_.Count) { agents_ = new Agent[simulator.agentList.Count]; agentTree_ = new AgentTreeNode[2 * agents_.Length]; for (int i = 0; i < agentTree_.Length; ++i) { agentTree_[i] = new AgentTreeNode(); } } if (agents_.Length != 0) { for (int i = 0; i < agents_.Length; i++) { agents_[i] = simulator.agentList[i]; } buildAgentTreeRecursive(0, agents_.Length, 0); } }
private void BuildAgentTreeRecursive(int start, int end, int node) { AgentTreeNode nd = agentTree[node]; nd.start = start; nd.end = end; nd.xmin = nd.xmax = agents[start].position.x; nd.ymin = nd.ymax = agents[start].position.z; for (int i = start + 1; i < end; i++) { nd.xmin = Math.Min(nd.xmin, agents[i].position.x); nd.xmax = Math.Max(nd.xmax, agents[i].position.x); nd.ymin = Math.Min(nd.ymin, agents[i].position.z); nd.ymax = Math.Max(nd.ymax, agents[i].position.z); } //Debug.DrawLine (new Vector3 (nd.xmin,0,nd.ymin),new Vector3 (nd.xmin,0,nd.ymax),Color.blue); //Debug.DrawLine (new Vector3 (nd.xmax,0,nd.ymin),new Vector3 (nd.xmax,0,nd.ymax),Color.blue); //Debug.DrawLine (new Vector3 (nd.xmin,0,nd.ymin),new Vector3 (nd.xmax,0,nd.ymin),Color.blue); //Debug.DrawLine (new Vector3 (nd.xmin,0,nd.ymax),new Vector3 (nd.xmax,0,nd.ymax),Color.blue); if (end - start > MAX_LEAF_SIZE) { /* This is no leaf node */ bool isVertical = (nd.xmax - nd.xmin > nd.ymax - nd.ymin); float splitValue = (isVertical ? 0.5f * (nd.xmax + nd.xmin) : 0.5f * (nd.ymax + nd.ymin)); #if ASTARDEBUG if (isVertical) { Debug.DrawLine(new Vector3(splitValue, 0, -2000), new Vector3(splitValue, 0, 2000), Color.green); } else { Debug.DrawLine(new Vector3(-2000, 0, splitValue), new Vector3(2000, 0, splitValue), Color.green); } #endif int left = start; int right = end; while (left < right) { while (left < right && (isVertical ? agents[left].position.x : agents[left].position.z) < splitValue) { left++; } while (right > left && (isVertical ? agents[right - 1].position.x : agents[right - 1].position.z) >= splitValue) { right--; } if (left < right) { Agent tmp = agents[left]; agents[left] = agents[right - 1]; agents[right - 1] = tmp; left++; right--; } } int leftSize = left - start; if (leftSize == 0) { leftSize++; left++; right++; } nd.left = node + 1; nd.right = node + 1 + (2 * leftSize - 1); agentTree[node] = nd; BuildAgentTreeRecursive(start, left, agentTree[node].left); BuildAgentTreeRecursive(left, end, agentTree[node].right); } else { agentTree[node] = nd; } }