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 |
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 |
|
---|
31 | namespace 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 IValueLookupParameter<ResultCollection> ResultsParameter {
|
---|
99 | get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
100 | }
|
---|
101 |
|
---|
102 | [StorableConstructor]
|
---|
103 | private GQAPSolutionArchiveAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
104 | private GQAPSolutionArchiveAnalyzer(GQAPSolutionArchiveAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
105 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
106 | return new GQAPSolutionArchiveAnalyzer(this, cloner);
|
---|
107 | }
|
---|
108 | public GQAPSolutionArchiveAnalyzer()
|
---|
109 | : base() {
|
---|
110 | Parameters.Add(new LookupParameter<BoolValue>("Maximization", GeneralizedQuadraticAssignmentProblem.MaximizationDescription));
|
---|
111 | Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", GeneralizedQuadraticAssignmentProblem.DistancesDescription));
|
---|
112 | Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", GeneralizedQuadraticAssignmentProblem.WeightsDescription));
|
---|
113 | Parameters.Add(new LookupParameter<DoubleMatrix>("InstallationCosts", GeneralizedQuadraticAssignmentProblem.InstallationCostsDescription));
|
---|
114 | Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription));
|
---|
115 | Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription));
|
---|
116 | Parameters.Add(new ValueLookupParameter<DoubleValue>("TransportationCosts", GeneralizedQuadraticAssignmentProblem.TransportationCostsDescription));
|
---|
117 | Parameters.Add(new ValueLookupParameter<DoubleValue>("OverbookedCapacityPenalty", GeneralizedQuadraticAssignmentProblem.OverbookedCapacityPenaltyDescription));
|
---|
118 | Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Assignment", GQAPSolutionCreator.AssignmentDescription));
|
---|
119 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", GQAPEvaluator.QualityDescription));
|
---|
120 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription));
|
---|
121 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription));
|
---|
122 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription));
|
---|
123 | Parameters.Add(new LookupParameter<StringArray>("EquipmentNames", GeneralizedQuadraticAssignmentProblem.EquipmentNamesDescription));
|
---|
124 | Parameters.Add(new LookupParameter<StringArray>("LocationNames", GeneralizedQuadraticAssignmentProblem.LocationNamesDescription));
|
---|
125 | Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", GeneralizedQuadraticAssignmentProblem.BestKnownQualityDescription));
|
---|
126 | Parameters.Add(new LookupParameter<IntegerVector>("BestKnownSolution", GeneralizedQuadraticAssignmentProblem.BestKnownSolutionDescription));
|
---|
127 | Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best GQAP solution should be stored."));
|
---|
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;
|
---|
181 | }
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | archive.Solutions = front;
|
---|
186 |
|
---|
187 | return base.Apply();
|
---|
188 | }
|
---|
189 | }
|
---|
190 | }
|
---|