Ejemplo n.º 1
0
 public double Cost()
 {
     return(Cycle().Aggregate(
                0.0,
                (sum, stop) =>
                sum + Stop.Distance(stop, stop.Next)));
 }
Ejemplo n.º 2
0
        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);
            }
        }