Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 7419 was 7419, checked in by abeham, 13 years ago

#1614

  • reworked parameterization (one interface for every parameter resp. parameter group)
  • unified parameter descriptions
File size: 11.2 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Encodings.IntegerVectorEncoding;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
32  /// <summary>
33  /// An operator for analyzing the best solution of Generalized Quadratic Assignment Problems.
34  /// </summary>
35  [Item("GeneralizedQAP Solution Archive Analyzer", "An operator for analyzing the archive of found solutions for the GQAP.")]
36  [StorableClass]
37  public sealed class GQAPSolutionArchiveAnalyzer : SingleSuccessorOperator, IAssignmentsAwareGQAPOperator,
38    IQualitiesAwareGQAPOperator, IDistancesAwareGQAPOperator, IWeightsAwareGQAPOperator, IInstallationCostsAwareGQAPOperator,
39    IDemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, ITransportationCostsAwareGQAPOperator,
40    IOverbookedCapacityPenaltyAwareGQAPOperator, IEquipmentNamesAwareGQAPOperator, ILocationNamesAwareGQAPOperator,
41    IBestKnownQualityAwareGQAPOperator, IBestKnownSolutionAwareGQAPOperator, IAnalyzer {
42
43    public bool EnabledByDefault {
44      get { return false; }
45    }
46
47    public IScopeTreeLookupParameter<IntegerVector> AssignmentParameter {
48      get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters["Assignment"]; }
49    }
50    public ILookupParameter<BoolValue> MaximizationParameter {
51      get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
52    }
53    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
54      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
55    }
56    public IScopeTreeLookupParameter<DoubleValue> FlowDistanceQualityParameter {
57      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; }
58    }
59    public IScopeTreeLookupParameter<DoubleValue> InstallationQualityParameter {
60      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["InstallationQuality"]; }
61    }
62    public IScopeTreeLookupParameter<DoubleValue> OverbookedCapacityParameter {
63      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; }
64    }
65    public ILookupParameter<DoubleMatrix> DistancesParameter {
66      get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; }
67    }
68    public ILookupParameter<DoubleMatrix> WeightsParameter {
69      get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; }
70    }
71    public ILookupParameter<DoubleMatrix> InstallationCostsParameter {
72      get { return (ILookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; }
73    }
74    public ILookupParameter<DoubleArray> DemandsParameter {
75      get { return (ILookupParameter<DoubleArray>)Parameters["Demands"]; }
76    }
77    public ILookupParameter<DoubleArray> CapacitiesParameter {
78      get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; }
79    }
80    public IValueLookupParameter<DoubleValue> TransportationCostsParameter {
81      get { return (IValueLookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }
82    }
83    public IValueLookupParameter<DoubleValue> OverbookedCapacityPenaltyParameter {
84      get { return (IValueLookupParameter<DoubleValue>)Parameters["OverbookedCapacityPenalty"]; }
85    }
86    public ILookupParameter<StringArray> EquipmentNamesParameter {
87      get { return (ILookupParameter<StringArray>)Parameters["EquipmentNames"]; }
88    }
89    public ILookupParameter<StringArray> LocationNamesParameter {
90      get { return (ILookupParameter<StringArray>)Parameters["LocationNames"]; }
91    }
92    public ILookupParameter<DoubleValue> BestKnownQualityParameter {
93      get { return (ILookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
94    }
95    public ILookupParameter<IntegerVector> BestKnownSolutionParameter {
96      get { return (ILookupParameter<IntegerVector>)Parameters["BestKnownSolution"]; }
97    }
98    public ILookupParameter<GQAPAssignment> BestSolutionParameter {
99      get { return (ILookupParameter<GQAPAssignment>)Parameters["BestSolution"]; }
100    }
101    public IValueLookupParameter<ResultCollection> ResultsParameter {
102      get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
103    }
104
105    [StorableConstructor]
106    private GQAPSolutionArchiveAnalyzer(bool deserializing) : base(deserializing) { }
107    private GQAPSolutionArchiveAnalyzer(GQAPSolutionArchiveAnalyzer original, Cloner cloner) : base(original, cloner) { }
108    public override IDeepCloneable Clone(Cloner cloner) {
109      return new GQAPSolutionArchiveAnalyzer(this, cloner);
110    }
111    public GQAPSolutionArchiveAnalyzer()
112      : base() {
113      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));
114      Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", "The distances between the locations."));
115      Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", "The weights between the equipments."));
116      Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", "The cost of installing equipment x at location y."));
117      Parameters.Add(new LookupParameter<DoubleArray>("Demands", "The demands of the equipments."));
118      Parameters.Add(new LookupParameter<DoubleArray>("Capacities", "The capacities at the locations."));
119      Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", "The transportation cost represents the flow-unit per distance-unit cost factor. This value can also be set to 1 if these costs are factored into the weights matrix already."));
120      Parameters.Add(new ValueLookupParameter<DoubleValue>("OverbookedCapacityPenalty", "The multiplier for the constraint violation when added to the quality."));
121      Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Assignment", "The GQAP solutions from which the best solution should be analyzed."));
122      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the GQAP solutions which should be analyzed."));
123      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("FlowDistanceQuality", "The flow-distance qualities of the GQAP solutions which should be analyzed."));
124      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InstallationQuality", "The installation qualities of the GQAP solutions which should be analyzed."));
125      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("OverbookedCapacity", "The overbooked capacities of the GQAP solutions which should be analyzed."));
126      Parameters.Add(new LookupParameter<GQAPAssignment>("BestSolution", "The best GQAP solution."));
127      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best GQAP solution should be stored."));
128      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this GQAP instance."));
129      Parameters.Add(new LookupParameter<IntegerVector>("BestKnownSolution", "The best known solution of this GQAP instance."));
130      Parameters.Add(new LookupParameter<StringArray>("EquipmentNames", "A list of names that describes the equipments."));
131      Parameters.Add(new LookupParameter<StringArray>("LocationNames", "A list of names that describes the locations."));
132    }
133
134    public override IOperation Apply() {
135      var assignments = AssignmentParameter.ActualValue;
136      var qualities = QualityParameter.ActualValue;
137      var equipmentNames = EquipmentNamesParameter.ActualValue;
138      var locationNames = LocationNamesParameter.ActualValue;
139      var flowDistanceQualities = FlowDistanceQualityParameter.ActualValue;
140      var installationQualities = InstallationQualityParameter.ActualValue;
141      var overbookedCapacities = OverbookedCapacityParameter.ActualValue;
142      var distances = DistancesParameter.ActualValue;
143      var weights = WeightsParameter.ActualValue;
144      var installationCosts = InstallationCostsParameter.ActualValue;
145      var demands = DemandsParameter.ActualValue;
146      var capacities = CapacitiesParameter.ActualValue;
147      var transportationCosts = TransportationCostsParameter.ActualValue;
148      var overbookedCapacityPenalty = OverbookedCapacityPenaltyParameter.ActualValue;
149      var results = ResultsParameter.ActualValue;
150      var maximization = MaximizationParameter.ActualValue.Value;
151      var bestKnownQuality = BestKnownQualityParameter.ActualValue;
152
153      GQAPAssignmentArchive archive = results.ContainsKey("Solution Archive") ? results["Solution Archive"].Value as GQAPAssignmentArchive : null;
154      if (archive == null) {
155        archive = new GQAPAssignmentArchive(equipmentNames, locationNames, distances, weights, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);
156        results.Add(new Result("Solution Archive", archive));
157      } else {
158        archive.EquipmentNames = equipmentNames;
159        archive.LocationNames = locationNames;
160        archive.Distances = distances;
161        archive.Weights = weights;
162        archive.InstallationCosts = installationCosts;
163        archive.Demands = demands;
164        archive.Capacities = capacities;
165        archive.TransportationCosts = transportationCosts;
166        archive.OverbookedCapacityPenalty = overbookedCapacityPenalty;
167      }
168
169      ItemList<GQAPSolution> front = new ItemList<GQAPSolution>(archive.Solutions);
170      for (int i = 0; i < assignments.Length; i++) {
171        if (overbookedCapacities[i].Value <= 0.0)
172          front.Add(new GQAPSolution(assignments[i], qualities[i], flowDistanceQualities[i], installationQualities[i], overbookedCapacities[i]));
173      }
174
175      for (int i = 0; i < front.Count - 1; i++) {
176        for (int j = i + 1; j < front.Count; j++) {
177          if (front[i].FlowDistanceQuality.Value < front[j].FlowDistanceQuality.Value
178            && front[i].InstallationQuality.Value < front[j].InstallationQuality.Value) {
179            front.RemoveAt(j);
180            j--;
181          } else if (front[i].FlowDistanceQuality.Value > front[j].FlowDistanceQuality.Value
182            && front[i].InstallationQuality.Value > front[j].InstallationQuality.Value) {
183            front.RemoveAt(i);
184            j = i + 1;
185          }
186        }
187      }
188
189      archive.Solutions = front;
190
191      return base.Apply();
192    }
193  }
194}
Note: See TracBrowser for help on using the repository browser.