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 System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
28 | using HeuristicLab.Operators;
|
---|
29 | using HeuristicLab.Optimization;
|
---|
30 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
31 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
32 | using HeuristicLab.Parameters;
|
---|
33 | using HeuristicLab.Data;
|
---|
34 | using HeuristicLab.Common;
|
---|
35 |
|
---|
36 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
37 | /// <summary>
|
---|
38 | /// An operator for adaptive constraint relaxation.
|
---|
39 | /// </summary>
|
---|
40 | [Item("PickupViolationsRelaxationVRPAnalyzer", "An operator for adaptively relaxing the pickup constraints.")]
|
---|
41 | [StorableClass]
|
---|
42 | public class PickupViolationsRelaxationVRPAnalyzer: SingleSuccessorOperator, IAnalyzer, IPickupAndDeliveryOperator {
|
---|
43 | public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
|
---|
44 | get { return (ILookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
|
---|
45 | }
|
---|
46 | public ScopeTreeLookupParameter<IVRPEncoding> VRPToursParameter {
|
---|
47 | get { return (ScopeTreeLookupParameter<IVRPEncoding>)Parameters["VRPTours"]; }
|
---|
48 | }
|
---|
49 | public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
50 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
51 | }
|
---|
52 |
|
---|
53 | public ScopeTreeLookupParameter<IntValue> PickupViolationsParameter {
|
---|
54 | get { return (ScopeTreeLookupParameter<IntValue>)Parameters["PickupViolations"]; }
|
---|
55 | }
|
---|
56 |
|
---|
57 | public IValueParameter<DoubleValue> SigmaParameter {
|
---|
58 | get { return (IValueParameter<DoubleValue>)Parameters["Sigma"]; }
|
---|
59 | }
|
---|
60 | public IValueParameter<DoubleValue> PhiParameter {
|
---|
61 | get { return (IValueParameter<DoubleValue>)Parameters["Phi"]; }
|
---|
62 | }
|
---|
63 | public IValueParameter<DoubleValue> MinPenaltyFactorParameter {
|
---|
64 | get { return (IValueParameter<DoubleValue>)Parameters["MinPenaltyFactor"]; }
|
---|
65 | }
|
---|
66 |
|
---|
67 | public ValueLookupParameter<ResultCollection> ResultsParameter {
|
---|
68 | get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
69 | }
|
---|
70 |
|
---|
71 | public bool EnabledByDefault {
|
---|
72 | get { return false; }
|
---|
73 | }
|
---|
74 |
|
---|
75 | [StorableConstructor]
|
---|
76 | protected PickupViolationsRelaxationVRPAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
77 |
|
---|
78 | public PickupViolationsRelaxationVRPAnalyzer()
|
---|
79 | : base() {
|
---|
80 | Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
|
---|
81 | Parameters.Add(new ScopeTreeLookupParameter<IVRPEncoding>("VRPTours", "The VRP tours which should be evaluated."));
|
---|
82 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the VRP solutions which should be analyzed."));
|
---|
83 |
|
---|
84 | Parameters.Add(new ScopeTreeLookupParameter<IntValue>("PickupViolations", "The pickup violation of the VRP solutions which should be analyzed."));
|
---|
85 |
|
---|
86 | Parameters.Add(new ValueParameter<DoubleValue>("Sigma", "The sigma applied to the penalty factor.", new DoubleValue(0.04)));
|
---|
87 | Parameters.Add(new ValueParameter<DoubleValue>("Phi", "The phi applied to the penalty factor.", new DoubleValue(0.01)));
|
---|
88 | Parameters.Add(new ValueParameter<DoubleValue>("MinPenaltyFactor", "The minimum penalty factor.", new DoubleValue(0.01)));
|
---|
89 |
|
---|
90 | Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best VRP solution should be stored."));
|
---|
91 | }
|
---|
92 |
|
---|
93 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
94 | return new PickupViolationsRelaxationVRPAnalyzer(this, cloner);
|
---|
95 | }
|
---|
96 |
|
---|
97 | protected PickupViolationsRelaxationVRPAnalyzer(PickupViolationsRelaxationVRPAnalyzer original, Cloner cloner)
|
---|
98 | : base(original, cloner) {
|
---|
99 | }
|
---|
100 |
|
---|
101 | public override IOperation Apply() {
|
---|
102 | IPickupAndDeliveryProblemInstance pdp = ProblemInstanceParameter.ActualValue as IPickupAndDeliveryProblemInstance;
|
---|
103 | ResultCollection results = ResultsParameter.ActualValue;
|
---|
104 |
|
---|
105 | ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
|
---|
106 | ItemArray<IntValue> pickupViolations = PickupViolationsParameter.ActualValue;
|
---|
107 |
|
---|
108 | double sigma = SigmaParameter.Value.Value;
|
---|
109 | double phi = PhiParameter.Value.Value;
|
---|
110 | double minPenalty = MinPenaltyFactorParameter.Value.Value;
|
---|
111 |
|
---|
112 | for (int j = 0; j < qualities.Length; j++) {
|
---|
113 | qualities[j].Value -= pickupViolations[j].Value * pdp.PickupViolationPenalty.Value;
|
---|
114 | }
|
---|
115 |
|
---|
116 | int validCount = 0;
|
---|
117 | for (int j = 0; j < qualities.Length; j++) {
|
---|
118 | if (pickupViolations[j].Value == 0)
|
---|
119 | validCount++;
|
---|
120 | }
|
---|
121 |
|
---|
122 | double factor = 1.0 - ((double)validCount / (double)qualities.Length);
|
---|
123 |
|
---|
124 | double min = pdp.PickupViolationPenalty.Value / (1 + sigma);
|
---|
125 | double max = pdp.PickupViolationPenalty.Value * (1 + phi);
|
---|
126 |
|
---|
127 | pdp.PickupViolationPenalty = new DoubleValue(min + (max - min) * factor);
|
---|
128 | if (pdp.PickupViolationPenalty.Value < minPenalty)
|
---|
129 | pdp.PickupViolationPenalty.Value = minPenalty;
|
---|
130 |
|
---|
131 | for (int j = 0; j < qualities.Length; j++) {
|
---|
132 | qualities[j].Value += pickupViolations[j].Value * pdp.PickupViolationPenalty.Value;
|
---|
133 | }
|
---|
134 |
|
---|
135 | if (!results.ContainsKey("Current Pickup Violation Penalty")) {
|
---|
136 | results.Add(new Result("Current Pickup Violation Penalty", new DoubleValue(pdp.PickupViolationPenalty.Value)));
|
---|
137 | } else {
|
---|
138 | (results["Current Pickup Violation Penalty"].Value as DoubleValue).Value = pdp.PickupViolationPenalty.Value;
|
---|
139 | }
|
---|
140 |
|
---|
141 | return base.Apply();
|
---|
142 | }
|
---|
143 | }
|
---|
144 | }
|
---|