Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Analyzers/GQAPSolutionArchiveAnalyzer.cs @ 7470

Last change on this file since 7470 was 7470, checked in by abeham, 12 years ago

#1614

  • Removed incompatible problem linhp318.tsp (contains fixed edges)
  • Fixed AssemblyInfo for TSPLIB
  • Added unit tests
  • Worked on assignment / solution view
File size: 10.5 KB
Line 
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
22using System.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.IntegerVectorEncoding;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace 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]
38  public sealed class GQAPSolutionArchiveAnalyzer : SingleSuccessorOperator, IAssignmentsAwareGQAPOperator,
39    IQualitiesAwareGQAPOperator, IDistancesAwareGQAPOperator, IWeightsAwareGQAPOperator, IInstallationCostsAwareGQAPOperator,
40    IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, ITransportationCostsAwareGQAPOperator,
41    IOverbookedCapacityPenaltyAwareGQAPOperator, IEquipmentNamesAwareGQAPOperator, ILocationNamesAwareGQAPOperator,
42    IBestKnownSolutionsAwareGQAPOperator, IAnalyzer {
43
44    public bool EnabledByDefault {
45      get { return true; }
46    }
47
48    public IScopeTreeLookupParameter<IntegerVector> AssignmentParameter {
49      get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters["Assignment"]; }
50    }
51    public ILookupParameter<BoolValue> MaximizationParameter {
52      get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
53    }
54    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
55      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
56    }
57    public IScopeTreeLookupParameter<DoubleValue> FlowDistanceQualityParameter {
58      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; }
59    }
60    public IScopeTreeLookupParameter<DoubleValue> InstallationQualityParameter {
61      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["InstallationQuality"]; }
62    }
63    public IScopeTreeLookupParameter<DoubleValue> OverbookedCapacityParameter {
64      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; }
65    }
66    public ILookupParameter<DoubleMatrix> DistancesParameter {
67      get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; }
68    }
69    public ILookupParameter<DoubleMatrix> WeightsParameter {
70      get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; }
71    }
72    public ILookupParameter<DoubleMatrix> InstallationCostsParameter {
73      get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; }
74    }
75    public ILookupParameter<DoubleArray> DemandsParameter {
76      get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
77    }
78    public ILookupParameter<DoubleArray> CapacitiesParameter {
79      get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
80    }
81    public IValueLookupParameter<DoubleValue> TransportationCostsParameter {
82      get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }
83    }
84    public IValueLookupParameter<DoubleValue> OverbookedCapacityPenaltyParameter {
85      get { return (IValueLookupParameter<DoubleValue>)Parameters["OverbookedCapacityPenalty"]; }
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    }
93    public IValueLookupParameter<ResultCollection> ResultsParameter {
94      get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
95    }
96    public ILookupParameter<GQAPAssignmentArchive> BestKnownSolutionsParameter {
97      get { return (ILookupParameter<GQAPAssignmentArchive>)Parameters["BestKnownSolutions"]; }
98    }
99
100    [StorableConstructor]
101    private GQAPSolutionArchiveAnalyzer(bool deserializing) : base(deserializing) { }
102    private GQAPSolutionArchiveAnalyzer(GQAPSolutionArchiveAnalyzer original, Cloner cloner) : base(original, cloner) { }
103    public override IDeepCloneable Clone(Cloner cloner) {
104      return new GQAPSolutionArchiveAnalyzer(this, cloner);
105    }
106    public GQAPSolutionArchiveAnalyzer()
107      : base() {
108      Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription));
109      Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription));
110      Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription));
111      Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription));
112      Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
113      Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
114      Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription));
115      Parameters.Add(new ValueLookupParameter<DoubleValue>("OverbookedCapacityPenalty", GeneralizedQuadraticAssignmentProblem.OverbookedCapacityPenaltyDescription));
116      Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
117      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription));
118      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription));
119      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription));
120      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription));
121      Parameters.Add(new LookupParameter<StringArray>("EquipmentNames", GeneralizedQuadraticAssignmentProblem.EquipmentNamesDescription));
122      Parameters.Add(new LookupParameter<StringArray>("LocationNames", GeneralizedQuadraticAssignmentProblem.LocationNamesDescription));
123      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best GQAP solution should be stored."));
124      Parameters.Add(new LookupParameter<GQAPAssignmentArchive>("BestKnownSolutions", GeneralizedQuadraticAssignmentProblem.BestKnownSolutionsDescription));
125    }
126
127    public override IOperation Apply() {
128      var assignments = AssignmentParameter.ActualValue;
129      var qualities = QualityParameter.ActualValue;
130      var equipmentNames = EquipmentNamesParameter.ActualValue;
131      var locationNames = LocationNamesParameter.ActualValue;
132      var flowDistanceQualities = FlowDistanceQualityParameter.ActualValue;
133      var installationQualities = InstallationQualityParameter.ActualValue;
134      var overbookedCapacities = OverbookedCapacityParameter.ActualValue;
135      var distances = DistancesParameter.ActualValue;
136      var weights = WeightsParameter.ActualValue;
137      var installationCosts = InstallationCostsParameter.ActualValue;
138      var demands = DemandsParameter.ActualValue;
139      var capacities = CapacitiesParameter.ActualValue;
140      var transportationCosts = TransportationCostsParameter.ActualValue;
141      var overbookedCapacityPenalty = OverbookedCapacityPenaltyParameter.ActualValue;
142      var results = ResultsParameter.ActualValue;
143      var maximization = MaximizationParameter.ActualValue.Value;
144
145      GQAPAssignmentArchive archive = results.ContainsKey("Solution Archive") ? results["Solution Archive"].Value as GQAPAssignmentArchive : null;
146      if (archive == null) {
147        archive = new GQAPAssignmentArchive(equipmentNames, locationNames, distances, weights, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);
148        results.Add(new Result("Solution Archive", archive));
149      } else {
150        archive.EquipmentNames = equipmentNames;
151        archive.LocationNames = locationNames;
152        archive.Distances = distances;
153        archive.Weights = weights;
154        archive.InstallationCosts = installationCosts;
155        archive.Demands = demands;
156        archive.Capacities = capacities;
157        archive.TransportationCosts = transportationCosts;
158        archive.OverbookedCapacityPenalty = overbookedCapacityPenalty;
159      }
160
161      var solutions = Enumerable.Range(0, assignments.Length)
162        .Select(i => new GQAPSolution(assignments[i], qualities[i], flowDistanceQualities[i], installationQualities[i], overbookedCapacities[i]))
163        .Concat(archive.Solutions);
164      archive.Solutions = GQAPSolutionArchiveUpdater.GetFeasibleParetoFront(solutions);
165
166      GQAPAssignmentArchive bestKnownArchive = BestKnownSolutionsParameter.ActualValue;
167      if (bestKnownArchive == null) {
168        bestKnownArchive = new GQAPAssignmentArchive();
169        BestKnownSolutionsParameter.ActualValue = bestKnownArchive;
170      } else {
171        var archiveSolutions = Enumerable.Range(0, assignments.Length)
172        .Select(i => new GQAPSolution(assignments[i], qualities[i], flowDistanceQualities[i], installationQualities[i], overbookedCapacities[i]))
173        .Concat(archive.Solutions);
174        bestKnownArchive.Solutions = GQAPSolutionArchiveUpdater.GetFeasibleParetoFront(archiveSolutions);
175      }
176
177      return base.Apply();
178    }
179  }
180}
Note: See TracBrowser for help on using the repository browser.