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