Fixed a critical error in distance function.
Fixed a critical error in distance function.
Fixed another bug in traveling salesman problem solver implementation.
diff --git a/PokemonGo/RocketAPI/ICoordinate.cs b/PokemonGo/RocketAPI/ICoordinate.cs
index 7acfc1c..14c6ae6 100644
--- a/PokemonGo/RocketAPI/ICoordinate.cs
+++ b/PokemonGo/RocketAPI/ICoordinate.cs
@@ -22,7 +22,7 @@ namespace PokemonGo.RocketAPI
double R = 6371;
Func<double, double> toRad = x => x * (Math.PI / 180);
double dLat = toRad(c2.Latitude - c1.Latitude);
- double dLong = toRad(c2.Latitude - c2.Longitude);
+ double dLong = toRad(c2.Longitude - c2.Longitude);
double lat1 = toRad(c1.Latitude);
double lat2 = toRad(c2.Latitude);
double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
diff --git a/PokemonGo/RocketAPI/Window/TSP.cs b/PokemonGo/RocketAPI/Window/TSP.cs
index 90482c6..b47c966 100644
--- a/PokemonGo/RocketAPI/Window/TSP.cs
+++ b/PokemonGo/RocketAPI/Window/TSP.cs
@@ -13,6 +13,9 @@ namespace PokemonGo.RocketAPI.Window
public static IEnumerable<T> getMinimumTour(IEnumerable<T> nodes, Func<T,T,double> distance)
{
TSP<T>.distance = distance;
+ if (nodes.Count() < 2)
+ return nodes;
+
//create an initial tour out of nearest neighbors
var stops = nodes
.Select(i => new Stop(i))
You may download the files in Public Git.