void Start() { PolyMapLoader loader = new PolyMapLoader("x", "y", "goalPos", "startPos", "button"); polyData = loader.polyData; graph = new VGraph(); walkableLines = new List <Line> (); CreateObstacles(); ConstructWalkableLines(); // CreateInterObstacleWalk (); // print ("Walkable lines: " + walkableLines.Count); // graph.PrintGraph (); kinematic_vel = 20f; path = pathFinder.AStarSearch(polyData.start, polyData.end, graph); // print ("path length: " + path.Count); // Choose model transform.position = polyData.start; //model = gameObject.AddComponent<KinematicPointModel> (); //model = gameObject.AddComponent<DynamicPointModel> (); model = gameObject.AddComponent <DifferentialDriveModel> (); model.SetPath(path); model.StartCoroutineMove(); }
// Use this for initialization void Start() { Application.runInBackground = true; map = new PolyMapLoader("polygMap1/x", "polygMap1/y", "polygMap1/goalPos", "polygMap1/startPos", "polygMap1/button"); polyData = map.polyData; graph = new VGraph(); walkableLines = new List <Line> (); //Create visibility graph CreateObstacles(); ConstructWalkableLines(); CreateInterObstacleWalk(); agents = new List <T5Agent>(); agentColors = new List <Color>(); agentColors.Add(Color.black); agentColors.Add(Color.blue); agentColors.Add(Color.yellow); agentColors.Add(Color.cyan); agentColors.Add(Color.green); paths = new List <Vector3> [map.polyData.start.Count]; agentAtWaypoint = new int[map.polyData.start.Count]; int agentCounter = 0; for (int i = 0; i < map.polyData.start.Count; i = i + 1) { Vector3 startNode = map.polyData.start[i]; Vector3 endNode = map.polyData.end[i]; T5Agent newAgent = new T5Agent("Agent " + agentCounter, startNode, endNode, agentCounter, true); newAgent.agent.gameObject.renderer.material.color = agentColors[i]; List <PolyNode> ppath = pathFinder.AStarSearch(startNode, endNode, graph); List <Vector3> temp = new List <Vector3> (); foreach (PolyNode p in ppath) { temp.Add(p.pos); } //temp.Add(endNode); paths[i] = temp; agentAtWaypoint[i] = 0; agents.Add(newAgent); agentCounter++; } Debug.Log("Agents size:" + agents.Count); StartCoroutine("Move"); }
public List <PolyNode> AStarSearch(Vector3 start, Vector3 end, VGraph graph) { if (start == end) { return(new List <PolyNode>()); } PolyNode targetNode = graph.graph [end]; PolyNode startNode = graph.graph [start]; PriorityQueue <PolyNode, float> frontier = new PriorityQueue <PolyNode, float> (); Dictionary <PolyNode, PolyNode> cameFrom = new Dictionary <PolyNode, PolyNode> (); Dictionary <PolyNode, float> costSoFar = new Dictionary <PolyNode, float> (); frontier.Enqueue(startNode, 0f); cameFrom [startNode] = null; costSoFar [startNode] = 0; PolyNode currentNode; while (frontier.Count() != 0) { currentNode = frontier.Dequeue(); if (currentNode == targetNode) { return(ConstructPath(startNode, targetNode, cameFrom)); } foreach (Vector3 nodePos in currentNode.neighbours) { float newCost = costSoFar[currentNode] + GetCost(currentNode, graph.graph[nodePos]); if (!costSoFar.ContainsKey(graph.graph[nodePos]) || newCost < costSoFar[graph.graph[nodePos]]) { costSoFar[graph.graph[nodePos]] = newCost; float priority = newCost + Heuristic(targetNode.pos, nodePos); frontier.Enqueue(graph.graph[nodePos], priority); cameFrom[graph.graph[nodePos]] = currentNode; } } } return(new List <PolyNode> ()); }
void Start() { map = new PolyMapLoaderT3("polygMap1/x", "polygMap1/y", "polygMap1/goalPos", "polygMap1/startPos", "polygMap1/button", "polygMap1/customerPos"); polyData = map.polyData; graph = new VGraph(); walkableLines = new List <Line> (); // START VRP R = 3; agents = new List <PolyAgent> (); for (int i = 0; i < polyData.start.Count; i++) { Vector3 start = polyData.start[i]; Vector3 end = polyData.end[i]; agents.Add(new PolyAgent("Agent " + i, start, end, R, "car")); agents [i].agent.renderer.material.color = Color.black; agents[i].model = gameObject.AddComponent <DynamicCarModel> (); //agents[i].model = gameObject.AddComponent<DynamicPointModel> (); } List <Vector3> customers = new List <Vector3> (); // for plotting foreach (Vector3 v in polyData.customers) { customers.Add(v); } vrp = new VRPPL(customers, agents.Count); // END VRP CreateObstacles(); ConstructWalkableLines(); CreateInterObstacleWalk(); // print ("Walkable lines: " + walkableLines.Count); // graph.PrintGraph (); stopwatch.Start(); ready = new List <PolyAgent> (); }
void Start() { map = new PolyMapLoaderT3("polygMap1/x", "polygMap1/y", "polygMap1/goalPos", "polygMap1/startPos", "polygMap1/button", "polygMap1/customerPos"); polyData = map.polyData; graph = new VGraph(); walkableLines = new List <Line> (); // START VRP R = 3; CreateObstacles(); ConstructWalkableLines(); CreateInterObstacleWalk(); agents = new List <T5PolyAgent> (); for (int i = 0; i < polyData.start.Count; i++) { Vector3 start = polyData.start[i]; Vector3 end = polyData.end[i]; agents.Add(new T5PolyAgent("Agent " + i, start, end, R, "car")); agents [i].agent.renderer.material.color = Color.black; agents[i].model = gameObject.AddComponent <T5DynCar> (); List <PolyNode> ppath = pathFinder.AStarSearch(start, end, graph); List <Vector3> path = new List <Vector3> (); foreach (PolyNode node in ppath) { path.Add(node.pos); } agents[i].model.SetPath(path, agents[i], new List <Line> ()); } foreach (T5PolyAgent agent in agents) { agent.model.SetAgents(ref agents); agent.model.StartCoroutineMove(); } stopwatch.Start(); ready = new List <T5PolyAgent> (); }