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 |
|
---|
22 | using HEAL.Attic;
|
---|
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.Problems.VehicleRouting.Interfaces;
|
---|
30 | using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
|
---|
31 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
34 | /// <summary>
|
---|
35 | /// An operator for adaptive constraint relaxation.
|
---|
36 | /// </summary>
|
---|
37 | [Item("TimeWindowRelaxationVRPAnalyzer", "An operator for adaptively relaxing the time window constraints.")]
|
---|
38 | [StorableType("e782fe43-c77f-445a-a676-7b03db53ca99")]
|
---|
39 | public class TimeWindowRelaxationVRPAnalyzer : SingleSuccessorOperator, IAnalyzer, ITimeWindowedOperator, ISingleObjectiveOperator {
|
---|
40 | [Storable] public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter { get; private set; }
|
---|
41 | [Storable] public IScopeTreeLookupParameter<IVRPEncodedSolution> VRPToursParameter { get; private set; }
|
---|
42 | [Storable] public IScopeTreeLookupParameter<CVRPTWEvaluation> EvaluationResultParameter { get; private set; }
|
---|
43 |
|
---|
44 | [Storable] public IValueParameter<DoubleValue> SigmaParameter { get; private set; }
|
---|
45 | [Storable] public IValueParameter<DoubleValue> PhiParameter { get; private set; }
|
---|
46 | [Storable] public IValueParameter<DoubleValue> MinPenaltyFactorParameter { get; private set; }
|
---|
47 | [Storable] public IValueParameter<DoubleValue> MaxPenaltyFactorParameter { get; private set; }
|
---|
48 |
|
---|
49 | [Storable] public IResultParameter<DoubleValue> CurrentTardinessPenaltyResult { get; private set; }
|
---|
50 |
|
---|
51 | public bool EnabledByDefault {
|
---|
52 | get { return false; }
|
---|
53 | }
|
---|
54 |
|
---|
55 | [StorableConstructor]
|
---|
56 | protected TimeWindowRelaxationVRPAnalyzer(StorableConstructorFlag _) : base(_) { }
|
---|
57 | protected TimeWindowRelaxationVRPAnalyzer(TimeWindowRelaxationVRPAnalyzer original, Cloner cloner)
|
---|
58 | : base(original, cloner) {
|
---|
59 | ProblemInstanceParameter = cloner.Clone(original.ProblemInstanceParameter);
|
---|
60 | VRPToursParameter = cloner.Clone(original.VRPToursParameter);
|
---|
61 | EvaluationResultParameter = cloner.Clone(original.EvaluationResultParameter);
|
---|
62 | SigmaParameter = cloner.Clone(original.SigmaParameter);
|
---|
63 | PhiParameter = cloner.Clone(original.PhiParameter);
|
---|
64 | MinPenaltyFactorParameter = cloner.Clone(original.MinPenaltyFactorParameter);
|
---|
65 | MaxPenaltyFactorParameter = cloner.Clone(original.MaxPenaltyFactorParameter);
|
---|
66 | CurrentTardinessPenaltyResult = cloner.Clone(original.CurrentTardinessPenaltyResult);
|
---|
67 | }
|
---|
68 | public TimeWindowRelaxationVRPAnalyzer()
|
---|
69 | : base() {
|
---|
70 | Parameters.Add(ProblemInstanceParameter = new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
|
---|
71 | Parameters.Add(VRPToursParameter = new ScopeTreeLookupParameter<IVRPEncodedSolution>("VRPTours", "The VRP tours which should be evaluated."));
|
---|
72 | Parameters.Add(EvaluationResultParameter = new ScopeTreeLookupParameter<CVRPTWEvaluation>("EvaluationResult", "The evaluations of the VRP solutions which should be analyzed."));
|
---|
73 |
|
---|
74 | Parameters.Add(SigmaParameter = new ValueParameter<DoubleValue>("Sigma", "The sigma applied to the penalty factor.", new DoubleValue(0.5)));
|
---|
75 | Parameters.Add(PhiParameter = new ValueParameter<DoubleValue>("Phi", "The phi applied to the penalty factor.", new DoubleValue(0.5)));
|
---|
76 | Parameters.Add(MinPenaltyFactorParameter = new ValueParameter<DoubleValue>("MinPenaltyFactor", "The minimum penalty factor.", new DoubleValue(0.01)));
|
---|
77 | Parameters.Add(MaxPenaltyFactorParameter = new ValueParameter<DoubleValue>("MaxPenaltyFactor", "The maximum penalty factor.", new DoubleValue(100000)));
|
---|
78 | Parameters.Add(CurrentTardinessPenaltyResult = new ResultParameter<DoubleValue>("Current Tardiness Penalty", "The current penalty applied to failing the time window constraint.", new DoubleValue(double.NaN)));
|
---|
79 | }
|
---|
80 |
|
---|
81 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
82 | return new TimeWindowRelaxationVRPAnalyzer(this, cloner);
|
---|
83 | }
|
---|
84 |
|
---|
85 | public override IOperation Apply() {
|
---|
86 | var vrptw = (ITimeWindowedProblemInstance)ProblemInstanceParameter.ActualValue;
|
---|
87 |
|
---|
88 | ItemArray<CVRPTWEvaluation> evaluations = EvaluationResultParameter.ActualValue;
|
---|
89 |
|
---|
90 | double sigma = SigmaParameter.Value.Value;
|
---|
91 | double phi = PhiParameter.Value.Value;
|
---|
92 | double minPenalty = MinPenaltyFactorParameter.Value.Value;
|
---|
93 | double maxPenalty = MaxPenaltyFactorParameter.Value.Value;
|
---|
94 |
|
---|
95 | for (int j = 0; j < evaluations.Length; j++) {
|
---|
96 | evaluations[j].Quality -= evaluations[j].Tardiness * vrptw.TardinessPenalty.Value;
|
---|
97 | }
|
---|
98 |
|
---|
99 | int validCount = 0;
|
---|
100 | for (int j = 0; j < evaluations.Length; j++) {
|
---|
101 | if (evaluations[j].Tardiness == 0)
|
---|
102 | validCount++;
|
---|
103 | }
|
---|
104 |
|
---|
105 | double factor = 1.0 - ((double)validCount / (double)evaluations.Length);
|
---|
106 |
|
---|
107 | double min = vrptw.TardinessPenalty.Value / (1 + sigma);
|
---|
108 | double max = vrptw.TardinessPenalty.Value * (1 + phi);
|
---|
109 |
|
---|
110 | vrptw.CurrentTardinessPenalty = new DoubleValue(min + (max - min) * factor);
|
---|
111 | if (vrptw.CurrentTardinessPenalty.Value < minPenalty)
|
---|
112 | vrptw.CurrentTardinessPenalty.Value = minPenalty;
|
---|
113 | if (vrptw.CurrentTardinessPenalty.Value > maxPenalty)
|
---|
114 | vrptw.CurrentTardinessPenalty.Value = maxPenalty;
|
---|
115 |
|
---|
116 | for (int j = 0; j < evaluations.Length; j++) {
|
---|
117 | evaluations[j].Quality += evaluations[j].Tardiness * vrptw.CurrentTardinessPenalty.Value;
|
---|
118 | }
|
---|
119 |
|
---|
120 | CurrentTardinessPenaltyResult.ActualValue = new DoubleValue(vrptw.CurrentTardinessPenalty.Value);
|
---|
121 |
|
---|
122 | return base.Apply();
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|