Beispiel #1
0
        /// <summary>
        /// Get the stop of Stop collection that is farthest from any Stop in TourStops
        /// </summary>
        /// <returns></returns>
        public Stop FindFarthestStop()
        {
            float currentMaxDistance = float.MinValue;
            Stop  farthestCandidate  = null;

            foreach (var pointInTour in TourStops)
            {
                foreach (var stop in Stops)
                {
                    //Exlude visited stops as candidates
                    if (TourStops.Any(ts => ts.Id == stop.Id))
                    {
                        continue;
                    }
                    var distance = DistanceMatrix[pointInTour.Id][stop.Id];
                    if (distance > currentMaxDistance)
                    {
                        currentMaxDistance = distance;
                        farthestCandidate  = stop;
                    }
                }
            }

            if (farthestCandidate == null)
            {
                throw new Exception("Cannot find farthest pair");
            }
            return(farthestCandidate);
        }
Beispiel #2
0
        public void AddTourStop(TourStop ts)
        {
            ts.Owner = this;

            TourStops.Add(ts);
            currentTourstopIndex = tourStops.Count - 1;
            TourDirty            = true;
        }
 public void InsertAfterTourStop(TourStop ts)
 {
     ts.Owner = this;
     if (currentTourstopIndex > -1 || currentTourstopIndex < TourStops.Count)
     {
         TourStops.Insert(currentTourstopIndex + 1, ts);
     }
     else
     {
         TourStops.Add(ts);
         currentTourstopIndex = tourStops.Count - 1;
     }
     TourDirty = true;
 }
Beispiel #4
0
        public Dictionary <Stop, float> GetTimeTable()
        {
            if (!TimeMatrixReady)
            {
                throw new Exception("DistanceMatrix needs to be calculated first");
            }
            var timeTable = new Dictionary <Stop, float>();

            for (int i = 0; i < TourStops.Count - 1; i++)
            {
                var stop       = TourStops.ElementAt(i + 1);
                var travelTime = TimeMatrix[i][i + 1];
                timeTable.Add(stop, travelTime);
            }
            return(timeTable);
        }
Beispiel #5
0
        /// <summary>
        /// Insert Stop at least expensive edge of TourStops
        /// </summary>
        /// <param name="stopToAdd"></param>
        public void InsertAtLeastExpensiveEdge(Stop stopToAdd)
        {
            float currentMinInsertionCost = float.MaxValue;
            int   insertionIndexCandidate = -1;

            //Iterate through every pair of the tour eg 0+1,1+2..
            for (int i = 0; i < TourStops.Count - 1; i++)
            {
                var leftCandidate  = TourStops.ElementAt(i);
                var rightCandidate = TourStops.ElementAt(i + 1);

                var insertionCost = MinFunction(leftCandidate.Id, stopToAdd.Id, rightCandidate.Id);
                if (insertionCost < currentMinInsertionCost)
                {
                    currentMinInsertionCost = insertionCost;
                    insertionIndexCandidate = i + 1;
                }
            }

            TourStops.Insert(insertionIndexCandidate, stopToAdd);
        }
        public static List <TourStop> GetTourStops(int count)
        {
            var result = TourStops.Take(count).ToList();

            return(result);
        }
        public static List <TourStop> GetAllTourStops()
        {
            var result = TourStops.ToList();

            return(result);
        }