Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDRearrange/PotvinPDRearrangeMoveTabuCriterion.cs

Last change on this file was 17717, checked in by abeham, 4 years ago

#2521: working on VRP (refactoring all the capabilities, features, and operator discovery)

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