Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GeneralizedQuadraticAssignmentProblem.cs @ 7548

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

#1614: changed according to architects review

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