public double Cost() { return(Cycle().Aggregate( 0.0, (sum, stop) => sum + Stop.Distance(stop, stop.Next))); }
private static IEnumerable <Stop> NearestNeighbors(this IEnumerable <Stop> stops) { var stopsLeft = stops.ToList(); for (var stop = stopsLeft.First(); stop != null; stop = stopsLeft.MinBy(s => Stop.Distance(stop, s))) { stopsLeft.Remove(stop); yield return(stop); } }