Esempio n. 1
0
        /// <summary>
        /// Switches the arrival offset.
        /// </summary>
        public static int SwitchArrivalOffset(int directedId)
        {
            int turn;
            var id = DirectedHelper.ExtractId(directedId, out turn);
            int arrivalOffset, oldDepartureOffset;

            DirectedHelper.ExtractOffset(turn, out arrivalOffset, out oldDepartureOffset);
            return(DirectedHelper.BuildDirectedId(id, DirectedHelper.BuildTurn(1 - arrivalOffset, oldDepartureOffset)));
        }
Esempio n. 2
0
        /// <summary>
        /// Shifts the directed customer aft er the given directed before with the best possible turns.
        /// </summary>
        public static float ShiftAfterBestTurns(this Tour tour, float[][] weights, float[] penalties, int directedCustomer, int directedBefore)
        {
            var customer      = DirectedHelper.ExtractId(directedCustomer);
            var directedAfter = tour.GetNeigbour(directedCustomer);

            if (directedAfter == Constants.NOT_SET)
            { // TODO: figure out if this happens and if so how to calculate turns.
                return(0);
            }

            // insert directed customer.
            tour.ShiftAfter(directedCustomer, directedBefore);

            // calculate best shift-after.
            int departureOffset1, arrivalOffset3, turn2;
            var cost = CheapestInsertion.CheapestInsertionDirectedHelper.CalculateCheapestInsert(weights, penalties, directedBefore, customer, directedAfter,
                                                                                                 !tour.IsFirst(directedBefore), !tour.IsLast(directedAfter), out departureOffset1, out arrivalOffset3, out turn2);
            var newDirectedBefore   = DirectedHelper.UpdateDepartureOffset(directedBefore, departureOffset1);
            var newDirectedAfter    = DirectedHelper.UpdateArrivalOffset(directedAfter, arrivalOffset3);
            var newDirectedCustomer = DirectedHelper.BuildDirectedId(customer, turn2);

            if (directedBefore != newDirectedBefore)
            {
                tour.Replace(directedBefore, newDirectedBefore);
            }
            if (directedCustomer != newDirectedCustomer)
            {
                tour.Replace(directedCustomer, newDirectedCustomer);
            }
            if (directedAfter != newDirectedAfter)
            {
                tour.Replace(directedAfter, newDirectedAfter);
            }

            return(cost);
        }