[6773] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 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 |
|
---|
| 22 | using HeuristicLab.Core;
|
---|
| 23 | using HeuristicLab.Data;
|
---|
| 24 | using HeuristicLab.Operators;
|
---|
| 25 | using HeuristicLab.Optimization;
|
---|
| 26 | using HeuristicLab.Parameters;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 | using HeuristicLab.Common;
|
---|
| 29 | using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
|
---|
| 30 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
| 31 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
|
---|
| 34 | [Item("PotvinPDExchangeMoveMaker", "Peforms the exchange move on a given PDP encoding and updates the quality.")]
|
---|
| 35 | [StorableClass]
|
---|
| 36 | public class PotvinPDExchangeMoveMaker : PotvinMoveMaker, IPotvinPDExchangeMoveOperator, IMoveMaker {
|
---|
| 37 | public ILookupParameter<PotvinPDExchangeMove> PDExchangeMoveParameter {
|
---|
| 38 | get { return (ILookupParameter<PotvinPDExchangeMove>)Parameters["PotvinPDExchangeMove"]; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public override ILookupParameter VRPMoveParameter {
|
---|
| 42 | get { return PDExchangeMoveParameter; }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | [StorableConstructor]
|
---|
| 46 | private PotvinPDExchangeMoveMaker(bool deserializing) : base(deserializing) { }
|
---|
| 47 |
|
---|
| 48 | public PotvinPDExchangeMoveMaker()
|
---|
| 49 | : base() {
|
---|
| 50 | Parameters.Add(new LookupParameter<PotvinPDExchangeMove>("PotvinPDExchangeMove", "The moves that should be made."));
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 54 | return new PotvinPDExchangeMoveMaker(this, cloner);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | protected PotvinPDExchangeMoveMaker(PotvinPDExchangeMoveMaker original, Cloner cloner)
|
---|
| 58 | : base(original, cloner) {
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public static void Apply(PotvinEncoding solution, PotvinPDExchangeMove move, IVRPProblemInstance problemInstance) {
|
---|
| 62 | if (move.Tour >= solution.Tours.Count)
|
---|
| 63 | solution.Tours.Add(new Tour());
|
---|
| 64 | Tour tour = solution.Tours[move.Tour];
|
---|
| 65 |
|
---|
| 66 | Tour oldTour = solution.Tours.Find(t => t.Stops.Contains(move.City));
|
---|
| 67 | oldTour.Stops.Remove(move.City);
|
---|
| 68 |
|
---|
| 69 | if (problemInstance is IPickupAndDeliveryProblemInstance) {
|
---|
[6856] | 70 | IPickupAndDeliveryProblemInstance pdp = problemInstance as IPickupAndDeliveryProblemInstance;
|
---|
[6773] | 71 |
|
---|
[6856] | 72 | int location = pdp.GetPickupDeliveryLocation(move.City);
|
---|
[6773] | 73 | Tour oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location));
|
---|
| 74 | oldTour2.Stops.Remove(location);
|
---|
| 75 |
|
---|
[6856] | 76 | location = pdp.GetPickupDeliveryLocation(move.Replaced);
|
---|
[6773] | 77 | oldTour2 = solution.Tours.Find(t => t.Stops.Contains(location));
|
---|
| 78 |
|
---|
| 79 | oldTour2.Stops.Remove(location);
|
---|
| 80 | tour.Stops.Remove(move.Replaced);
|
---|
| 81 |
|
---|
[6960] | 82 | solution.InsertPair(tour, move.City, pdp.GetPickupDeliveryLocation(move.City), problemInstance);
|
---|
| 83 | solution.InsertPair(oldTour, move.Replaced, pdp.GetPickupDeliveryLocation(move.Replaced), problemInstance);
|
---|
[6773] | 84 | } else {
|
---|
| 85 | tour.Stops.Remove(move.Replaced);
|
---|
| 86 |
|
---|
| 87 | int place = solution.FindBestInsertionPlace(tour, move.City);
|
---|
| 88 | tour.Stops.Insert(place, move.City);
|
---|
| 89 |
|
---|
| 90 | place = solution.FindBestInsertionPlace(oldTour, move.Replaced);
|
---|
| 91 | oldTour.Stops.Insert(place, move.Replaced);
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | protected override void PerformMove() {
|
---|
| 96 | PotvinPDExchangeMove move = PDExchangeMoveParameter.ActualValue;
|
---|
| 97 |
|
---|
| 98 | PotvinEncoding newSolution = move.Individual.Clone() as PotvinEncoding;
|
---|
| 99 | Apply(newSolution, move, ProblemInstance);
|
---|
[6857] | 100 | newSolution.Repair();
|
---|
[6773] | 101 | VRPToursParameter.ActualValue = newSolution;
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | }
|
---|