[7689] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15584] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[7689] | 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 System.Collections.Generic;
|
---|
[7689] | 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
[8053] | 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Operators;
|
---|
| 27 | using HeuristicLab.Optimization;
|
---|
[7689] | 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
|
---|
[7865] | 33 | [Item("PotvinTwoOptStarMoveTabuMaker", "Declares a given two opt star move as tabu.")]
|
---|
[7689] | 34 | [StorableClass]
|
---|
[12005] | 35 | public class PotvinTwoOptStarMoveTabuMaker : SingleSuccessorOperator, ITabuMaker, IPotvinTwoOptStarMoveOperator, IPotvinOperator, ISingleObjectiveOperator {
|
---|
[7689] | 36 | public LookupParameter<ItemList<IItem>> TabuListParameter {
|
---|
| 37 | get { return (LookupParameter<ItemList<IItem>>)Parameters["TabuList"]; }
|
---|
| 38 | }
|
---|
| 39 | public ValueLookupParameter<IntValue> TabuTenureParameter {
|
---|
| 40 | get { return (ValueLookupParameter<IntValue>)Parameters["TabuTenure"]; }
|
---|
| 41 | }
|
---|
| 42 | public ILookupParameter<DoubleValue> MoveQualityParameter {
|
---|
| 43 | get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
|
---|
| 44 | }
|
---|
| 45 | public ILookupParameter<DoubleValue> QualityParameter {
|
---|
| 46 | get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 47 | }
|
---|
| 48 | public IValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
| 49 | get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 |
|
---|
[7865] | 53 | public ILookupParameter<PotvinTwoOptStarMove> TwoOptStarMoveParameter {
|
---|
| 54 | get { return (ILookupParameter<PotvinTwoOptStarMove>)Parameters["PotvinTwoOptStarMove"]; }
|
---|
[7689] | 55 | }
|
---|
| 56 | public ILookupParameter VRPMoveParameter {
|
---|
[7865] | 57 | get { return TwoOptStarMoveParameter; }
|
---|
[7689] | 58 | }
|
---|
| 59 | public ILookupParameter<IVRPEncoding> VRPToursParameter {
|
---|
| 60 | get { return (ILookupParameter<IVRPEncoding>)Parameters["VRPTours"]; }
|
---|
| 61 | }
|
---|
| 62 | public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
|
---|
| 63 | get { return (LookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | public ILookupParameter<DoubleValue> DistanceParameter {
|
---|
| 67 | get { return (ILookupParameter<DoubleValue>)Parameters["Distance"]; }
|
---|
| 68 | }
|
---|
| 69 | public ILookupParameter<DoubleValue> OverloadParameter {
|
---|
| 70 | get { return (ILookupParameter<DoubleValue>)Parameters["Overload"]; }
|
---|
| 71 | }
|
---|
| 72 | public ILookupParameter<DoubleValue> TardinessParameter {
|
---|
| 73 | get { return (ILookupParameter<DoubleValue>)Parameters["Tardiness"]; }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | [StorableConstructor]
|
---|
[7865] | 77 | protected PotvinTwoOptStarMoveTabuMaker(bool deserializing) : base(deserializing) { }
|
---|
| 78 | protected PotvinTwoOptStarMoveTabuMaker(PotvinTwoOptStarMoveTabuMaker original, Cloner cloner) : base(original, cloner) { }
|
---|
| 79 | public PotvinTwoOptStarMoveTabuMaker()
|
---|
[7689] | 80 | : base() {
|
---|
| 81 | Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list where move attributes are stored."));
|
---|
| 82 | Parameters.Add(new ValueLookupParameter<IntValue>("TabuTenure", "The tenure of the tabu list."));
|
---|
| 83 | Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the move."));
|
---|
| 84 | Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution."));
|
---|
| 85 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
|
---|
| 86 |
|
---|
[7865] | 87 | Parameters.Add(new LookupParameter<PotvinTwoOptStarMove>("PotvinTwoOptStarMove", "The moves that should be made."));
|
---|
[7689] | 88 | Parameters.Add(new LookupParameter<IVRPEncoding>("VRPTours", "The VRP tours considered in the move."));
|
---|
| 89 | Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance"));
|
---|
| 90 |
|
---|
| 91 | Parameters.Add(new LookupParameter<DoubleValue>("Distance", "The distance of the individual"));
|
---|
| 92 | Parameters.Add(new LookupParameter<DoubleValue>("Overload", "The overload of the individual"));
|
---|
| 93 | Parameters.Add(new LookupParameter<DoubleValue>("Tardiness", "The tardiness of the individual"));
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[7865] | 97 | return new PotvinTwoOptStarMoveTabuMaker(this, cloner);
|
---|
[7689] | 98 | }
|
---|
| 99 |
|
---|
| 100 | public override IOperation Apply() {
|
---|
| 101 | ItemList<IItem> tabuList = TabuListParameter.ActualValue;
|
---|
| 102 | int tabuTenure = TabuTenureParameter.ActualValue.Value;
|
---|
| 103 |
|
---|
| 104 | int overlength = tabuList.Count - tabuTenure;
|
---|
| 105 | if (overlength >= 0) {
|
---|
| 106 | for (int i = 0; i < tabuTenure - 1; i++)
|
---|
| 107 | tabuList[i] = tabuList[i + overlength + 1];
|
---|
| 108 | while (tabuList.Count >= tabuTenure)
|
---|
| 109 | tabuList.RemoveAt(tabuList.Count - 1);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | double distance = 0;
|
---|
| 113 | if (DistanceParameter.ActualValue != null)
|
---|
| 114 | distance = DistanceParameter.ActualValue.Value;
|
---|
| 115 |
|
---|
| 116 | double overload = 0;
|
---|
| 117 | if (OverloadParameter.ActualValue != null)
|
---|
| 118 | overload = OverloadParameter.ActualValue.Value;
|
---|
| 119 |
|
---|
| 120 | double tardiness = 0;
|
---|
| 121 | if (TardinessParameter.ActualValue != null)
|
---|
| 122 | tardiness = TardinessParameter.ActualValue.Value;
|
---|
| 123 |
|
---|
[7865] | 124 | PotvinTwoOptStarMove move = TwoOptStarMoveParameter.ActualValue;
|
---|
[7689] | 125 | double moveQuality = MoveQualityParameter.ActualValue.Value;
|
---|
| 126 | double quality = QualityParameter.ActualValue.Value;
|
---|
| 127 | double baseQuality = moveQuality;
|
---|
| 128 | if (quality < moveQuality) baseQuality = quality; // we make an uphill move, the lower bound is the solution quality
|
---|
| 129 |
|
---|
| 130 | List<int> segmentX1;
|
---|
| 131 | List<int> segmentX2;
|
---|
[7865] | 132 | PotvinTwoOptStarMoveMaker.GetSegments(move, out segmentX1, out segmentX2);
|
---|
[7689] | 133 |
|
---|
| 134 | foreach (int city in segmentX1) {
|
---|
[7865] | 135 | tabuList.Add(new PotvinTwoOptStarMoveAttribute(baseQuality, move.Tour1, city, distance, overload, tardiness));
|
---|
[7689] | 136 | }
|
---|
| 137 |
|
---|
| 138 | foreach (int city in segmentX2) {
|
---|
[7865] | 139 | tabuList.Add(new PotvinTwoOptStarMoveAttribute(baseQuality, move.Tour2, city, distance, overload, tardiness));
|
---|
[7689] | 140 | }
|
---|
[8053] | 141 |
|
---|
[7689] | 142 | return base.Apply();
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 | }
|
---|