[4301] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[5445] | 3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[4301] | 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.Linq;
|
---|
[4722] | 23 | using HeuristicLab.Common;
|
---|
[4301] | 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Operators;
|
---|
| 27 | using HeuristicLab.Parameters;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
| 31 | [Item("BestVRPToursMemorizer", "An operator that updates the best VRP tour found so far in the scope three.")]
|
---|
| 32 | [StorableClass]
|
---|
| 33 | public class BestVRPToursMemorizer : SingleSuccessorOperator {
|
---|
| 34 | public ScopeTreeLookupParameter<DoubleValue> OverloadParameter {
|
---|
| 35 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Overload"]; }
|
---|
| 36 | }
|
---|
| 37 | public ScopeTreeLookupParameter<DoubleValue> TardinessParameter {
|
---|
| 38 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Tardiness"]; }
|
---|
| 39 | }
|
---|
| 40 | public ScopeTreeLookupParameter<DoubleValue> DistanceParameter {
|
---|
| 41 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Distance"]; }
|
---|
| 42 | }
|
---|
| 43 | public ScopeTreeLookupParameter<DoubleValue> TravelTimeParameter {
|
---|
| 44 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["TravelTime"]; }
|
---|
| 45 | }
|
---|
| 46 | public ScopeTreeLookupParameter<DoubleValue> VehiclesUtilizedParameter {
|
---|
| 47 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["VehiclesUtilized"]; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | public ValueLookupParameter<DoubleValue> BestOverloadParameter {
|
---|
| 51 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestOverload"]; }
|
---|
| 52 | }
|
---|
| 53 | public ValueLookupParameter<DoubleValue> BestTardinessParameter {
|
---|
| 54 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestTardiness"]; }
|
---|
| 55 | }
|
---|
| 56 | public ValueLookupParameter<DoubleValue> BestDistanceParameter {
|
---|
| 57 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestDistance"]; }
|
---|
| 58 | }
|
---|
| 59 | public ValueLookupParameter<DoubleValue> BestTravelTimeParameter {
|
---|
| 60 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestTravelTime"]; }
|
---|
| 61 | }
|
---|
| 62 | public ValueLookupParameter<DoubleValue> BestVehiclesUtilizedParameter {
|
---|
| 63 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestVehiclesUtilized"]; }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[4722] | 66 | [StorableConstructor]
|
---|
| 67 | protected BestVRPToursMemorizer(bool deserializing) : base(deserializing) { }
|
---|
| 68 | protected BestVRPToursMemorizer(BestVRPToursMemorizer original, Cloner cloner)
|
---|
| 69 | : base(original, cloner) {
|
---|
| 70 | }
|
---|
[4301] | 71 | public BestVRPToursMemorizer()
|
---|
| 72 | : base() {
|
---|
| 73 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Distance", "The distances of the VRP solutions which should be analyzed."));
|
---|
| 74 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Overload", "The overloads of the VRP solutions which should be analyzed."));
|
---|
| 75 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Tardiness", "The tardiness of the VRP solutions which should be analyzed."));
|
---|
| 76 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("TravelTime", "The travel times of the VRP solutions which should be analyzed."));
|
---|
| 77 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("VehiclesUtilized", "The utilized vehicles of the VRP solutions which should be analyzed."));
|
---|
| 78 |
|
---|
| 79 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestDistance", "The best distance found so far."));
|
---|
| 80 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestOverload", "The best overload found so far."));
|
---|
| 81 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestTardiness", "The best tardiness found so far."));
|
---|
| 82 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestTravelTime", "The best travel time found so far."));
|
---|
| 83 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestVehiclesUtilized", "The best vehicles utilized found so far."));
|
---|
| 84 |
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[4722] | 87 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 88 | return new BestVRPToursMemorizer(this, cloner);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[4301] | 91 | public override IOperation Apply() {
|
---|
| 92 | int i = OverloadParameter.ActualValue.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
|
---|
| 93 | if (BestOverloadParameter.ActualValue == null)
|
---|
| 94 | BestOverloadParameter.ActualValue = new DoubleValue(OverloadParameter.ActualValue[i].Value);
|
---|
| 95 | else if(OverloadParameter.ActualValue[i].Value <= BestOverloadParameter.ActualValue.Value)
|
---|
| 96 | BestOverloadParameter.ActualValue.Value = OverloadParameter.ActualValue[i].Value;
|
---|
| 97 |
|
---|
| 98 | i = TardinessParameter.ActualValue.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
|
---|
| 99 | if (BestTardinessParameter.ActualValue == null)
|
---|
| 100 | BestTardinessParameter.ActualValue = new DoubleValue(TardinessParameter.ActualValue[i].Value);
|
---|
| 101 | else if (TardinessParameter.ActualValue[i].Value <= BestTardinessParameter.ActualValue.Value)
|
---|
| 102 | BestTardinessParameter.ActualValue.Value = TardinessParameter.ActualValue[i].Value;
|
---|
| 103 |
|
---|
| 104 | i = DistanceParameter.ActualValue.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
|
---|
| 105 | if (BestDistanceParameter.ActualValue == null)
|
---|
| 106 | BestDistanceParameter.ActualValue = new DoubleValue(DistanceParameter.ActualValue[i].Value);
|
---|
| 107 | else if (DistanceParameter.ActualValue[i].Value <= BestDistanceParameter.ActualValue.Value)
|
---|
| 108 | BestDistanceParameter.ActualValue.Value = DistanceParameter.ActualValue[i].Value;
|
---|
| 109 |
|
---|
| 110 | i = TravelTimeParameter.ActualValue.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
|
---|
| 111 | if (BestTravelTimeParameter.ActualValue == null)
|
---|
| 112 | BestTravelTimeParameter.ActualValue = new DoubleValue(TravelTimeParameter.ActualValue[i].Value);
|
---|
| 113 | else if (TravelTimeParameter.ActualValue[i].Value <= BestTravelTimeParameter.ActualValue.Value)
|
---|
| 114 | BestTravelTimeParameter.ActualValue.Value = TravelTimeParameter.ActualValue[i].Value;
|
---|
| 115 |
|
---|
| 116 | i = VehiclesUtilizedParameter.ActualValue.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
|
---|
| 117 | if (BestVehiclesUtilizedParameter.ActualValue == null)
|
---|
| 118 | BestVehiclesUtilizedParameter.ActualValue = new DoubleValue(VehiclesUtilizedParameter.ActualValue[i].Value);
|
---|
| 119 | else if (VehiclesUtilizedParameter.ActualValue[i].Value <= BestVehiclesUtilizedParameter.ActualValue.Value)
|
---|
| 120 | BestVehiclesUtilizedParameter.ActualValue.Value = VehiclesUtilizedParameter.ActualValue[i].Value;
|
---|
| 121 |
|
---|
| 122 | return base.Apply();
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|