[7418] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2012 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 |
|
---|
[7438] | 22 | using System.Linq;
|
---|
[7418] | 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
| 27 | using HeuristicLab.Operators;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Parameters;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
|
---|
| 33 | /// <summary>
|
---|
| 34 | /// An operator for analyzing the best solution of Generalized Quadratic Assignment Problems.
|
---|
| 35 | /// </summary>
|
---|
| 36 | [Item("GeneralizedQAP Solution Archive Analyzer", "An operator for analyzing the archive of found solutions for the GQAP.")]
|
---|
| 37 | [StorableClass]
|
---|
[7419] | 38 | public sealed class GQAPSolutionArchiveAnalyzer : SingleSuccessorOperator, IAssignmentsAwareGQAPOperator,
|
---|
| 39 | IQualitiesAwareGQAPOperator, IDistancesAwareGQAPOperator, IWeightsAwareGQAPOperator, IInstallationCostsAwareGQAPOperator,
|
---|
| 40 | IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, ITransportationCostsAwareGQAPOperator,
|
---|
[7970] | 41 | IExpectedRandomQualityAwareGQAPOperator, IEquipmentNamesAwareGQAPOperator, ILocationNamesAwareGQAPOperator,
|
---|
| 42 | IBestKnownSolutionsAwareGQAPOperator, IEvaluatorAwareGQAPOperator, IAnalyzer {
|
---|
[7418] | 43 |
|
---|
| 44 | public bool EnabledByDefault {
|
---|
[7470] | 45 | get { return true; }
|
---|
[7418] | 46 | }
|
---|
| 47 |
|
---|
[7419] | 48 | public IScopeTreeLookupParameter<IntegerVector> AssignmentParameter {
|
---|
| 49 | get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters["Assignment"]; }
|
---|
[7418] | 50 | }
|
---|
[7419] | 51 | public ILookupParameter<BoolValue> MaximizationParameter {
|
---|
| 52 | get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
[7418] | 53 | }
|
---|
[7419] | 54 | public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
| 55 | get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
[7418] | 56 | }
|
---|
[7419] | 57 | public IScopeTreeLookupParameter<DoubleValue> FlowDistanceQualityParameter {
|
---|
| 58 | get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; }
|
---|
[7418] | 59 | }
|
---|
[7419] | 60 | public IScopeTreeLookupParameter<DoubleValue> InstallationQualityParameter {
|
---|
| 61 | get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["InstallationQuality"]; }
|
---|
[7418] | 62 | }
|
---|
[7419] | 63 | public IScopeTreeLookupParameter<DoubleValue> OverbookedCapacityParameter {
|
---|
| 64 | get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; }
|
---|
[7418] | 65 | }
|
---|
[7419] | 66 | public ILookupParameter<DoubleMatrix> DistancesParameter {
|
---|
| 67 | get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; }
|
---|
[7418] | 68 | }
|
---|
[7419] | 69 | public ILookupParameter<DoubleMatrix> WeightsParameter {
|
---|
| 70 | get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; }
|
---|
[7418] | 71 | }
|
---|
[7419] | 72 | public ILookupParameter<DoubleMatrix> InstallationCostsParameter {
|
---|
| 73 | get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; }
|
---|
[7418] | 74 | }
|
---|
[7419] | 75 | public ILookupParameter<DoubleArray> DemandsParameter {
|
---|
| 76 | get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
|
---|
[7418] | 77 | }
|
---|
[7419] | 78 | public ILookupParameter<DoubleArray> CapacitiesParameter {
|
---|
| 79 | get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
|
---|
[7418] | 80 | }
|
---|
[7419] | 81 | public IValueLookupParameter<DoubleValue> TransportationCostsParameter {
|
---|
| 82 | get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }
|
---|
[7418] | 83 | }
|
---|
[7970] | 84 | public IValueLookupParameter<DoubleValue> ExpectedRandomQualityParameter {
|
---|
| 85 | get { return (IValueLookupParameter<DoubleValue>)Parameters["ExpectedRandomQuality"]; }
|
---|
[7418] | 86 | }
|
---|
| 87 | public ILookupParameter<StringArray> EquipmentNamesParameter {
|
---|
| 88 | get { return (ILookupParameter<StringArray>)Parameters["EquipmentNames"]; }
|
---|
| 89 | }
|
---|
| 90 | public ILookupParameter<StringArray> LocationNamesParameter {
|
---|
| 91 | get { return (ILookupParameter<StringArray>)Parameters["LocationNames"]; }
|
---|
| 92 | }
|
---|
[7419] | 93 | public IValueLookupParameter<ResultCollection> ResultsParameter {
|
---|
| 94 | get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
| 95 | }
|
---|
[7470] | 96 | public ILookupParameter<GQAPAssignmentArchive> BestKnownSolutionsParameter {
|
---|
| 97 | get { return (ILookupParameter<GQAPAssignmentArchive>)Parameters["BestKnownSolutions"]; }
|
---|
| 98 | }
|
---|
[7970] | 99 | public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {
|
---|
| 100 | get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }
|
---|
| 101 | }
|
---|
[7418] | 102 |
|
---|
| 103 | [StorableConstructor]
|
---|
| 104 | private GQAPSolutionArchiveAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
| 105 | private GQAPSolutionArchiveAnalyzer(GQAPSolutionArchiveAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
| 106 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 107 | return new GQAPSolutionArchiveAnalyzer(this, cloner);
|
---|
| 108 | }
|
---|
| 109 | public GQAPSolutionArchiveAnalyzer()
|
---|
| 110 | : base() {
|
---|
[7423] | 111 | Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription));
|
---|
| 112 | Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription));
|
---|
| 113 | Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription));
|
---|
| 114 | Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription));
|
---|
| 115 | Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
|
---|
| 116 | Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
|
---|
| 117 | Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription));
|
---|
[7970] | 118 | Parameters.Add(new ValueLookupParameter<DoubleValue>("ExpectedRandomQuality", GeneralizedQuadraticAssignmentProblem.ExpectedRandomQualityDescription));
|
---|
[7423] | 119 | Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
|
---|
| 120 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription));
|
---|
| 121 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription));
|
---|
| 122 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription));
|
---|
| 123 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription));
|
---|
| 124 | Parameters.Add(new LookupParameter<StringArray>("EquipmentNames", GeneralizedQuadraticAssignmentProblem.EquipmentNamesDescription));
|
---|
| 125 | Parameters.Add(new LookupParameter<StringArray>("LocationNames", GeneralizedQuadraticAssignmentProblem.LocationNamesDescription));
|
---|
[7418] | 126 | Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best GQAP solution should be stored."));
|
---|
[7470] | 127 | Parameters.Add(new LookupParameter<GQAPAssignmentArchive>("BestKnownSolutions", GeneralizedQuadraticAssignmentProblem.BestKnownSolutionsDescription));
|
---|
[7970] | 128 | Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions."));
|
---|
[7418] | 129 | }
|
---|
| 130 |
|
---|
| 131 | public override IOperation Apply() {
|
---|
[7970] | 132 | var evaluator = EvaluatorParameter.ActualValue;
|
---|
[7418] | 133 | var assignments = AssignmentParameter.ActualValue;
|
---|
| 134 | var qualities = QualityParameter.ActualValue;
|
---|
| 135 | var equipmentNames = EquipmentNamesParameter.ActualValue;
|
---|
| 136 | var locationNames = LocationNamesParameter.ActualValue;
|
---|
| 137 | var flowDistanceQualities = FlowDistanceQualityParameter.ActualValue;
|
---|
| 138 | var installationQualities = InstallationQualityParameter.ActualValue;
|
---|
| 139 | var overbookedCapacities = OverbookedCapacityParameter.ActualValue;
|
---|
| 140 | var distances = DistancesParameter.ActualValue;
|
---|
| 141 | var weights = WeightsParameter.ActualValue;
|
---|
| 142 | var installationCosts = InstallationCostsParameter.ActualValue;
|
---|
| 143 | var demands = DemandsParameter.ActualValue;
|
---|
| 144 | var capacities = CapacitiesParameter.ActualValue;
|
---|
| 145 | var transportationCosts = TransportationCostsParameter.ActualValue;
|
---|
[7970] | 146 | var expectedRandomQuality = ExpectedRandomQualityParameter.ActualValue;
|
---|
[7418] | 147 | var results = ResultsParameter.ActualValue;
|
---|
| 148 | var maximization = MaximizationParameter.ActualValue.Value;
|
---|
| 149 |
|
---|
| 150 | GQAPAssignmentArchive archive = results.ContainsKey("Solution Archive") ? results["Solution Archive"].Value as GQAPAssignmentArchive : null;
|
---|
| 151 | if (archive == null) {
|
---|
[7970] | 152 | archive = new GQAPAssignmentArchive(equipmentNames, locationNames, distances, weights, installationCosts, demands, capacities, transportationCosts, expectedRandomQuality, evaluator);
|
---|
[7418] | 153 | results.Add(new Result("Solution Archive", archive));
|
---|
| 154 | } else {
|
---|
| 155 | archive.EquipmentNames = equipmentNames;
|
---|
| 156 | archive.LocationNames = locationNames;
|
---|
| 157 | archive.Distances = distances;
|
---|
| 158 | archive.Weights = weights;
|
---|
| 159 | archive.InstallationCosts = installationCosts;
|
---|
| 160 | archive.Demands = demands;
|
---|
| 161 | archive.Capacities = capacities;
|
---|
| 162 | archive.TransportationCosts = transportationCosts;
|
---|
[7970] | 163 | archive.ExpectedRandomQuality = expectedRandomQuality;
|
---|
| 164 | archive.Evaluator = evaluator;
|
---|
[7418] | 165 | }
|
---|
| 166 |
|
---|
[7438] | 167 | var solutions = Enumerable.Range(0, assignments.Length)
|
---|
| 168 | .Select(i => new GQAPSolution(assignments[i], qualities[i], flowDistanceQualities[i], installationQualities[i], overbookedCapacities[i]))
|
---|
| 169 | .Concat(archive.Solutions);
|
---|
| 170 | archive.Solutions = GQAPSolutionArchiveUpdater.GetFeasibleParetoFront(solutions);
|
---|
[7418] | 171 |
|
---|
[7470] | 172 | GQAPAssignmentArchive bestKnownArchive = BestKnownSolutionsParameter.ActualValue;
|
---|
| 173 | if (bestKnownArchive == null) {
|
---|
| 174 | bestKnownArchive = new GQAPAssignmentArchive();
|
---|
| 175 | BestKnownSolutionsParameter.ActualValue = bestKnownArchive;
|
---|
| 176 | } else {
|
---|
| 177 | var archiveSolutions = Enumerable.Range(0, assignments.Length)
|
---|
| 178 | .Select(i => new GQAPSolution(assignments[i], qualities[i], flowDistanceQualities[i], installationQualities[i], overbookedCapacities[i]))
|
---|
| 179 | .Concat(archive.Solutions);
|
---|
| 180 | bestKnownArchive.Solutions = GQAPSolutionArchiveUpdater.GetFeasibleParetoFront(archiveSolutions);
|
---|
| 181 | }
|
---|
| 182 |
|
---|
[7418] | 183 | return base.Apply();
|
---|
| 184 | }
|
---|
| 185 | }
|
---|
| 186 | }
|
---|