Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1614

  • fixed build
File size: 9.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    IAnalyzer {
43
44    public bool EnabledByDefault {
45      get { return false; }
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
97    [StorableConstructor]
98    private GQAPSolutionArchiveAnalyzer(bool deserializing) : base(deserializing) { }
99    private GQAPSolutionArchiveAnalyzer(GQAPSolutionArchiveAnalyzer original, Cloner cloner) : base(original, cloner) { }
100    public override IDeepCloneable Clone(Cloner cloner) {
101      return new GQAPSolutionArchiveAnalyzer(this, cloner);
102    }
103    public GQAPSolutionArchiveAnalyzer()
104      : base() {
105      Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription));
106      Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription));
107      Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription));
108      Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription));
109      Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
110      Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
111      Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription));
112      Parameters.Add(new ValueLookupParameter<DoubleValue>("OverbookedCapacityPenalty", GeneralizedQuadraticAssignmentProblem.OverbookedCapacityPenaltyDescription));
113      Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
114      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription));
115      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription));
116      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription));
117      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription));
118      Parameters.Add(new LookupParameter<StringArray>("EquipmentNames", GeneralizedQuadraticAssignmentProblem.EquipmentNamesDescription));
119      Parameters.Add(new LookupParameter<StringArray>("LocationNames", GeneralizedQuadraticAssignmentProblem.LocationNamesDescription));
120      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best GQAP solution should be stored."));
121    }
122
123    public override IOperation Apply() {
124      var assignments = AssignmentParameter.ActualValue;
125      var qualities = QualityParameter.ActualValue;
126      var equipmentNames = EquipmentNamesParameter.ActualValue;
127      var locationNames = LocationNamesParameter.ActualValue;
128      var flowDistanceQualities = FlowDistanceQualityParameter.ActualValue;
129      var installationQualities = InstallationQualityParameter.ActualValue;
130      var overbookedCapacities = OverbookedCapacityParameter.ActualValue;
131      var distances = DistancesParameter.ActualValue;
132      var weights = WeightsParameter.ActualValue;
133      var installationCosts = InstallationCostsParameter.ActualValue;
134      var demands = DemandsParameter.ActualValue;
135      var capacities = CapacitiesParameter.ActualValue;
136      var transportationCosts = TransportationCostsParameter.ActualValue;
137      var overbookedCapacityPenalty = OverbookedCapacityPenaltyParameter.ActualValue;
138      var results = ResultsParameter.ActualValue;
139      var maximization = MaximizationParameter.ActualValue.Value;
140
141      GQAPAssignmentArchive archive = results.ContainsKey("Solution Archive") ? results["Solution Archive"].Value as GQAPAssignmentArchive : null;
142      if (archive == null) {
143        archive = new GQAPAssignmentArchive(equipmentNames, locationNames, distances, weights, installationCosts, demands, capacities, transportationCosts, overbookedCapacityPenalty);
144        results.Add(new Result("Solution Archive", archive));
145      } else {
146        archive.EquipmentNames = equipmentNames;
147        archive.LocationNames = locationNames;
148        archive.Distances = distances;
149        archive.Weights = weights;
150        archive.InstallationCosts = installationCosts;
151        archive.Demands = demands;
152        archive.Capacities = capacities;
153        archive.TransportationCosts = transportationCosts;
154        archive.OverbookedCapacityPenalty = overbookedCapacityPenalty;
155      }
156
157      var solutions = Enumerable.Range(0, assignments.Length)
158        .Select(i => new GQAPSolution(assignments[i], qualities[i], flowDistanceQualities[i], installationQualities[i], overbookedCapacities[i]))
159        .Concat(archive.Solutions);
160      archive.Solutions = GQAPSolutionArchiveUpdater.GetFeasibleParetoFront(solutions);
161
162      return base.Apply();
163    }
164  }
165}
Note: See TracBrowser for help on using the repository browser.