[4374] | 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.Linq;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Operators;
|
---|
| 26 | using HeuristicLab.Optimization;
|
---|
| 27 | using HeuristicLab.Parameters;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
| 30 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
[4752] | 31 | using HeuristicLab.Common;
|
---|
[4374] | 32 |
|
---|
| 33 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
| 34 | /// <summary>
|
---|
| 35 | /// An operator for analyzing the best solution of Vehicle Routing Problems.
|
---|
| 36 | /// </summary>
|
---|
| 37 | [Item("BestCapacitatedVRPSolutionAnalyzer", "An operator for analyzing the best solution of capacitated Vehicle Routing Problems.")]
|
---|
| 38 | [StorableClass]
|
---|
| 39 | public sealed class BestCapacitatedVRPSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer, ICapacitatedOperator {
|
---|
| 40 | public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
|
---|
| 41 | get { return (ILookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
|
---|
| 42 | }
|
---|
| 43 | public ScopeTreeLookupParameter<IVRPEncoding> VRPToursParameter {
|
---|
| 44 | get { return (ScopeTreeLookupParameter<IVRPEncoding>)Parameters["VRPTours"]; }
|
---|
| 45 | }
|
---|
| 46 | public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
| 47 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | public ScopeTreeLookupParameter<DoubleValue> OverloadParameter {
|
---|
| 51 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Overload"]; }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | public LookupParameter<VRPSolution> BestSolutionParameter {
|
---|
| 55 | get { return (LookupParameter<VRPSolution>)Parameters["BestSolution"]; }
|
---|
| 56 | }
|
---|
| 57 | public ValueLookupParameter<ResultCollection> ResultsParameter {
|
---|
| 58 | get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[7175] | 61 | public bool EnabledByDefault {
|
---|
| 62 | get { return true; }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[4374] | 65 | [StorableConstructor]
|
---|
| 66 | private BestCapacitatedVRPSolutionAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
| 67 |
|
---|
| 68 | public BestCapacitatedVRPSolutionAnalyzer()
|
---|
| 69 | : base() {
|
---|
| 70 | Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
|
---|
| 71 | Parameters.Add(new ScopeTreeLookupParameter<IVRPEncoding>("VRPTours", "The VRP tours which should be evaluated."));
|
---|
| 72 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the VRP solutions which should be analyzed."));
|
---|
| 73 |
|
---|
| 74 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Overload", "The overloads of the VRP solutions which should be analyzed."));
|
---|
| 75 |
|
---|
[6710] | 76 | Parameters.Add(new LookupParameter<VRPSolution>("BestSolution", "The best VRP solution."));
|
---|
[4374] | 77 | Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best VRP solution should be stored."));
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[4752] | 80 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 81 | return new BestCapacitatedVRPSolutionAnalyzer(this, cloner);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | private BestCapacitatedVRPSolutionAnalyzer(BestCapacitatedVRPSolutionAnalyzer original, Cloner cloner)
|
---|
| 85 | : base(original, cloner) {
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[4374] | 88 | public override IOperation Apply() {
|
---|
| 89 | ItemArray<IVRPEncoding> solutions = VRPToursParameter.ActualValue;
|
---|
| 90 | ResultCollection results = ResultsParameter.ActualValue;
|
---|
| 91 |
|
---|
| 92 | ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
|
---|
| 93 | ItemArray<DoubleValue> overloads = OverloadParameter.ActualValue;
|
---|
| 94 |
|
---|
| 95 | int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
|
---|
| 96 |
|
---|
| 97 | VRPSolution solution = BestSolutionParameter.ActualValue;
|
---|
[6710] | 98 | if (solution != null) {
|
---|
| 99 | if (!results.ContainsKey("Best VRP Solution Overload")) {
|
---|
| 100 | results.Add(new Result("Best VRP Solution Overload", new DoubleValue(overloads[i].Value)));
|
---|
| 101 | } else {
|
---|
| 102 | if (qualities[i].Value <= solution.Quality.Value) {
|
---|
| 103 | (results["Best VRP Solution Overload"].Value as DoubleValue).Value = overloads[i].Value;
|
---|
| 104 | }
|
---|
[4374] | 105 | }
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | return base.Apply();
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | }
|
---|