1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 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.Optimization.Operators;
|
---|
25 | using HeuristicLab.Parameters;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
28 | using HeuristicLab.Operators;
|
---|
29 | using HeuristicLab.Data;
|
---|
30 | using HeuristicLab.Optimization;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
|
---|
33 | [Item("PotvinVehicleAssignmentMoveTabuMaker", "Declares a given vehicle assignment move as tabu.")]
|
---|
34 | [StorableClass]
|
---|
35 | public class PotvinVehicleAssignmentMoveTabuMaker : SingleSuccessorOperator, ITabuMaker, IPotvinVehicleAssignmentMoveOperator, IPotvinOperator, IVRPMoveOperator {
|
---|
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 |
|
---|
53 | public ILookupParameter<PotvinVehicleAssignmentMove> VehicleAssignmentMoveParameter {
|
---|
54 | get { return (ILookupParameter<PotvinVehicleAssignmentMove>)Parameters["PotvinVehicleAssignmentMove"]; }
|
---|
55 | }
|
---|
56 | public ILookupParameter VRPMoveParameter {
|
---|
57 | get { return VehicleAssignmentMoveParameter; }
|
---|
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]
|
---|
77 | protected PotvinVehicleAssignmentMoveTabuMaker(bool deserializing) : base(deserializing) { }
|
---|
78 | protected PotvinVehicleAssignmentMoveTabuMaker(PotvinVehicleAssignmentMoveTabuMaker original, Cloner cloner) : base(original, cloner) { }
|
---|
79 | public PotvinVehicleAssignmentMoveTabuMaker()
|
---|
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 |
|
---|
87 | Parameters.Add(new LookupParameter<PotvinVehicleAssignmentMove>("PotvinVehicleAssignmentMove", "The moves that should be made."));
|
---|
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) {
|
---|
97 | return new PotvinVehicleAssignmentMoveTabuMaker(this, cloner);
|
---|
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 | PotvinVehicleAssignmentMove move = VehicleAssignmentMoveParameter.ActualValue;
|
---|
113 | double moveQuality = MoveQualityParameter.ActualValue.Value;
|
---|
114 | double quality = QualityParameter.ActualValue.Value;
|
---|
115 | double baseQuality = moveQuality;
|
---|
116 | if (quality < moveQuality) baseQuality = quality; // we make an uphill move, the lower bound is the solution quality
|
---|
117 |
|
---|
118 | double distance = 0;
|
---|
119 | if (DistanceParameter.ActualValue != null)
|
---|
120 | distance = DistanceParameter.ActualValue.Value;
|
---|
121 |
|
---|
122 | double overload = 0;
|
---|
123 | if (OverloadParameter.ActualValue != null)
|
---|
124 | overload = OverloadParameter.ActualValue.Value;
|
---|
125 |
|
---|
126 | double tardiness = 0;
|
---|
127 | if (TardinessParameter.ActualValue != null)
|
---|
128 | tardiness = TardinessParameter.ActualValue.Value;
|
---|
129 |
|
---|
130 | tabuList.Add(new PotvinVehicleAssignmentMoveAttribute(baseQuality, move.Tour1, move.Individual.GetVehicleAssignment(move.Tour1),
|
---|
131 | distance, overload, tardiness));
|
---|
132 | tabuList.Add(new PotvinVehicleAssignmentMoveAttribute(baseQuality, move.Tour2, move.Individual.GetVehicleAssignment(move.Tour2),
|
---|
133 | distance, overload, tardiness));
|
---|
134 |
|
---|
135 | return base.Apply();
|
---|
136 | }
|
---|
137 | }
|
---|
138 | }
|
---|