[6711] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9456] | 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6711] | 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 |
|
---|
[8053] | 22 | using HeuristicLab.Common;
|
---|
[6711] | 23 | using HeuristicLab.Core;
|
---|
[8053] | 24 | using HeuristicLab.Data;
|
---|
[6711] | 25 | using HeuristicLab.Operators;
|
---|
| 26 | using HeuristicLab.Optimization;
|
---|
[8053] | 27 | using HeuristicLab.Parameters;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
[6711] | 30 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
| 33 | /// <summary>
|
---|
| 34 | /// An operator for adaptive constraint relaxation.
|
---|
| 35 | /// </summary>
|
---|
| 36 | [Item("PickupViolationsRelaxationVRPAnalyzer", "An operator for adaptively relaxing the pickup constraints.")]
|
---|
| 37 | [StorableClass]
|
---|
[8053] | 38 | public class PickupViolationsRelaxationVRPAnalyzer : SingleSuccessorOperator, IAnalyzer, IPickupAndDeliveryOperator {
|
---|
[6711] | 39 | public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
|
---|
| 40 | get { return (ILookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
|
---|
| 41 | }
|
---|
| 42 | public ScopeTreeLookupParameter<IVRPEncoding> VRPToursParameter {
|
---|
| 43 | get { return (ScopeTreeLookupParameter<IVRPEncoding>)Parameters["VRPTours"]; }
|
---|
| 44 | }
|
---|
| 45 | public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
| 46 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public ScopeTreeLookupParameter<IntValue> PickupViolationsParameter {
|
---|
| 50 | get { return (ScopeTreeLookupParameter<IntValue>)Parameters["PickupViolations"]; }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public IValueParameter<DoubleValue> SigmaParameter {
|
---|
| 54 | get { return (IValueParameter<DoubleValue>)Parameters["Sigma"]; }
|
---|
| 55 | }
|
---|
| 56 | public IValueParameter<DoubleValue> PhiParameter {
|
---|
| 57 | get { return (IValueParameter<DoubleValue>)Parameters["Phi"]; }
|
---|
| 58 | }
|
---|
| 59 | public IValueParameter<DoubleValue> MinPenaltyFactorParameter {
|
---|
| 60 | get { return (IValueParameter<DoubleValue>)Parameters["MinPenaltyFactor"]; }
|
---|
| 61 | }
|
---|
[8497] | 62 | public IValueParameter<DoubleValue> MaxPenaltyFactorParameter {
|
---|
| 63 | get { return (IValueParameter<DoubleValue>)Parameters["MaxPenaltyFactor"]; }
|
---|
| 64 | }
|
---|
[6711] | 65 |
|
---|
| 66 | public ValueLookupParameter<ResultCollection> ResultsParameter {
|
---|
| 67 | get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[7175] | 70 | public bool EnabledByDefault {
|
---|
| 71 | get { return false; }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[6711] | 74 | [StorableConstructor]
|
---|
[7906] | 75 | protected PickupViolationsRelaxationVRPAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
[6711] | 76 |
|
---|
| 77 | public PickupViolationsRelaxationVRPAnalyzer()
|
---|
| 78 | : base() {
|
---|
| 79 | Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
|
---|
| 80 | Parameters.Add(new ScopeTreeLookupParameter<IVRPEncoding>("VRPTours", "The VRP tours which should be evaluated."));
|
---|
| 81 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the VRP solutions which should be analyzed."));
|
---|
| 82 |
|
---|
| 83 | Parameters.Add(new ScopeTreeLookupParameter<IntValue>("PickupViolations", "The pickup violation of the VRP solutions which should be analyzed."));
|
---|
| 84 |
|
---|
[8497] | 85 | Parameters.Add(new ValueParameter<DoubleValue>("Sigma", "The sigma applied to the penalty factor.", new DoubleValue(0.5)));
|
---|
| 86 | Parameters.Add(new ValueParameter<DoubleValue>("Phi", "The phi applied to the penalty factor.", new DoubleValue(0.5)));
|
---|
[6711] | 87 | Parameters.Add(new ValueParameter<DoubleValue>("MinPenaltyFactor", "The minimum penalty factor.", new DoubleValue(0.01)));
|
---|
[8497] | 88 | Parameters.Add(new ValueParameter<DoubleValue>("MaxPenaltyFactor", "The maximum penalty factor.", new DoubleValue(100000)));
|
---|
[6711] | 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 |
|
---|
[7906] | 97 | protected PickupViolationsRelaxationVRPAnalyzer(PickupViolationsRelaxationVRPAnalyzer original, Cloner cloner)
|
---|
[6711] | 98 | : base(original, cloner) {
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[8497] | 101 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 102 | private void AfterDeserialization() {
|
---|
| 103 | // BackwardsCompatibility3.3
|
---|
| 104 | #region Backwards compatible code, remove with 3.4
|
---|
| 105 | if (!Parameters.ContainsKey("MaxPenaltyFactor")) {
|
---|
| 106 | Parameters.Add(new ValueParameter<DoubleValue>("MaxPenaltyFactor", "The maximum penalty factor.", new DoubleValue(100000)));
|
---|
| 107 | }
|
---|
| 108 | #endregion
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[6711] | 111 | public override IOperation Apply() {
|
---|
| 112 | IPickupAndDeliveryProblemInstance pdp = ProblemInstanceParameter.ActualValue as IPickupAndDeliveryProblemInstance;
|
---|
| 113 | ResultCollection results = ResultsParameter.ActualValue;
|
---|
[8053] | 114 |
|
---|
[6711] | 115 | ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
|
---|
| 116 | ItemArray<IntValue> pickupViolations = PickupViolationsParameter.ActualValue;
|
---|
[8053] | 117 |
|
---|
[6711] | 118 | double sigma = SigmaParameter.Value.Value;
|
---|
| 119 | double phi = PhiParameter.Value.Value;
|
---|
| 120 | double minPenalty = MinPenaltyFactorParameter.Value.Value;
|
---|
[8497] | 121 | double maxPenalty = MaxPenaltyFactorParameter.Value.Value;
|
---|
[6711] | 122 |
|
---|
| 123 | for (int j = 0; j < qualities.Length; j++) {
|
---|
| 124 | qualities[j].Value -= pickupViolations[j].Value * pdp.PickupViolationPenalty.Value;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | int validCount = 0;
|
---|
| 128 | for (int j = 0; j < qualities.Length; j++) {
|
---|
| 129 | if (pickupViolations[j].Value == 0)
|
---|
| 130 | validCount++;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | double factor = 1.0 - ((double)validCount / (double)qualities.Length);
|
---|
| 134 |
|
---|
| 135 | double min = pdp.PickupViolationPenalty.Value / (1 + sigma);
|
---|
| 136 | double max = pdp.PickupViolationPenalty.Value * (1 + phi);
|
---|
| 137 |
|
---|
| 138 | pdp.PickupViolationPenalty = new DoubleValue(min + (max - min) * factor);
|
---|
| 139 | if (pdp.PickupViolationPenalty.Value < minPenalty)
|
---|
| 140 | pdp.PickupViolationPenalty.Value = minPenalty;
|
---|
[8497] | 141 | if (pdp.PickupViolationPenalty.Value > maxPenalty)
|
---|
| 142 | pdp.PickupViolationPenalty.Value = maxPenalty;
|
---|
[6711] | 143 |
|
---|
| 144 | for (int j = 0; j < qualities.Length; j++) {
|
---|
| 145 | qualities[j].Value += pickupViolations[j].Value * pdp.PickupViolationPenalty.Value;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | if (!results.ContainsKey("Current Pickup Violation Penalty")) {
|
---|
| 149 | results.Add(new Result("Current Pickup Violation Penalty", new DoubleValue(pdp.PickupViolationPenalty.Value)));
|
---|
| 150 | } else {
|
---|
| 151 | (results["Current Pickup Violation Penalty"].Value as DoubleValue).Value = pdp.PickupViolationPenalty.Value;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | return base.Apply();
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 | }
|
---|