private void computeAstar(Vector3 goalPosition) { this.goalPosition = goalPosition; this.goalPosition.y = model.getVehicle().transform.position.y; // keep closeness-to-the-goal-control in 2D /* compute Astar */ pathFinder = new Astar(MyUtils.precisionAstar, MyUtils.droneRadius, false); if (pathFinder.setNewTargetPosition(goalPosition) == true) //set the target for A* algorithm { pathFinder.AstarBestPathFrom(model.getVehicle().transform.position); path = pathFinder.getSolution(); en = path.GetEnumerator(); en.MoveNext(); isPathInProgress = true; //path = Chromosome.allPairPathsMatrix[CHromo,]; } else { Debug.Log("Target position unreachable"); } if (path == null) { Debug.Log("Astar failed!"); } }
/* Computes all pairs distances between drones and customers in order * to be used later by the computing fitness function */ private static void computeAllPairDistancesAndPaths() { allPairDistancesMatrix = new float[Ngenes, Ngenes]; allPairPathsMatrix = new LinkedList <Vector3> [Ngenes, Ngenes]; Astar pathFinder = new Astar(0.1f, 0.5f); Vector3 pt1, pt2; for (int i = 0; i < Ngenes; i++) { allPairDistancesMatrix[i, i] = 0.0f; for (int z = i + 1; z < Ngenes; z++) { pt1 = positionAtIndex(i); pt2 = positionAtIndex(z); if (pathFinder.setNewTargetPosition(pt2) == true) { float solutionCost = 0; pathFinder.AstarBestPathFrom(pt1); LinkedList <Vector3> path = pathFinder.getSolution(); allPairDistancesMatrix[i, z] = pathFinder.getSolutionCost(); allPairDistancesMatrix[z, i] = pathFinder.getSolutionCost(); allPairPathsMatrix[i, z] = path; allPairPathsMatrix[z, i] = path; } } } /* String str = ""; * for (int i=0; i<Ngenes; i++) { * for (int z=0; z<Ngenes; z++) { * str+=allPairDistancesMatrix[i,z]+" "; * } * str+="\n"; * } * Debug.Log (str);*/ }