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("PickupViolationsRelaxationVRPAnalyzer", "An operator for adaptively relaxing the pickup constraints.")]
|
---|
38 | [StorableType("86D541AB-5E65-432B-A8C4-F012A6B46275")]
|
---|
39 | public class PickupViolationsRelaxationVRPAnalyzer : SingleSuccessorOperator, IAnalyzer, IPickupAndDeliveryOperator, ISingleObjectiveOperator {
|
---|
40 | [Storable] public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter { get; private set; }
|
---|
41 | [Storable] public IScopeTreeLookupParameter<IVRPEncodedSolution> VRPToursParameter { get; private set; }
|
---|
42 | [Storable] public IScopeTreeLookupParameter<CVRPPDTWEvaluation> 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> CurrentPickupViolationPenaltyResult { get; private set; }
|
---|
50 |
|
---|
51 |
|
---|
52 | public bool EnabledByDefault {
|
---|
53 | get { return false; }
|
---|
54 | }
|
---|
55 |
|
---|
56 | [StorableConstructor]
|
---|
57 | protected PickupViolationsRelaxationVRPAnalyzer(StorableConstructorFlag _) : base(_) { }
|
---|
58 | protected PickupViolationsRelaxationVRPAnalyzer(PickupViolationsRelaxationVRPAnalyzer original, Cloner cloner)
|
---|
59 | : base(original, cloner) {
|
---|
60 | ProblemInstanceParameter = cloner.Clone(original.ProblemInstanceParameter);
|
---|
61 | VRPToursParameter = cloner.Clone(original.VRPToursParameter);
|
---|
62 | EvaluationResultParameter = cloner.Clone(original.EvaluationResultParameter);
|
---|
63 | SigmaParameter = cloner.Clone(original.SigmaParameter);
|
---|
64 | PhiParameter = cloner.Clone(original.PhiParameter);
|
---|
65 | MinPenaltyFactorParameter = cloner.Clone(original.MinPenaltyFactorParameter);
|
---|
66 | MaxPenaltyFactorParameter = cloner.Clone(original.MaxPenaltyFactorParameter);
|
---|
67 | CurrentPickupViolationPenaltyResult = cloner.Clone(original.CurrentPickupViolationPenaltyResult);
|
---|
68 | }
|
---|
69 | public PickupViolationsRelaxationVRPAnalyzer()
|
---|
70 | : base() {
|
---|
71 | Parameters.Add(ProblemInstanceParameter = new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
|
---|
72 | Parameters.Add(VRPToursParameter = new ScopeTreeLookupParameter<IVRPEncodedSolution>("VRPTours", "The VRP tours which should be evaluated."));
|
---|
73 | Parameters.Add(EvaluationResultParameter = new ScopeTreeLookupParameter<CVRPPDTWEvaluation>("EvaluationResult", "The evaluations of the VRP solutions which should be analyzed."));
|
---|
74 |
|
---|
75 | Parameters.Add(SigmaParameter = new ValueParameter<DoubleValue>("Sigma", "The sigma applied to the penalty factor.", new DoubleValue(0.5)));
|
---|
76 | Parameters.Add(PhiParameter = new ValueParameter<DoubleValue>("Phi", "The phi applied to the penalty factor.", new DoubleValue(0.5)));
|
---|
77 | Parameters.Add(MinPenaltyFactorParameter = new ValueParameter<DoubleValue>("MinPenaltyFactor", "The minimum penalty factor.", new DoubleValue(0.01)));
|
---|
78 | Parameters.Add(MaxPenaltyFactorParameter = new ValueParameter<DoubleValue>("MaxPenaltyFactor", "The maximum penalty factor.", new DoubleValue(100000)));
|
---|
79 | Parameters.Add(CurrentPickupViolationPenaltyResult = new ResultParameter<DoubleValue>("Current Pickup Violation Penalty", "The current penalty applied to violating pickup-dropoff precedence constraint.", new DoubleValue(double.NaN)));
|
---|
80 | }
|
---|
81 |
|
---|
82 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
83 | return new PickupViolationsRelaxationVRPAnalyzer(this, cloner);
|
---|
84 | }
|
---|
85 |
|
---|
86 | public override IOperation Apply() {
|
---|
87 | var pdp = (IPickupAndDeliveryProblemInstance)ProblemInstanceParameter.ActualValue;
|
---|
88 |
|
---|
89 | ItemArray<CVRPPDTWEvaluation> evaluations = EvaluationResultParameter.ActualValue;
|
---|
90 |
|
---|
91 | double sigma = SigmaParameter.Value.Value;
|
---|
92 | double phi = PhiParameter.Value.Value;
|
---|
93 | double minPenalty = MinPenaltyFactorParameter.Value.Value;
|
---|
94 | double maxPenalty = MaxPenaltyFactorParameter.Value.Value;
|
---|
95 |
|
---|
96 | for (int j = 0; j < evaluations.Length; j++) {
|
---|
97 | evaluations[j].Quality -= evaluations[j].PickupViolations * pdp.PickupViolationPenalty.Value;
|
---|
98 | }
|
---|
99 |
|
---|
100 | int validCount = 0;
|
---|
101 | for (int j = 0; j < evaluations.Length; j++) {
|
---|
102 | if (evaluations[j].PickupViolations == 0)
|
---|
103 | validCount++;
|
---|
104 | }
|
---|
105 |
|
---|
106 | double factor = 1.0 - ((double)validCount / (double)evaluations.Length);
|
---|
107 |
|
---|
108 | double min = pdp.PickupViolationPenalty.Value / (1 + sigma);
|
---|
109 | double max = pdp.PickupViolationPenalty.Value * (1 + phi);
|
---|
110 |
|
---|
111 | pdp.CurrentPickupViolationPenalty = new DoubleValue(min + (max - min) * factor);
|
---|
112 | if (pdp.CurrentPickupViolationPenalty.Value < minPenalty)
|
---|
113 | pdp.CurrentPickupViolationPenalty.Value = minPenalty;
|
---|
114 | if (pdp.CurrentPickupViolationPenalty.Value > maxPenalty)
|
---|
115 | pdp.CurrentPickupViolationPenalty.Value = maxPenalty;
|
---|
116 |
|
---|
117 | for (int j = 0; j < evaluations.Length; j++) {
|
---|
118 | evaluations[j].Quality += evaluations[j].PickupViolations * pdp.CurrentPickupViolationPenalty.Value;
|
---|
119 | }
|
---|
120 |
|
---|
121 | CurrentPickupViolationPenaltyResult.ActualValue = new DoubleValue(pdp.CurrentPickupViolationPenalty.Value);
|
---|
122 |
|
---|
123 | return base.Apply();
|
---|
124 | }
|
---|
125 | }
|
---|
126 | }
|
---|