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 System;
|
---|
23 | using System.Drawing;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
29 | using HeuristicLab.Optimization;
|
---|
30 | using HeuristicLab.Parameters;
|
---|
31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
32 | using HeuristicLab.PluginInfrastructure;
|
---|
33 | using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common;
|
---|
34 | using HeuristicLab.Problems.Instances;
|
---|
35 |
|
---|
36 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment {
|
---|
37 | [Item("Generalized Quadratic Assignment Problem", "The Generalized Quadratic Assignment Problem (GQAP) is a generalization of the QAP in that it allows to assign multiple facilities (here called equipment) to a single location. The problem is described in Lee, C.G., and Ma, Z. 2003. The Generalized Quadratic Assignment Problem. Technical Report M5S 3G8, University of Toronto, Canada.")]
|
---|
38 | [Creatable("Problems")]
|
---|
39 | [StorableClass]
|
---|
40 | public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IGQAPSolutionCreator>, IStorableContent, IProblemInstanceConsumer<IQAPInstance>, IProblemInstanceConsumer<ICTAPInstance>, IProblemInstanceConsumer<ITSPInstance>, IProblemInstanceConsumer<IATSPInstance> {
|
---|
41 |
|
---|
42 | public override Image ItemImage {
|
---|
43 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public string Filename { get; set; }
|
---|
47 |
|
---|
48 | #region Parameter Descriptions
|
---|
49 | public static readonly string MaximizationDescription = "False if the fitness function should be minimized (default) or otherwise True if it should be maximized.";
|
---|
50 | public static readonly string WeightsDescription = "The weights matrix describes the flows between the equipments.";
|
---|
51 | public static readonly string DistancesDescription = "The distances matrix describes the distances between the locations at which the equipment can be installed.";
|
---|
52 | public static readonly string InstallationCostsDescription = "The installation costs matrix describes the installation costs of installing equipment i at location j";
|
---|
53 | public static readonly string DemandsDescription = "The demands vector describes the space requirements of the equipments.";
|
---|
54 | public static readonly string CapacitiesDescription = "The capacities vector describes the available space at the locations.";
|
---|
55 | public static readonly string TransportationCostsDescription = "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.";
|
---|
56 | public static readonly string OverbookedCapacityPenaltyDescription = "The multiplier for the constraint violation when added to the quality.";
|
---|
57 | public static readonly string BestKnownQualityDescription = "The best known quality (if available).";
|
---|
58 | public static readonly string BestKnownSolutionDescription = "The best known solution (if available).";
|
---|
59 | public static readonly string BestKnownSolutionsDescription = "Contains an archive of best-known solutions regarding flow-distance quality and installation quality.";
|
---|
60 | public static readonly string EquipmentNamesDescription = "Optional: A list of names that describes the equipments.";
|
---|
61 | public static readonly string LocationNamesDescription = "Optional: A list of names that describes the locations.";
|
---|
62 | #endregion
|
---|
63 |
|
---|
64 | #region Parameter Properties
|
---|
65 | public ValueParameter<DoubleMatrix> WeightsParameter {
|
---|
66 | get { return (ValueParameter<DoubleMatrix>)Parameters["Weights"]; }
|
---|
67 | }
|
---|
68 | public ValueParameter<DoubleMatrix> DistancesParameter {
|
---|
69 | get { return (ValueParameter<DoubleMatrix>)Parameters["Distances"]; }
|
---|
70 | }
|
---|
71 | public ValueParameter<DoubleMatrix> InstallationCostsParameter {
|
---|
72 | get { return (ValueParameter<DoubleMatrix>)Parameters["InstallationCosts"]; }
|
---|
73 | }
|
---|
74 | public ValueParameter<DoubleArray> DemandsParameter {
|
---|
75 | get { return (ValueParameter<DoubleArray>)Parameters["Demands"]; }
|
---|
76 | }
|
---|
77 | public ValueParameter<DoubleArray> CapacitiesParameter {
|
---|
78 | get { return (ValueParameter<DoubleArray>)Parameters["Capacities"]; }
|
---|
79 | }
|
---|
80 | public FixedValueParameter<DoubleValue> TransportationCostsParameter {
|
---|
81 | get { return (FixedValueParameter<DoubleValue>)Parameters["TransportationCosts"]; }
|
---|
82 | }
|
---|
83 | public FixedValueParameter<DoubleValue> OverbookedCapacityPenaltyParameter {
|
---|
84 | get { return (FixedValueParameter<DoubleValue>)Parameters["OverbookedCapacityPenalty"]; }
|
---|
85 | }
|
---|
86 | public OptionalValueParameter<GQAPAssignment> BestKnownSolutionParameter {
|
---|
87 | get { return (OptionalValueParameter<GQAPAssignment>)Parameters["BestKnownSolution"]; }
|
---|
88 | }
|
---|
89 | public OptionalValueParameter<GQAPAssignmentArchive> BestKnownSolutionsParameter {
|
---|
90 | get { return (OptionalValueParameter<GQAPAssignmentArchive>)Parameters["BestKnownSolutions"]; }
|
---|
91 | }
|
---|
92 | public OptionalValueParameter<StringArray> EquipmentNamesParameter {
|
---|
93 | get { return (OptionalValueParameter<StringArray>)Parameters["EquipmentNames"]; }
|
---|
94 | }
|
---|
95 | public OptionalValueParameter<StringArray> LocationNamesParameter {
|
---|
96 | get { return (OptionalValueParameter<StringArray>)Parameters["LocationNames"]; }
|
---|
97 | }
|
---|
98 | #endregion
|
---|
99 |
|
---|
100 | #region Properties
|
---|
101 | public DoubleMatrix Weights {
|
---|
102 | get { return WeightsParameter.Value; }
|
---|
103 | set { WeightsParameter.Value = value; }
|
---|
104 | }
|
---|
105 | public DoubleMatrix Distances {
|
---|
106 | get { return DistancesParameter.Value; }
|
---|
107 | set { DistancesParameter.Value = value; }
|
---|
108 | }
|
---|
109 | public DoubleMatrix InstallationCosts {
|
---|
110 | get { return InstallationCostsParameter.Value; }
|
---|
111 | set { InstallationCostsParameter.Value = value; }
|
---|
112 | }
|
---|
113 | public DoubleArray Demands {
|
---|
114 | get { return DemandsParameter.Value; }
|
---|
115 | set { DemandsParameter.Value = value; }
|
---|
116 | }
|
---|
117 | public DoubleArray Capacities {
|
---|
118 | get { return CapacitiesParameter.Value; }
|
---|
119 | set { CapacitiesParameter.Value = value; }
|
---|
120 | }
|
---|
121 | public DoubleValue TransportationCosts {
|
---|
122 | get { return TransportationCostsParameter.Value; }
|
---|
123 | set { TransportationCostsParameter.Value = value; }
|
---|
124 | }
|
---|
125 | public DoubleValue OverbookedCapacityPenalty {
|
---|
126 | get { return TransportationCostsParameter.Value; }
|
---|
127 | set { TransportationCostsParameter.Value = value; }
|
---|
128 | }
|
---|
129 | public StringArray EquipmentNames {
|
---|
130 | get { return EquipmentNamesParameter.Value; }
|
---|
131 | set { EquipmentNamesParameter.Value = value; }
|
---|
132 | }
|
---|
133 | public StringArray LocationNames {
|
---|
134 | get { return LocationNamesParameter.Value; }
|
---|
135 | set { LocationNamesParameter.Value = value; }
|
---|
136 | }
|
---|
137 | public GQAPAssignment BestKnownSolution {
|
---|
138 | get { return BestKnownSolutionParameter.Value; }
|
---|
139 | set { BestKnownSolutionParameter.Value = value; }
|
---|
140 | }
|
---|
141 | public GQAPAssignmentArchive BestKnownSolutions {
|
---|
142 | get { return BestKnownSolutionsParameter.Value; }
|
---|
143 | set { BestKnownSolutionsParameter.Value = value; }
|
---|
144 | }
|
---|
145 | #endregion
|
---|
146 |
|
---|
147 | public BestGQAPSolutionAnalyzer BestSolutionAnalyzer {
|
---|
148 | get { return Operators.OfType<BestGQAPSolutionAnalyzer>().FirstOrDefault(); }
|
---|
149 | }
|
---|
150 | public GQAPSolutionArchiveAnalyzer SolutionArchiveAnalyzer {
|
---|
151 | get { return Operators.OfType<GQAPSolutionArchiveAnalyzer>().FirstOrDefault(); }
|
---|
152 | }
|
---|
153 |
|
---|
154 | [StorableConstructor]
|
---|
155 | private GeneralizedQuadraticAssignmentProblem(bool deserializing) : base(deserializing) { }
|
---|
156 | private GeneralizedQuadraticAssignmentProblem(GeneralizedQuadraticAssignmentProblem original, Cloner cloner)
|
---|
157 | : base(original, cloner) {
|
---|
158 | RegisterEventHandlers();
|
---|
159 | }
|
---|
160 | public GeneralizedQuadraticAssignmentProblem()
|
---|
161 | : base(new GQAPEvaluator(), new RandomSolutionCreator()) {
|
---|
162 | Parameters.Add(new ValueParameter<DoubleMatrix>("Weights", WeightsDescription, new DoubleMatrix(), false));
|
---|
163 | Parameters.Add(new ValueParameter<DoubleMatrix>("Distances", DistancesDescription, new DoubleMatrix(), false));
|
---|
164 | Parameters.Add(new ValueParameter<DoubleMatrix>("InstallationCosts", InstallationCostsDescription, new DoubleMatrix(), false));
|
---|
165 | Parameters.Add(new FixedValueParameter<DoubleValue>("TransportationCosts", TransportationCostsDescription, new DoubleValue(1)));
|
---|
166 | Parameters.Add(new FixedValueParameter<DoubleValue>("OverbookedCapacityPenalty", OverbookedCapacityPenaltyDescription, new DoubleValue(1000)));
|
---|
167 | Parameters.Add(new ValueParameter<DoubleArray>("Demands", DemandsDescription, new DoubleArray(), false));
|
---|
168 | Parameters.Add(new ValueParameter<DoubleArray>("Capacities", CapacitiesDescription, new DoubleArray(), false));
|
---|
169 | Parameters.Add(new OptionalValueParameter<GQAPSolution>("BestKnownSolution", BestKnownSolutionDescription, null, false));
|
---|
170 | Parameters.Add(new OptionalValueParameter<GQAPAssignmentArchive>("BestKnownSolutions", BestKnownSolutionsDescription, null, false));
|
---|
171 | Parameters.Add(new OptionalValueParameter<StringArray>("EquipmentNames", EquipmentNamesDescription, null, false));
|
---|
172 | Parameters.Add(new OptionalValueParameter<StringArray>("LocationNames", LocationNamesDescription, null, false));
|
---|
173 |
|
---|
174 | WeightsParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
|
---|
175 | DistancesParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
|
---|
176 | InstallationCostsParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
|
---|
177 |
|
---|
178 | Weights = new DoubleMatrix(5, 5);
|
---|
179 | Weights[0, 0] = Weights[1, 1] = Weights[2, 2] = Weights[3, 3] = Weights[4, 4] = 0;
|
---|
180 | Weights[0, 1] = Weights[1, 0] = Weights[0, 2] = Weights[2, 0] = Weights[0, 3] = Weights[3, 0] = Weights[0, 4] = Weights[4, 0] = 10;
|
---|
181 | Weights[1, 2] = Weights[2, 1] = Weights[1, 3] = Weights[3, 1] = Weights[1, 4] = Weights[4, 1] = 5;
|
---|
182 | Weights[2, 3] = Weights[3, 2] = Weights[2, 4] = Weights[4, 2] = 7.5;
|
---|
183 | Weights[3, 4] = Weights[4, 3] = 2.5;
|
---|
184 |
|
---|
185 | Distances = new DoubleMatrix(3, 3);
|
---|
186 | Distances[0, 0] = Distances[1, 1] = Distances[2, 2] = 0;
|
---|
187 | Distances[0, 1] = Distances[1, 0] = Distances[1, 2] = Distances[2, 1] = 1;
|
---|
188 | Distances[0, 2] = Distances[2, 0] = 2;
|
---|
189 |
|
---|
190 | InstallationCosts = new DoubleMatrix(5, 3);
|
---|
191 |
|
---|
192 | Demands = new DoubleArray(5);
|
---|
193 | Demands[0] = 2; Demands[1] = 1; Demands[2] = 3; Demands[3] = 1; Demands[4] = 1;
|
---|
194 |
|
---|
195 | Capacities = new DoubleArray(3);
|
---|
196 | Capacities[0] = 4; Capacities[1] = 1; Capacities[2] = 4;
|
---|
197 |
|
---|
198 | SolutionCreator.AssignmentParameter.ActualName = "Assignment";
|
---|
199 |
|
---|
200 | InitializeOperators();
|
---|
201 | RegisterEventHandlers();
|
---|
202 | }
|
---|
203 |
|
---|
204 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
205 | return new GeneralizedQuadraticAssignmentProblem(this, cloner);
|
---|
206 | }
|
---|
207 |
|
---|
208 | public bool LoadFrom(IQAPInstance instance) {
|
---|
209 | try {
|
---|
210 | Name = instance.Name;
|
---|
211 | Description = instance.Description;
|
---|
212 |
|
---|
213 | Weights = new DoubleMatrix(instance.Weights);
|
---|
214 | Distances = new DoubleMatrix(instance.Distances);
|
---|
215 | InstallationCosts = new DoubleMatrix(Weights.Rows, Distances.Columns); // all zero
|
---|
216 | Capacities = new DoubleArray(Enumerable.Range(0, Distances.Rows).Select(x => 1.0).ToArray());
|
---|
217 | Demands = new DoubleArray(Enumerable.Range(0, Weights.Rows).Select(x => 1.0).ToArray());
|
---|
218 |
|
---|
219 | TransportationCosts.Value = 1;
|
---|
220 |
|
---|
221 | if (instance.BestKnownAssignment != null) {
|
---|
222 | EvaluateAndLoadAssignment(instance.BestKnownAssignment);
|
---|
223 | } else {
|
---|
224 | BestKnownQuality = null;
|
---|
225 | BestKnownSolution = null;
|
---|
226 | BestKnownSolutions = null;
|
---|
227 | }
|
---|
228 | } catch {
|
---|
229 | return false;
|
---|
230 | }
|
---|
231 | return true;
|
---|
232 | }
|
---|
233 |
|
---|
234 | public bool LoadFrom(ICTAPInstance instance) {
|
---|
235 | try {
|
---|
236 | Name = instance.Name;
|
---|
237 | Description = instance.Description;
|
---|
238 |
|
---|
239 | Capacities = new DoubleArray(instance.MemoryCapacities);
|
---|
240 | Demands = new DoubleArray(instance.MemoryRequirements);
|
---|
241 | Weights = new DoubleMatrix(instance.CommunicationCosts);
|
---|
242 | InstallationCosts = new DoubleMatrix(instance.ExecutionCosts.Transpose());
|
---|
243 | Distances = new DoubleMatrix(Capacities.Length, Capacities.Length); // all one, except diagonal
|
---|
244 | for (int i = 0; i < Capacities.Length - 1; i++)
|
---|
245 | for (int j = i + 1; j < Capacities.Length; j++) {
|
---|
246 | Distances[i, j] = 1;
|
---|
247 | Distances[j, i] = 1;
|
---|
248 | }
|
---|
249 |
|
---|
250 | TransportationCosts.Value = 1;
|
---|
251 |
|
---|
252 | if (instance.BestKnownAssignment != null) {
|
---|
253 | EvaluateAndLoadAssignment(instance.BestKnownAssignment);
|
---|
254 | } else {
|
---|
255 | BestKnownQuality = null;
|
---|
256 | BestKnownSolution = null;
|
---|
257 | BestKnownSolutions = null;
|
---|
258 | }
|
---|
259 | } catch {
|
---|
260 | return false;
|
---|
261 | }
|
---|
262 | return true;
|
---|
263 | }
|
---|
264 |
|
---|
265 | public bool LoadFrom(ITSPInstance instance) {
|
---|
266 | try {
|
---|
267 | if (instance.Dimension > 1000) return false;
|
---|
268 |
|
---|
269 | Name = instance.Name;
|
---|
270 | Description = instance.Description;
|
---|
271 |
|
---|
272 | Capacities = new DoubleArray(instance.Dimension);
|
---|
273 | Demands = new DoubleArray(instance.Dimension);
|
---|
274 | for (int i = 0; i < instance.Dimension; i++) {
|
---|
275 | Capacities[i] = 1;
|
---|
276 | Demands[i] = 1;
|
---|
277 | }
|
---|
278 | InstallationCosts = new DoubleMatrix(instance.Dimension, instance.Dimension);
|
---|
279 | Weights = new DoubleMatrix(instance.Dimension, instance.Dimension);
|
---|
280 | for (int i = 0; i < instance.Dimension; i++)
|
---|
281 | Weights[i, (i + 1) % instance.Dimension] = 1;
|
---|
282 | Distances = new DoubleMatrix(instance.GetDistanceMatrix());
|
---|
283 |
|
---|
284 | TransportationCosts.Value = 1;
|
---|
285 |
|
---|
286 | if (instance.BestKnownTour != null) {
|
---|
287 | EvaluateAndLoadAssignment(instance.BestKnownTour);
|
---|
288 | } else {
|
---|
289 | BestKnownQuality = null;
|
---|
290 | BestKnownSolution = null;
|
---|
291 | BestKnownSolutions = null;
|
---|
292 | }
|
---|
293 | } catch {
|
---|
294 | return false;
|
---|
295 | }
|
---|
296 | return true;
|
---|
297 | }
|
---|
298 |
|
---|
299 | public bool LoadFrom(IATSPInstance instance) {
|
---|
300 | try {
|
---|
301 | Name = instance.Name;
|
---|
302 | Description = instance.Description;
|
---|
303 |
|
---|
304 | Capacities = new DoubleArray(instance.Dimension);
|
---|
305 | Demands = new DoubleArray(instance.Dimension);
|
---|
306 | for (int i = 0; i < instance.Dimension; i++) {
|
---|
307 | Capacities[i] = 1;
|
---|
308 | Demands[i] = 1;
|
---|
309 | }
|
---|
310 | InstallationCosts = new DoubleMatrix(instance.Dimension, instance.Dimension);
|
---|
311 | Weights = new DoubleMatrix(instance.Dimension, instance.Dimension);
|
---|
312 | for (int i = 0; i < instance.Dimension; i++)
|
---|
313 | Weights[i, (i + 1) % instance.Dimension] = 1;
|
---|
314 | Distances = new DoubleMatrix(instance.Distances);
|
---|
315 |
|
---|
316 | TransportationCosts.Value = 1;
|
---|
317 |
|
---|
318 | if (instance.BestKnownTour != null) {
|
---|
319 | EvaluateAndLoadAssignment(instance.BestKnownTour);
|
---|
320 | } else {
|
---|
321 | BestKnownQuality = null;
|
---|
322 | BestKnownSolution = null;
|
---|
323 | BestKnownSolutions = null;
|
---|
324 | }
|
---|
325 | } catch {
|
---|
326 | return false;
|
---|
327 | }
|
---|
328 | return true;
|
---|
329 | }
|
---|
330 |
|
---|
331 | private void EvaluateAndLoadAssignment(int[] vector) {
|
---|
332 | var assignment = new IntegerVector(vector);
|
---|
333 | double flowDistanceQuality, installationQuality, overbookedCapacity;
|
---|
334 | GQAPEvaluator.Evaluate(assignment, Weights, Distances, InstallationCosts, Demands, Capacities,
|
---|
335 | out flowDistanceQuality, out installationQuality, out overbookedCapacity);
|
---|
336 | double quality = GQAPEvaluator.GetCombinedQuality(flowDistanceQuality, installationQuality, overbookedCapacity, TransportationCosts.Value, OverbookedCapacityPenalty.Value);
|
---|
337 | BestKnownSolution = new GQAPAssignment(assignment, new DoubleValue(quality),
|
---|
338 | new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality),
|
---|
339 | new DoubleValue(overbookedCapacity), EquipmentNames, LocationNames, Distances, Weights, InstallationCosts,
|
---|
340 | Demands, Capacities, TransportationCosts, OverbookedCapacityPenalty);
|
---|
341 | BestKnownQuality = new DoubleValue(quality);
|
---|
342 | BestKnownSolutions = new GQAPAssignmentArchive(EquipmentNames, LocationNames, Distances, Weights, InstallationCosts, Demands, Capacities, TransportationCosts, OverbookedCapacityPenalty);
|
---|
343 | BestKnownSolutions.Solutions.Add(BestKnownSolution);
|
---|
344 | }
|
---|
345 |
|
---|
346 | #region Events
|
---|
347 | protected override void OnOperatorsChanged() {
|
---|
348 | base.OnOperatorsChanged();
|
---|
349 | Parameterize();
|
---|
350 | }
|
---|
351 | protected override void OnEvaluatorChanged() {
|
---|
352 | base.OnEvaluatorChanged();
|
---|
353 | Parameterize();
|
---|
354 | Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
355 | }
|
---|
356 | protected override void OnSolutionCreatorChanged() {
|
---|
357 | base.OnSolutionCreatorChanged();
|
---|
358 | Parameterize();
|
---|
359 | SolutionCreator.AssignmentParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
|
---|
360 | }
|
---|
361 |
|
---|
362 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
363 | Parameterize();
|
---|
364 | }
|
---|
365 | private void SolutionCreator_IntegerVectorParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
366 | Parameterize();
|
---|
367 | }
|
---|
368 | #endregion
|
---|
369 |
|
---|
370 | #region Helpers
|
---|
371 | [StorableHook(HookType.AfterDeserialization)]
|
---|
372 | private void AfterDeserialization() {
|
---|
373 | RegisterEventHandlers();
|
---|
374 | }
|
---|
375 |
|
---|
376 | private void RegisterEventHandlers() {
|
---|
377 | Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
378 | SolutionCreator.AssignmentParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
|
---|
379 | }
|
---|
380 |
|
---|
381 | private void InitializeOperators() {
|
---|
382 | Operators.Clear();
|
---|
383 | Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPOperator>());
|
---|
384 | Operators.AddRange(ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>());
|
---|
385 | Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator);
|
---|
386 | Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPMoveEvaluator>());
|
---|
387 | Parameterize();
|
---|
388 | }
|
---|
389 |
|
---|
390 | private void Parameterize() {
|
---|
391 |
|
---|
392 | var operators = Operators.Union(new IOperator[] { SolutionCreator, Evaluator }).ToArray();
|
---|
393 |
|
---|
394 | foreach (var op in operators.OfType<IAssignmentAwareGQAPOperator>()) {
|
---|
395 | op.AssignmentParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
396 | }
|
---|
397 | foreach (var op in operators.OfType<IAssignmentsAwareGQAPOperator>()) {
|
---|
398 | op.AssignmentParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
399 | }
|
---|
400 | foreach (var op in operators.OfType<IBestKnownQualityAwareGQAPOperator>()) {
|
---|
401 | op.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
|
---|
402 | }
|
---|
403 | foreach (var op in operators.OfType<IBestKnownSolutionAwareGQAPOperator>()) {
|
---|
404 | op.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
|
---|
405 | }
|
---|
406 | foreach (var op in operators.OfType<IBestKnownSolutionsAwareGQAPOperator>()) {
|
---|
407 | op.BestKnownSolutionsParameter.ActualName = BestKnownSolutionsParameter.Name;
|
---|
408 | }
|
---|
409 | foreach (var op in operators.OfType<ICapacitiesAwareGQAPOperator>()) {
|
---|
410 | op.CapacitiesParameter.ActualName = CapacitiesParameter.Name;
|
---|
411 | }
|
---|
412 | foreach (var op in operators.OfType<IDemandsAwareGQAPOperator>()) {
|
---|
413 | op.DemandsParameter.ActualName = DemandsParameter.Name;
|
---|
414 | }
|
---|
415 | foreach (var op in operators.OfType<IDistancesAwareGQAPOperator>()) {
|
---|
416 | op.DistancesParameter.ActualName = DistancesParameter.Name;
|
---|
417 | }
|
---|
418 | foreach (var op in operators.OfType<IEquipmentNamesAwareGQAPOperator>()) {
|
---|
419 | op.EquipmentNamesParameter.ActualName = EquipmentNamesParameter.Name;
|
---|
420 | }
|
---|
421 | foreach (var op in operators.OfType<IGQAPCrossover>()) {
|
---|
422 | op.ParentsParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
423 | op.ChildParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
424 | }
|
---|
425 | foreach (var op in operators.OfType<IInstallationCostsAwareGQAPOperator>()) {
|
---|
426 | op.InstallationCostsParameter.ActualName = InstallationCostsParameter.Name;
|
---|
427 | }
|
---|
428 | foreach (var op in operators.OfType<ILocationNamesAwareGQAPOperator>()) {
|
---|
429 | op.LocationNamesParameter.ActualName = LocationNamesParameter.Name;
|
---|
430 | }
|
---|
431 | var moveEvaluator = operators.OfType<IGQAPMoveEvaluator>().FirstOrDefault();
|
---|
432 | foreach (var op in operators.OfType<IGQAPMoveEvaluator>()) { // synchronize all move evaluators
|
---|
433 | if (moveEvaluator != null) {
|
---|
434 | op.MoveQualityParameter.ActualName = moveEvaluator.MoveQualityParameter.ActualName;
|
---|
435 | op.MoveFlowDistanceQualityParameter.ActualName = moveEvaluator.MoveFlowDistanceQualityParameter.ActualName;
|
---|
436 | op.MoveInstallationQualityParameter.ActualName = moveEvaluator.MoveInstallationQualityParameter.ActualName;
|
---|
437 | op.MoveOverbookedCapacityParameter.ActualName = moveEvaluator.MoveOverbookedCapacityParameter.ActualName;
|
---|
438 | }
|
---|
439 | }
|
---|
440 | foreach (var op in operators.OfType<IMoveQualityAwareGQAPOperator>()) {
|
---|
441 | if (moveEvaluator != null) {
|
---|
442 | op.MoveQualityParameter.ActualName = moveEvaluator.MoveQualityParameter.ActualName;
|
---|
443 | op.MoveFlowDistanceQualityParameter.ActualName = moveEvaluator.MoveFlowDistanceQualityParameter.ActualName;
|
---|
444 | op.MoveInstallationQualityParameter.ActualName = moveEvaluator.MoveInstallationQualityParameter.ActualName;
|
---|
445 | op.MoveOverbookedCapacityParameter.ActualName = moveEvaluator.MoveOverbookedCapacityParameter.ActualName;
|
---|
446 | }
|
---|
447 | op.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
448 | }
|
---|
449 | foreach (var op in operators.OfType<IOverbookedCapacityPenaltyAwareGQAPOperator>()) {
|
---|
450 | op.OverbookedCapacityPenaltyParameter.ActualName = OverbookedCapacityPenaltyParameter.Name;
|
---|
451 | }
|
---|
452 | foreach (var op in operators.OfType<IQualitiesAwareGQAPOperator>()) {
|
---|
453 | op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
454 | op.FlowDistanceQualityParameter.ActualName = Evaluator.FlowDistanceQualityParameter.ActualName;
|
---|
455 | op.InstallationQualityParameter.ActualName = Evaluator.InstallationQualityParameter.ActualName;
|
---|
456 | op.OverbookedCapacityParameter.ActualName = Evaluator.OverbookedCapacityParameter.ActualName;
|
---|
457 | op.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
458 | }
|
---|
459 | foreach (var op in operators.OfType<IQualityAwareGQAPOperator>()) {
|
---|
460 | op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
461 | op.FlowDistanceQualityParameter.ActualName = Evaluator.FlowDistanceQualityParameter.ActualName;
|
---|
462 | op.InstallationQualityParameter.ActualName = Evaluator.InstallationQualityParameter.ActualName;
|
---|
463 | op.OverbookedCapacityParameter.ActualName = Evaluator.OverbookedCapacityParameter.ActualName;
|
---|
464 | op.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
465 | }
|
---|
466 | foreach (var op in operators.OfType<ITransportationCostsAwareGQAPOperator>()) {
|
---|
467 | op.TransportationCostsParameter.ActualName = TransportationCostsParameter.Name;
|
---|
468 | }
|
---|
469 | foreach (var op in operators.OfType<IWeightsAwareGQAPOperator>()) {
|
---|
470 | op.WeightsParameter.ActualName = WeightsParameter.Name;
|
---|
471 | }
|
---|
472 |
|
---|
473 | foreach (var op in operators.OfType<IIntegerVectorCrossover>()) {
|
---|
474 | op.ParentsParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
475 | op.ChildParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
476 | }
|
---|
477 | foreach (var op in operators.OfType<IIntegerVectorManipulator>()) {
|
---|
478 | op.IntegerVectorParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
479 | }
|
---|
480 | }
|
---|
481 | #endregion
|
---|
482 | }
|
---|
483 | }
|
---|