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