Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1614

  • Added shaking operator based on n-moves
  • Added pareto analyzer regarding flowdistance and installation qualities
File size: 10.7 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, IAnalyzer {
38
39    public bool EnabledByDefault {
40      get { return true; }
41    }
42
43    public LookupParameter<BoolValue> MaximizationParameter {
44      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
45    }
46    public LookupParameter<DoubleMatrix> DistancesParameter {
47      get { return (LookupParameter<DoubleMatrix>)Parameters["Distances"]; }
48    }
49    public LookupParameter<DoubleMatrix> WeightsParameter {
50      get { return (LookupParameter<DoubleMatrix>)Parameters["Weights"]; }
51    }
52    public LookupParameter<DoubleMatrix> InstallationCostsParameter {
53      get { return (LookupParameter<DoubleMatrix>)Parameters["InstallationCosts"]; }
54    }
55    public LookupParameter<DoubleArray> DemandsParameter {
56      get { return (LookupParameter<DoubleArray>)Parameters["Demands"]; }
57    }
58    public LookupParameter<DoubleArray> CapacitiesParameter {
59      get { return (LookupParameter<DoubleArray>)Parameters["Capacities"]; }
60    }
61    public LookupParameter<DoubleValue> TransportationCostsParameter {
62      get { return (LookupParameter<DoubleValue>)Parameters["TransportationCosts"]; }
63    }
64    public LookupParameter<DoubleValue> OverbookedCapacityPenaltyParameter {
65      get { return (LookupParameter<DoubleValue>)Parameters["OverbookedCapacityPenalty"]; }
66    }
67    public ScopeTreeLookupParameter<IntegerVector> AssignmentParameter {
68      get { return (ScopeTreeLookupParameter<IntegerVector>)Parameters["Assignment"]; }
69    }
70    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
71      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
72    }
73    public ScopeTreeLookupParameter<DoubleValue> FlowDistanceQualityParameter {
74      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; }
75    }
76    public ScopeTreeLookupParameter<DoubleValue> InstallationQualityParameter {
77      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["InstallationQuality"]; }
78    }
79    public ScopeTreeLookupParameter<DoubleValue> OverbookedCapacityParameter {
80      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; }
81    }
82    public LookupParameter<GQAPAssignment> BestSolutionParameter {
83      get { return (LookupParameter<GQAPAssignment>)Parameters["BestSolution"]; }
84    }
85    public ValueLookupParameter<ResultCollection> ResultsParameter {
86      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
87    }
88    public LookupParameter<DoubleValue> BestKnownQualityParameter {
89      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
90    }
91    public LookupParameter<IntegerVector> BestKnownSolutionParameter {
92      get { return (LookupParameter<IntegerVector>)Parameters["BestKnownSolution"]; }
93    }
94    public ILookupParameter<StringArray> EquipmentNamesParameter {
95      get { return (ILookupParameter<StringArray>)Parameters["EquipmentNames"]; }
96    }
97    public ILookupParameter<StringArray> LocationNamesParameter {
98      get { return (ILookupParameter<StringArray>)Parameters["LocationNames"]; }
99    }
100
101    [StorableConstructor]
102    private GQAPSolutionArchiveAnalyzer(bool deserializing) : base(deserializing) { }
103    private GQAPSolutionArchiveAnalyzer(GQAPSolutionArchiveAnalyzer original, Cloner cloner) : base(original, cloner) { }
104    public override IDeepCloneable Clone(Cloner cloner) {
105      return new GQAPSolutionArchiveAnalyzer(this, cloner);
106    }
107    public GQAPSolutionArchiveAnalyzer()
108      : base() {
109      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));
110      Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", "The distances between the locations."));
111      Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", "The weights between the equipments."));
112      Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", "The cost of installing equipment x at location y."));
113      Parameters.Add(new LookupParameter<DoubleArray>("Demands", "The demands of the equipments."));
114      Parameters.Add(new LookupParameter<DoubleArray>("Capacities", "The capacities at the locations."));
115      Parameters.Add(new LookupParameter<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."));
116      Parameters.Add(new LookupParameter<DoubleValue>("OverbookedCapacityPenalty", "The multiplier for the constraint violation when added to the quality."));
117      Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Assignment", "The GQAP solutions from which the best solution should be analyzed."));
118      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the GQAP solutions which should be analyzed."));
119      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("FlowDistanceQuality", "The flow-distance qualities of the GQAP solutions which should be analyzed."));
120      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InstallationQuality", "The installation qualities of the GQAP solutions which should be analyzed."));
121      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("OverbookedCapacity", "The overbooked capacities of the GQAP solutions which should be analyzed."));
122      Parameters.Add(new LookupParameter<GQAPAssignment>("BestSolution", "The best GQAP solution."));
123      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best GQAP solution should be stored."));
124      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this GQAP instance."));
125      Parameters.Add(new LookupParameter<IntegerVector>("BestKnownSolution", "The best known solution of this GQAP instance."));
126      Parameters.Add(new LookupParameter<StringArray>("EquipmentNames", "A list of names that describes the equipments."));
127      Parameters.Add(new LookupParameter<StringArray>("LocationNames", "A list of names that describes the locations."));
128    }
129
130    public override IOperation Apply() {
131      var assignments = AssignmentParameter.ActualValue;
132      var qualities = QualityParameter.ActualValue;
133      var equipmentNames = EquipmentNamesParameter.ActualValue;
134      var locationNames = LocationNamesParameter.ActualValue;
135      var flowDistanceQualities = FlowDistanceQualityParameter.ActualValue;
136      var installationQualities = InstallationQualityParameter.ActualValue;
137      var overbookedCapacities = OverbookedCapacityParameter.ActualValue;
138      var distances = DistancesParameter.ActualValue;
139      var weights = WeightsParameter.ActualValue;
140      var installationCosts = InstallationCostsParameter.ActualValue;
141      var demands = DemandsParameter.ActualValue;
142      var capacities = CapacitiesParameter.ActualValue;
143      var transportationCosts = TransportationCostsParameter.ActualValue;
144      var overbookedCapacityPenalty = OverbookedCapacityPenaltyParameter.ActualValue;
145      var results = ResultsParameter.ActualValue;
146      var maximization = MaximizationParameter.ActualValue.Value;
147      var bestKnownQuality = BestKnownQualityParameter.ActualValue;
148
149      GQAPAssignmentArchive archive = results.ContainsKey("Solution Archive") ? results["Solution Archive"].Value as GQAPAssignmentArchive : null;
150      if (archive == null) {
151        archive = new GQAPAssignmentArchive(equipmentNames, locationNames, distances, weights, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);
152        results.Add(new Result("Solution Archive", archive));
153      } else {
154        archive.EquipmentNames = equipmentNames;
155        archive.LocationNames = locationNames;
156        archive.Distances = distances;
157        archive.Weights = weights;
158        archive.InstallationCosts = installationCosts;
159        archive.Demands = demands;
160        archive.Capacities = capacities;
161        archive.TransportationCosts = transportationCosts;
162        archive.OverbookedCapacityPenalty = overbookedCapacityPenalty;
163      }
164
165      ItemList<GQAPSolution> front = new ItemList<GQAPSolution>(archive.Solutions);
166      for (int i = 0; i < assignments.Length; i++) {
167        if (overbookedCapacities[i].Value <= 0.0)
168          front.Add(new GQAPSolution(assignments[i], qualities[i], flowDistanceQualities[i], installationQualities[i], overbookedCapacities[i]));
169      }
170
171      for (int i = 0; i < front.Count - 1; i++) {
172        for (int j = i + 1; j < front.Count; j++) {
173          if (front[i].FlowDistanceQuality.Value < front[j].FlowDistanceQuality.Value
174            && front[i].InstallationQuality.Value < front[j].InstallationQuality.Value) {
175            front.RemoveAt(j);
176            j--;
177          } else if (front[i].FlowDistanceQuality.Value > front[j].FlowDistanceQuality.Value
178            && front[i].InstallationQuality.Value > front[j].InstallationQuality.Value) {
179            front.RemoveAt(i);
180            j = i + 1;
181          }
182        }
183      }
184
185      archive.Solutions = front;
186
187      return base.Apply();
188    }
189  }
190}
Note: See TracBrowser for help on using the repository browser.