Exemple #1
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);
        }
Exemple #2
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);
        }