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

Last change on this file since 7523 was 7523, checked in by abeham, 8 years ago

#1614

  • sorted operators
  • added crossover defined by Cordeau et al.
  • fixed a few bugs
File size: 26.3 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<IQAPInstance>,
42    IProblemInstanceConsumer<ICTAPInstance>,
43    IProblemInstanceConsumer<ITSPInstance>,
44    IProblemInstanceConsumer<IATSPInstance>,
45    IProblemInstanceConsumer<IGQAPInstance> {
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(1000)));
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 Consumptions
216    public bool LoadFrom(IQAPInstance instance) {
217      try {
218        Name = instance.Name;
219        Description = instance.Description;
220
221        Weights = new DoubleMatrix(instance.Weights);
222        Distances = new DoubleMatrix(instance.Distances);
223        InstallationCosts = new DoubleMatrix(Weights.Rows, Distances.Columns); // all zero
224        Capacities = new DoubleArray(Enumerable.Range(0, Distances.Rows).Select(x => 1.0).ToArray());
225        Demands = new DoubleArray(Enumerable.Range(0, Weights.Rows).Select(x => 1.0).ToArray());
226
227        TransportationCosts.Value = 1;
228
229        if (instance.BestKnownAssignment != null) {
230          EvaluateAndLoadAssignment(instance.BestKnownAssignment);
231        } else {
232          BestKnownQuality = null;
233          BestKnownSolution = null;
234          BestKnownSolutions = null;
235        }
236      } catch {
237        return false;
238      }
239      return true;
240    }
241
242    public bool LoadFrom(ICTAPInstance instance) {
243      try {
244        Name = instance.Name;
245        Description = instance.Description;
246
247        Capacities = new DoubleArray(instance.MemoryCapacities);
248        Demands = new DoubleArray(instance.MemoryRequirements);
249        Weights = new DoubleMatrix(instance.CommunicationCosts);
250        InstallationCosts = new DoubleMatrix(instance.ExecutionCosts.Transpose());
251        Distances = new DoubleMatrix(Capacities.Length, Capacities.Length);
252        for (int i = 0; i < Capacities.Length - 1; i++)
253          for (int j = i + 1; j < Capacities.Length; j++) {
254            Distances[i, j] = 1;
255          }
256
257        TransportationCosts.Value = 1;
258
259        if (instance.BestKnownAssignment != null) {
260          EvaluateAndLoadAssignment(instance.BestKnownAssignment);
261        } else {
262          BestKnownQuality = null;
263          BestKnownSolution = null;
264          BestKnownSolutions = null;
265        }
266      } catch {
267        return false;
268      }
269      return true;
270    }
271
272    public bool LoadFrom(ITSPInstance instance) {
273      try {
274        if (instance.Dimension > 1000) return false;
275
276        Name = instance.Name;
277        Description = instance.Description;
278
279        Capacities = new DoubleArray(instance.Dimension);
280        Demands = new DoubleArray(instance.Dimension);
281        for (int i = 0; i < instance.Dimension; i++) {
282          Capacities[i] = 1;
283          Demands[i] = 1;
284        }
285        InstallationCosts = new DoubleMatrix(instance.Dimension, instance.Dimension);
286        Weights = new DoubleMatrix(instance.Dimension, instance.Dimension);
287        for (int i = 0; i < instance.Dimension; i++)
288          Weights[i, (i + 1) % instance.Dimension] = 1;
289        Distances = new DoubleMatrix(instance.GetDistanceMatrix());
290
291        TransportationCosts.Value = 1;
292
293        if (instance.BestKnownTour != null) {
294          EvaluateAndLoadAssignment(instance.BestKnownTour);
295        } else {
296          BestKnownQuality = null;
297          BestKnownSolution = null;
298          BestKnownSolutions = null;
299        }
300      } catch {
301        return false;
302      }
303      return true;
304    }
305
306    public bool LoadFrom(IATSPInstance instance) {
307      try {
308        Name = instance.Name;
309        Description = instance.Description;
310
311        Capacities = new DoubleArray(instance.Dimension);
312        Demands = new DoubleArray(instance.Dimension);
313        for (int i = 0; i < instance.Dimension; i++) {
314          Capacities[i] = 1;
315          Demands[i] = 1;
316        }
317        InstallationCosts = new DoubleMatrix(instance.Dimension, instance.Dimension);
318        Weights = new DoubleMatrix(instance.Dimension, instance.Dimension);
319        for (int i = 0; i < instance.Dimension; i++)
320          Weights[i, (i + 1) % instance.Dimension] = 1;
321        Distances = new DoubleMatrix(instance.Distances);
322
323        TransportationCosts.Value = 1;
324
325        if (instance.BestKnownTour != null) {
326          EvaluateAndLoadAssignment(instance.BestKnownTour);
327        } else {
328          BestKnownQuality = null;
329          BestKnownSolution = null;
330          BestKnownSolutions = null;
331        }
332      } catch {
333        return false;
334      }
335      return true;
336    }
337
338    public bool LoadFrom(IGQAPInstance instance) {
339      try {
340        Name = instance.Name;
341        Description = instance.Description;
342
343        Capacities = new DoubleArray(instance.Capacities);
344        Demands = new DoubleArray(instance.Demands);
345        InstallationCosts = new DoubleMatrix(instance.InstallationCosts);
346        Weights = new DoubleMatrix(instance.Weights);
347        Distances = new DoubleMatrix(instance.Distances);
348        TransportationCosts.Value = instance.TransportationCosts;
349
350        if (instance.BestKnownAssignment != null) {
351          EvaluateAndLoadAssignment(instance.BestKnownAssignment);
352        } else if (instance.BestKnownQuality.HasValue) {
353          BestKnownQuality = new DoubleValue(instance.BestKnownQuality.Value);
354          BestKnownSolution = null;
355          BestKnownSolutions = null;
356        } else {
357          BestKnownQuality = null;
358          BestKnownSolution = null;
359          BestKnownSolutions = null;
360        }
361      } catch {
362        return false;
363      }
364      return true;
365    }
366    #endregion
367
368    private void EvaluateAndLoadAssignment(int[] vector) {
369      EvaluateAndLoadAssignment(new IntegerVector(vector));
370    }
371    private void EvaluateAndLoadAssignment(IntegerVector assignment) {
372      if (!IsConfigurationValid()) {
373        BestKnownQuality = null;
374        BestKnownSolution = null;
375        BestKnownSolutions = null;
376      }
377      double flowDistanceQuality, installationQuality, overbookedCapacity;
378      GQAPEvaluator.Evaluate(assignment, Weights, Distances, InstallationCosts, Demands, Capacities,
379        out flowDistanceQuality, out installationQuality, out overbookedCapacity);
380      double quality = GQAPEvaluator.GetCombinedQuality(flowDistanceQuality, installationQuality, overbookedCapacity, TransportationCosts.Value, OverbookedCapacityPenalty.Value);
381      BestKnownSolution = new GQAPAssignment((IntegerVector)assignment.Clone(), new DoubleValue(quality),
382        new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality),
383        new DoubleValue(overbookedCapacity), EquipmentNames, LocationNames, Distances, Weights, InstallationCosts,
384        Demands, Capacities, TransportationCosts, OverbookedCapacityPenalty);
385      BestKnownQuality = new DoubleValue(quality);
386      BestKnownSolutions = new GQAPAssignmentArchive(EquipmentNames, LocationNames, Distances, Weights, InstallationCosts, Demands, Capacities, TransportationCosts, OverbookedCapacityPenalty);
387      BestKnownSolutions.Solutions.Add(new GQAPSolution((IntegerVector)assignment.Clone(), new DoubleValue(quality), new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality), new DoubleValue(overbookedCapacity)));
388    }
389
390    #region Events
391    protected override void OnOperatorsChanged() {
392      base.OnOperatorsChanged();
393      Parameterize();
394    }
395    protected override void OnEvaluatorChanged() {
396      base.OnEvaluatorChanged();
397      Parameterize();
398      Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged);
399    }
400    protected override void OnSolutionCreatorChanged() {
401      base.OnSolutionCreatorChanged();
402      Parameterize();
403      SolutionCreator.AssignmentParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
404    }
405
406    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
407      Parameterize();
408    }
409    private void SolutionCreator_IntegerVectorParameter_ActualNameChanged(object sender, EventArgs e) {
410      Parameterize();
411    }
412    #endregion
413
414    #region Helpers
415    [StorableHook(HookType.AfterDeserialization)]
416    private void AfterDeserialization() {
417      RegisterEventHandlers();
418    }
419
420    private void RegisterEventHandlers() {
421      Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged);
422      SolutionCreator.AssignmentParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
423    }
424
425    private void InitializeOperators() {
426      Operators.Clear();
427      Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPOperator>());
428      Operators.AddRange(ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>());
429      Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator);
430      Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPMoveEvaluator>());
431      Parameterize();
432    }
433
434    private void Parameterize() {
435
436      var operators = Operators.Union(new IOperator[] { SolutionCreator, Evaluator }).ToArray();
437
438      foreach (var op in operators.OfType<IAssignmentAwareGQAPOperator>()) {
439        op.AssignmentParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
440      }
441      foreach (var op in operators.OfType<IAssignmentsAwareGQAPOperator>()) {
442        op.AssignmentParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
443      }
444      foreach (var op in operators.OfType<IBestKnownQualityAwareGQAPOperator>()) {
445        op.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
446      }
447      foreach (var op in operators.OfType<IBestKnownSolutionAwareGQAPOperator>()) {
448        op.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
449      }
450      foreach (var op in operators.OfType<IBestKnownSolutionsAwareGQAPOperator>()) {
451        op.BestKnownSolutionsParameter.ActualName = BestKnownSolutionsParameter.Name;
452      }
453      foreach (var op in operators.OfType<ICapacitiesAwareGQAPOperator>()) {
454        op.CapacitiesParameter.ActualName = CapacitiesParameter.Name;
455      }
456      foreach (var op in operators.OfType<IDemandsAwareGQAPOperator>()) {
457        op.DemandsParameter.ActualName = DemandsParameter.Name;
458      }
459      foreach (var op in operators.OfType<IDistancesAwareGQAPOperator>()) {
460        op.DistancesParameter.ActualName = DistancesParameter.Name;
461      }
462      foreach (var op in operators.OfType<IEquipmentNamesAwareGQAPOperator>()) {
463        op.EquipmentNamesParameter.ActualName = EquipmentNamesParameter.Name;
464      }
465      foreach (var op in operators.OfType<IGQAPCrossover>()) {
466        op.ParentsParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
467        op.ChildParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
468      }
469      foreach (var op in operators.OfType<IInstallationCostsAwareGQAPOperator>()) {
470        op.InstallationCostsParameter.ActualName = InstallationCostsParameter.Name;
471      }
472      foreach (var op in operators.OfType<ILocationNamesAwareGQAPOperator>()) {
473        op.LocationNamesParameter.ActualName = LocationNamesParameter.Name;
474      }
475      var moveEvaluator = operators.OfType<IGQAPMoveEvaluator>().FirstOrDefault();
476      foreach (var op in operators.OfType<IGQAPMoveEvaluator>()) { // synchronize all move evaluators
477        if (moveEvaluator != null) {
478          op.MoveQualityParameter.ActualName = moveEvaluator.MoveQualityParameter.ActualName;
479          op.MoveFlowDistanceQualityParameter.ActualName = moveEvaluator.MoveFlowDistanceQualityParameter.ActualName;
480          op.MoveInstallationQualityParameter.ActualName = moveEvaluator.MoveInstallationQualityParameter.ActualName;
481          op.MoveOverbookedCapacityParameter.ActualName = moveEvaluator.MoveOverbookedCapacityParameter.ActualName;
482        }
483      }
484      foreach (var op in operators.OfType<IMoveQualityAwareGQAPOperator>()) {
485        if (moveEvaluator != null) {
486          op.MoveQualityParameter.ActualName = moveEvaluator.MoveQualityParameter.ActualName;
487          op.MoveFlowDistanceQualityParameter.ActualName = moveEvaluator.MoveFlowDistanceQualityParameter.ActualName;
488          op.MoveInstallationQualityParameter.ActualName = moveEvaluator.MoveInstallationQualityParameter.ActualName;
489          op.MoveOverbookedCapacityParameter.ActualName = moveEvaluator.MoveOverbookedCapacityParameter.ActualName;
490        }
491        op.MaximizationParameter.ActualName = MaximizationParameter.Name;
492      }
493      foreach (var op in operators.OfType<IOverbookedCapacityPenaltyAwareGQAPOperator>()) {
494        op.OverbookedCapacityPenaltyParameter.ActualName = OverbookedCapacityPenaltyParameter.Name;
495      }
496      foreach (var op in operators.OfType<IQualitiesAwareGQAPOperator>()) {
497        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
498        op.FlowDistanceQualityParameter.ActualName = Evaluator.FlowDistanceQualityParameter.ActualName;
499        op.InstallationQualityParameter.ActualName = Evaluator.InstallationQualityParameter.ActualName;
500        op.OverbookedCapacityParameter.ActualName = Evaluator.OverbookedCapacityParameter.ActualName;
501        op.MaximizationParameter.ActualName = MaximizationParameter.Name;
502      }
503      foreach (var op in operators.OfType<IQualityAwareGQAPOperator>()) {
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<ITransportationCostsAwareGQAPOperator>()) {
511        op.TransportationCostsParameter.ActualName = TransportationCostsParameter.Name;
512      }
513      foreach (var op in operators.OfType<IWeightsAwareGQAPOperator>()) {
514        op.WeightsParameter.ActualName = WeightsParameter.Name;
515      }
516
517      foreach (var op in operators.OfType<IIntegerVectorCrossover>()) {
518        op.ParentsParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
519        op.ChildParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
520      }
521      foreach (var op in operators.OfType<IIntegerVectorManipulator>()) {
522        op.IntegerVectorParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
523      }
524    }
525    #endregion
526
527    private bool IsConfigurationValid() {
528      return Weights != null && Distances != null && Demands != null && Capacities != null && InstallationCosts != null
529        && Weights.Rows == Weights.Columns && Weights.Rows == InstallationCosts.Rows
530        && Distances.Rows == Distances.Columns && Distances.Rows == InstallationCosts.Columns
531        && Demands.Length == Weights.Rows && Capacities.Length == Distances.Rows;
532    }
533  }
534}
Note: See TracBrowser for help on using the repository browser.