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