[7689] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12009] | 3 | * Copyright (C) 2002-2015 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;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Operators;
|
---|
| 27 | using HeuristicLab.Optimization;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
| 31 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
|
---|
[7865] | 34 | [Item("PotvinTwoOptStarTabuCriterion", @"Checks if a certain two opt star move is tabu.")]
|
---|
[7689] | 35 | [StorableClass]
|
---|
[7865] | 36 | public class PotvinTwoOptStarMoveTabuCriterion : SingleSuccessorOperator, IPotvinTwoOptStarMoveOperator, ITabuChecker, IPotvinOperator, IVRPMoveOperator {
|
---|
[7689] | 37 | public override bool CanChangeName {
|
---|
| 38 | get { return false; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[7865] | 41 | public ILookupParameter<PotvinTwoOptStarMove> TwoOptStarMoveParameter {
|
---|
| 42 | get { return (ILookupParameter<PotvinTwoOptStarMove>)Parameters["PotvinTwoOptStarMove"]; }
|
---|
[7689] | 43 | }
|
---|
| 44 | public ILookupParameter VRPMoveParameter {
|
---|
[7865] | 45 | get { return TwoOptStarMoveParameter; }
|
---|
[7689] | 46 | }
|
---|
| 47 | public ILookupParameter<IVRPEncoding> VRPToursParameter {
|
---|
| 48 | get { return (ILookupParameter<IVRPEncoding>)Parameters["VRPTours"]; }
|
---|
| 49 | }
|
---|
| 50 | public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
|
---|
| 51 | get { return (LookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
|
---|
[8053] | 52 | }
|
---|
[7689] | 53 |
|
---|
| 54 | public ILookupParameter<ItemList<IItem>> TabuListParameter {
|
---|
| 55 | get { return (ILookupParameter<ItemList<IItem>>)Parameters["TabuList"]; }
|
---|
| 56 | }
|
---|
| 57 | public ILookupParameter<BoolValue> MoveTabuParameter {
|
---|
| 58 | get { return (ILookupParameter<BoolValue>)Parameters["MoveTabu"]; }
|
---|
| 59 | }
|
---|
| 60 | public IValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
| 61 | get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
| 62 | }
|
---|
| 63 | public ILookupParameter<DoubleValue> MoveQualityParameter {
|
---|
| 64 | get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
|
---|
| 65 | }
|
---|
| 66 | public ValueParameter<BoolValue> UseAspirationCriterionParameter {
|
---|
| 67 | get { return (ValueParameter<BoolValue>)Parameters["UseAspirationCriterion"]; }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | public ILookupParameter<DoubleValue> MoveDistanceParameter {
|
---|
| 71 | get { return (ILookupParameter<DoubleValue>)Parameters["MoveDistance"]; }
|
---|
| 72 | }
|
---|
| 73 | public ILookupParameter<DoubleValue> MoveOverloadParameter {
|
---|
| 74 | get { return (ILookupParameter<DoubleValue>)Parameters["MoveOverload"]; }
|
---|
| 75 | }
|
---|
| 76 | public ILookupParameter<DoubleValue> MoveTardinessParameter {
|
---|
| 77 | get { return (ILookupParameter<DoubleValue>)Parameters["MoveTardiness"]; }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | public BoolValue UseAspirationCriterion {
|
---|
| 81 | get { return UseAspirationCriterionParameter.Value; }
|
---|
| 82 | set { UseAspirationCriterionParameter.Value = value; }
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | [StorableConstructor]
|
---|
[7865] | 86 | protected PotvinTwoOptStarMoveTabuCriterion(bool deserializing) : base(deserializing) { }
|
---|
| 87 | protected PotvinTwoOptStarMoveTabuCriterion(PotvinTwoOptStarMoveTabuCriterion original, Cloner cloner) : base(original, cloner) { }
|
---|
| 88 | public PotvinTwoOptStarMoveTabuCriterion()
|
---|
[7689] | 89 | : base() {
|
---|
[7865] | 90 | Parameters.Add(new LookupParameter<PotvinTwoOptStarMove>("PotvinTwoOptStarMove", "The moves that should be made."));
|
---|
[7689] | 91 | Parameters.Add(new LookupParameter<IVRPEncoding>("VRPTours", "The VRP tours considered in the move."));
|
---|
| 92 | Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance"));
|
---|
| 93 |
|
---|
| 94 | Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu."));
|
---|
| 95 | Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list."));
|
---|
| 96 | Parameters.Add(new ValueParameter<BoolValue>("UseAspirationCriterion", "Whether to use the aspiration criterion or not.", new BoolValue(true)));
|
---|
| 97 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
|
---|
| 98 | Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the current move."));
|
---|
| 99 |
|
---|
| 100 | Parameters.Add(new LookupParameter<DoubleValue>("MoveDistance", "The distance of the move"));
|
---|
| 101 | Parameters.Add(new LookupParameter<DoubleValue>("MoveOverload", "The overload of the move"));
|
---|
| 102 | Parameters.Add(new LookupParameter<DoubleValue>("MoveTardiness", "The tardiness of the move"));
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[7865] | 106 | return new PotvinTwoOptStarMoveTabuCriterion(this, cloner);
|
---|
[7689] | 107 | }
|
---|
| 108 |
|
---|
| 109 | public override IOperation Apply() {
|
---|
| 110 | ItemList<IItem> tabuList = TabuListParameter.ActualValue;
|
---|
| 111 | double moveQuality = MoveQualityParameter.ActualValue.Value;
|
---|
| 112 | bool useAspiration = UseAspirationCriterion.Value;
|
---|
| 113 | bool isTabu = false;
|
---|
[7865] | 114 | PotvinTwoOptStarMove move = TwoOptStarMoveParameter.ActualValue;
|
---|
[7689] | 115 |
|
---|
| 116 | List<int> segmentX1;
|
---|
| 117 | List<int> segmentX2;
|
---|
[7865] | 118 | PotvinTwoOptStarMoveMaker.GetSegments(move, out segmentX1, out segmentX2);
|
---|
[7689] | 119 |
|
---|
| 120 | foreach (IItem tabuMove in tabuList) {
|
---|
[7865] | 121 | PotvinTwoOptStarMoveAttribute attribute = tabuMove as PotvinTwoOptStarMoveAttribute;
|
---|
[7689] | 122 |
|
---|
| 123 | if (attribute != null) {
|
---|
| 124 | double distance = 0;
|
---|
| 125 | if (MoveDistanceParameter.ActualValue != null)
|
---|
| 126 | distance = MoveDistanceParameter.ActualValue.Value;
|
---|
| 127 |
|
---|
| 128 | double overload = 0;
|
---|
| 129 | if (MoveOverloadParameter.ActualValue != null)
|
---|
| 130 | overload = MoveOverloadParameter.ActualValue.Value;
|
---|
| 131 |
|
---|
| 132 | double tardiness = 0;
|
---|
| 133 | if (MoveTardinessParameter.ActualValue != null)
|
---|
| 134 | tardiness = MoveTardinessParameter.ActualValue.Value;
|
---|
| 135 |
|
---|
| 136 | IVRPProblemInstance instance = ProblemInstanceParameter.ActualValue;
|
---|
| 137 | double quality = attribute.Distance * instance.DistanceFactor.Value;
|
---|
| 138 |
|
---|
| 139 | IHomogenousCapacitatedProblemInstance cvrp = instance as IHomogenousCapacitatedProblemInstance;
|
---|
| 140 | if (cvrp != null)
|
---|
| 141 | quality += attribute.Overload * cvrp.OverloadPenalty.Value;
|
---|
| 142 |
|
---|
| 143 | ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
|
---|
| 144 | if (vrptw != null)
|
---|
| 145 | quality += attribute.Tardiness * vrptw.TardinessPenalty.Value;
|
---|
| 146 |
|
---|
| 147 | if (!useAspiration || moveQuality >= quality) {
|
---|
| 148 | if (attribute.Tour == move.Tour1 && segmentX2.Contains(attribute.City) ||
|
---|
| 149 | attribute.Tour == move.Tour2 && segmentX1.Contains(attribute.City)) {
|
---|
| 150 | isTabu = true;
|
---|
| 151 | break;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | if (attribute.Distance == distance && attribute.Overload == overload && attribute.Tardiness == tardiness) {
|
---|
| 155 | isTabu = true;
|
---|
| 156 | break;
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
[8053] | 161 |
|
---|
[7689] | 162 | MoveTabuParameter.ActualValue = new BoolValue(isTabu);
|
---|
| 163 | return base.Apply();
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | }
|
---|