[6773] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6773] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[8053] | 22 | using HeuristicLab.Common;
|
---|
[6773] | 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Optimization;
|
---|
| 25 | using HeuristicLab.Parameters;
|
---|
[14927] | 26 | using HeuristicLab.Persistence;
|
---|
[6773] | 27 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
| 28 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
|
---|
| 31 | [Item("PotvinPDExchangeMoveMaker", "Peforms the exchange move on a given PDP encoding and updates the quality.")]
|
---|
[14927] | 32 | [StorableType("6d19e79b-5887-4fdc-a1a9-dc6c1402c25c")]
|
---|
[6773] | 33 | public class PotvinPDExchangeMoveMaker : PotvinMoveMaker, IPotvinPDExchangeMoveOperator, IMoveMaker {
|
---|
| 34 | public ILookupParameter<PotvinPDExchangeMove> PDExchangeMoveParameter {
|
---|
| 35 | get { return (ILookupParameter<PotvinPDExchangeMove>)Parameters["PotvinPDExchangeMove"]; }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public override ILookupParameter VRPMoveParameter {
|
---|
| 39 | get { return PDExchangeMoveParameter; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | [StorableConstructor]
|
---|
[15018] | 43 | protected PotvinPDExchangeMoveMaker(StorableConstructorFlag deserializing) : base(deserializing) { }
|
---|
[6773] | 44 |
|
---|
| 45 | public PotvinPDExchangeMoveMaker()
|
---|
| 46 | : base() {
|
---|
[8053] | 47 | Parameters.Add(new LookupParameter<PotvinPDExchangeMove>("PotvinPDExchangeMove", "The moves that should be made."));
|
---|
[6773] | 48 | }
|
---|
| 49 |
|
---|
| 50 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 51 | return new PotvinPDExchangeMoveMaker(this, cloner);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | protected PotvinPDExchangeMoveMaker(PotvinPDExchangeMoveMaker original, Cloner cloner)
|
---|
| 55 | : base(original, cloner) {
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | public static void Apply(PotvinEncoding solution, PotvinPDExchangeMove move, IVRPProblemInstance problemInstance) {
|
---|
| 59 | if (move.Tour >= solution.Tours.Count)
|
---|
| 60 | solution.Tours.Add(new Tour());
|
---|
| 61 | Tour tour = solution.Tours[move.Tour];
|
---|
| 62 |
|
---|
| 63 | Tour oldTour = solution.Tours.Find(t => t.Stops.Contains(move.City));
|
---|
| 64 | oldTour.Stops.Remove(move.City);
|
---|
| 65 |
|
---|
| 66 | if (problemInstance is IPickupAndDeliveryProblemInstance) {
|
---|
[6856] | 67 | IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance;
|
---|
[6773] | 68 |
|
---|
[6856] | 69 | int location = pdp.GetPickupDeliveryLocation(move.City);
|
---|
[6773] | 70 | Tour oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location));
|
---|
| 71 | oldTour2.Stops.Remove(location);
|
---|
| 72 |
|
---|
[6856] | 73 | location = pdp.GetPickupDeliveryLocation(move.Replaced);
|
---|
[6773] | 74 | oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location));
|
---|
| 75 |
|
---|
| 76 | oldTour2.Stops.Remove(location);
|
---|
| 77 | tour.Stops.Remove(move.Replaced);
|
---|
| 78 |
|
---|
[6960] | 79 | solution.InsertPair(tour, move.City, pdp.GetPickupDeliveryLocation(move.City), problemInstance);
|
---|
| 80 | solution.InsertPair(oldTour, move.Replaced, pdp.GetPickupDeliveryLocation(move.Replaced), problemInstance);
|
---|
[6773] | 81 | } else {
|
---|
| 82 | tour.Stops.Remove(move.Replaced);
|
---|
| 83 |
|
---|
| 84 | int place = solution.FindBestInsertionPlace(tour, move.City);
|
---|
| 85 | tour.Stops.Insert(place, move.City);
|
---|
| 86 |
|
---|
| 87 | place = solution.FindBestInsertionPlace(oldTour, move.Replaced);
|
---|
| 88 | oldTour.Stops.Insert(place, move.Replaced);
|
---|
| 89 | }
|
---|
[7080] | 90 |
|
---|
| 91 | solution.Repair();
|
---|
[6773] | 92 | }
|
---|
| 93 |
|
---|
| 94 | protected override void PerformMove() {
|
---|
| 95 | PotvinPDExchangeMove move = PDExchangeMoveParameter.ActualValue;
|
---|
| 96 |
|
---|
| 97 | PotvinEncoding newSolution = move.Individual.Clone() as PotvinEncoding;
|
---|
| 98 | Apply(newSolution, move, ProblemInstance);
|
---|
| 99 | VRPToursParameter.ActualValue = newSolution;
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | }
|
---|