public static double CalculateDistance(Peak peak1, Peak peak2) { //http://stackoverflow.com/questions/6366408/calculating-distance-between-two-latitude-and-longitude-geocoordinates return MetersToMiles(peak1.geoCoordinate.GetDistanceTo(peak2.geoCoordinate)); }
public List<Peak> GetPeaksWithinDistanceNotVisited(Peak p, Stack<Peak> visited, double distance) { int index = peaks.IndexOf(p); var lookups = distanceLookup[index]; var returnValues = new List<Peak>(); for (int i = 0; i < lookups.Count; i++) { if (lookups[i] < distance) { if (visited.Contains(peaks[i]) || peaks[i].Equals(p)) { continue; } else { returnValues.Add(peaks[i]); } } } return returnValues; }
private void DebugPrint(Peak p, List<Peak> listOfPeaks) { for (int count = 0; count < listOfPeaks.Count; count++) { if (count < listOfPeaks.Count - 1) { Debug.WriteLine(" {0}, distance {1} ", listOfPeaks.ToArray()[count].name, CalculateDistance(listOfPeaks.ToArray()[count], p)); } else { Debug.WriteLine(" " + listOfPeaks.ToArray()[count].name); } } }
public void FindRoutesForPeak(Peak p, double distance, Stack<Peak> visited, List<List<Peak>> solutions) { if (progressCounter++ % 1000000 == 0) { Console.Write("."); } visited.Push(p); var nextPeaks = GetPeaksWithinDistanceNotVisited(p, visited, distance); if (nextPeaks.Count == 0) { //add to solutions if (solutions.Count > 0) { if (solutions[0].Count <= visited.Count) { //always keep longest solutions in front solutions.Insert(0, visited.ToList()); } } else { solutions.Add(visited.ToList()); } visited.Pop(); return; } foreach (Peak next in nextPeaks) { FindRoutesForPeak(next, distance - CalculateDistance(p, next), visited, solutions); } visited.Pop(); nextPeaks = null; return; }