[6956] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7319] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6956] | 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 |
|
---|
[7311] | 22 | using System;
|
---|
[6956] | 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;
|
---|
[7448] | 33 | using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Common;
|
---|
[7443] | 34 | using HeuristicLab.Problems.Instances;
|
---|
[6956] | 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]
|
---|
[7466] | 40 | public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IGQAPSolutionCreator>, IStorableContent, IProblemInstanceConsumer<IQAPInstance>, IProblemInstanceConsumer<ICTAPInstance>, IProblemInstanceConsumer<ITSPInstance>, IProblemInstanceConsumer<IATSPInstance> {
|
---|
[7419] | 41 |
|
---|
[6956] | 42 | public override Image ItemImage {
|
---|
| 43 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[7311] | 46 | public string Filename { get; set; }
|
---|
| 47 |
|
---|
[7419] | 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.";
|
---|
[7423] | 57 | public static readonly string BestKnownQualityDescription = "The best known quality (if available).";
|
---|
| 58 | public static readonly string BestKnownSolutionDescription = "The best known solution (if available).";
|
---|
[7438] | 59 | public static readonly string BestKnownSolutionsDescription = "Contains an archive of best-known solutions regarding flow-distance quality and installation quality.";
|
---|
[7419] | 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 |
|
---|
[6956] | 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 | }
|
---|
[7412] | 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 | }
|
---|
[7470] | 86 | public OptionalValueParameter<GQAPAssignment> BestKnownSolutionParameter {
|
---|
| 87 | get { return (OptionalValueParameter<GQAPAssignment>)Parameters["BestKnownSolution"]; }
|
---|
[6956] | 88 | }
|
---|
[7438] | 89 | public OptionalValueParameter<GQAPAssignmentArchive> BestKnownSolutionsParameter {
|
---|
| 90 | get { return (OptionalValueParameter<GQAPAssignmentArchive>)Parameters["BestKnownSolutions"]; }
|
---|
| 91 | }
|
---|
[7415] | 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 | }
|
---|
[6956] | 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 | }
|
---|
[7443] | 121 | public DoubleValue TransportationCosts {
|
---|
| 122 | get { return TransportationCostsParameter.Value; }
|
---|
| 123 | set { TransportationCostsParameter.Value = value; }
|
---|
[7412] | 124 | }
|
---|
[7443] | 125 | public DoubleValue OverbookedCapacityPenalty {
|
---|
| 126 | get { return TransportationCostsParameter.Value; }
|
---|
| 127 | set { TransportationCostsParameter.Value = value; }
|
---|
[7412] | 128 | }
|
---|
[7415] | 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 | }
|
---|
[7470] | 137 | public GQAPAssignment BestKnownSolution {
|
---|
[7443] | 138 | get { return BestKnownSolutionParameter.Value; }
|
---|
| 139 | set { BestKnownSolutionParameter.Value = value; }
|
---|
| 140 | }
|
---|
[7448] | 141 | public GQAPAssignmentArchive BestKnownSolutions {
|
---|
| 142 | get { return BestKnownSolutionsParameter.Value; }
|
---|
| 143 | set { BestKnownSolutionsParameter.Value = value; }
|
---|
| 144 | }
|
---|
[6956] | 145 | #endregion
|
---|
| 146 |
|
---|
| 147 | public BestGQAPSolutionAnalyzer BestSolutionAnalyzer {
|
---|
[7418] | 148 | get { return Operators.OfType<BestGQAPSolutionAnalyzer>().FirstOrDefault(); }
|
---|
[6956] | 149 | }
|
---|
[7418] | 150 | public GQAPSolutionArchiveAnalyzer SolutionArchiveAnalyzer {
|
---|
| 151 | get { return Operators.OfType<GQAPSolutionArchiveAnalyzer>().FirstOrDefault(); }
|
---|
| 152 | }
|
---|
[6956] | 153 |
|
---|
| 154 | [StorableConstructor]
|
---|
| 155 | private GeneralizedQuadraticAssignmentProblem(bool deserializing) : base(deserializing) { }
|
---|
| 156 | private GeneralizedQuadraticAssignmentProblem(GeneralizedQuadraticAssignmentProblem original, Cloner cloner)
|
---|
| 157 | : base(original, cloner) {
|
---|
[7432] | 158 | RegisterEventHandlers();
|
---|
[6956] | 159 | }
|
---|
| 160 | public GeneralizedQuadraticAssignmentProblem()
|
---|
[7373] | 161 | : base(new GQAPEvaluator(), new RandomSolutionCreator()) {
|
---|
[7438] | 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));
|
---|
[7419] | 165 | Parameters.Add(new FixedValueParameter<DoubleValue>("TransportationCosts", TransportationCostsDescription, new DoubleValue(1)));
|
---|
| 166 | Parameters.Add(new FixedValueParameter<DoubleValue>("OverbookedCapacityPenalty", OverbookedCapacityPenaltyDescription, new DoubleValue(1000)));
|
---|
[7438] | 167 | Parameters.Add(new ValueParameter<DoubleArray>("Demands", DemandsDescription, new DoubleArray(), false));
|
---|
| 168 | Parameters.Add(new ValueParameter<DoubleArray>("Capacities", CapacitiesDescription, new DoubleArray(), false));
|
---|
[7480] | 169 | Parameters.Add(new OptionalValueParameter<GQAPAssignment>("BestKnownSolution", BestKnownSolutionDescription, null, false));
|
---|
[7438] | 170 | Parameters.Add(new OptionalValueParameter<GQAPAssignmentArchive>("BestKnownSolutions", BestKnownSolutionsDescription, null, false));
|
---|
[7419] | 171 | Parameters.Add(new OptionalValueParameter<StringArray>("EquipmentNames", EquipmentNamesDescription, null, false));
|
---|
| 172 | Parameters.Add(new OptionalValueParameter<StringArray>("LocationNames", LocationNamesDescription, null, false));
|
---|
[6956] | 173 |
|
---|
| 174 | WeightsParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
|
---|
| 175 | DistancesParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
|
---|
| 176 | InstallationCostsParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
|
---|
[7471] | 177 | DemandsParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
|
---|
| 178 | CapacitiesParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
|
---|
[6956] | 179 |
|
---|
| 180 | Weights = new DoubleMatrix(5, 5);
|
---|
| 181 | Weights[0, 0] = Weights[1, 1] = Weights[2, 2] = Weights[3, 3] = Weights[4, 4] = 0;
|
---|
| 182 | 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;
|
---|
| 183 | Weights[1, 2] = Weights[2, 1] = Weights[1, 3] = Weights[3, 1] = Weights[1, 4] = Weights[4, 1] = 5;
|
---|
| 184 | Weights[2, 3] = Weights[3, 2] = Weights[2, 4] = Weights[4, 2] = 7.5;
|
---|
| 185 | Weights[3, 4] = Weights[4, 3] = 2.5;
|
---|
| 186 |
|
---|
| 187 | Distances = new DoubleMatrix(3, 3);
|
---|
| 188 | Distances[0, 0] = Distances[1, 1] = Distances[2, 2] = 0;
|
---|
| 189 | Distances[0, 1] = Distances[1, 0] = Distances[1, 2] = Distances[2, 1] = 1;
|
---|
| 190 | Distances[0, 2] = Distances[2, 0] = 2;
|
---|
| 191 |
|
---|
[7311] | 192 | InstallationCosts = new DoubleMatrix(5, 3);
|
---|
[6956] | 193 |
|
---|
| 194 | Demands = new DoubleArray(5);
|
---|
| 195 | Demands[0] = 2; Demands[1] = 1; Demands[2] = 3; Demands[3] = 1; Demands[4] = 1;
|
---|
| 196 |
|
---|
| 197 | Capacities = new DoubleArray(3);
|
---|
| 198 | Capacities[0] = 4; Capacities[1] = 1; Capacities[2] = 4;
|
---|
| 199 |
|
---|
[7373] | 200 | SolutionCreator.AssignmentParameter.ActualName = "Assignment";
|
---|
[6956] | 201 |
|
---|
| 202 | InitializeOperators();
|
---|
[7432] | 203 | RegisterEventHandlers();
|
---|
[6956] | 204 | }
|
---|
| 205 |
|
---|
| 206 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 207 | return new GeneralizedQuadraticAssignmentProblem(this, cloner);
|
---|
| 208 | }
|
---|
| 209 |
|
---|
[7466] | 210 | public bool LoadFrom(IQAPInstance instance) {
|
---|
| 211 | try {
|
---|
| 212 | Name = instance.Name;
|
---|
| 213 | Description = instance.Description;
|
---|
[7448] | 214 |
|
---|
[7466] | 215 | Weights = new DoubleMatrix(instance.Weights);
|
---|
| 216 | Distances = new DoubleMatrix(instance.Distances);
|
---|
| 217 | InstallationCosts = new DoubleMatrix(Weights.Rows, Distances.Columns); // all zero
|
---|
| 218 | Capacities = new DoubleArray(Enumerable.Range(0, Distances.Rows).Select(x => 1.0).ToArray());
|
---|
| 219 | Demands = new DoubleArray(Enumerable.Range(0, Weights.Rows).Select(x => 1.0).ToArray());
|
---|
[7443] | 220 |
|
---|
[7466] | 221 | TransportationCosts.Value = 1;
|
---|
[7445] | 222 |
|
---|
[7466] | 223 | if (instance.BestKnownAssignment != null) {
|
---|
| 224 | EvaluateAndLoadAssignment(instance.BestKnownAssignment);
|
---|
| 225 | } else {
|
---|
| 226 | BestKnownQuality = null;
|
---|
| 227 | BestKnownSolution = null;
|
---|
| 228 | BestKnownSolutions = null;
|
---|
| 229 | }
|
---|
| 230 | } catch {
|
---|
| 231 | return false;
|
---|
[7443] | 232 | }
|
---|
[7466] | 233 | return true;
|
---|
[7443] | 234 | }
|
---|
| 235 |
|
---|
[7466] | 236 | public bool LoadFrom(ICTAPInstance instance) {
|
---|
| 237 | try {
|
---|
| 238 | Name = instance.Name;
|
---|
| 239 | Description = instance.Description;
|
---|
[7448] | 240 |
|
---|
[7466] | 241 | Capacities = new DoubleArray(instance.MemoryCapacities);
|
---|
| 242 | Demands = new DoubleArray(instance.MemoryRequirements);
|
---|
| 243 | Weights = new DoubleMatrix(instance.CommunicationCosts);
|
---|
| 244 | InstallationCosts = new DoubleMatrix(instance.ExecutionCosts.Transpose());
|
---|
[7480] | 245 | Distances = new DoubleMatrix(Capacities.Length, Capacities.Length);
|
---|
[7466] | 246 | for (int i = 0; i < Capacities.Length - 1; i++)
|
---|
| 247 | for (int j = i + 1; j < Capacities.Length; j++) {
|
---|
| 248 | Distances[i, j] = 1;
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | TransportationCosts.Value = 1;
|
---|
| 252 |
|
---|
| 253 | if (instance.BestKnownAssignment != null) {
|
---|
| 254 | EvaluateAndLoadAssignment(instance.BestKnownAssignment);
|
---|
| 255 | } else {
|
---|
| 256 | BestKnownQuality = null;
|
---|
| 257 | BestKnownSolution = null;
|
---|
| 258 | BestKnownSolutions = null;
|
---|
[7445] | 259 | }
|
---|
[7466] | 260 | } catch {
|
---|
| 261 | return false;
|
---|
| 262 | }
|
---|
| 263 | return true;
|
---|
| 264 | }
|
---|
[7445] | 265 |
|
---|
[7466] | 266 | public bool LoadFrom(ITSPInstance instance) {
|
---|
| 267 | try {
|
---|
| 268 | if (instance.Dimension > 1000) return false;
|
---|
[7470] | 269 |
|
---|
[7466] | 270 | Name = instance.Name;
|
---|
| 271 | Description = instance.Description;
|
---|
[7445] | 272 |
|
---|
[7466] | 273 | Capacities = new DoubleArray(instance.Dimension);
|
---|
| 274 | Demands = new DoubleArray(instance.Dimension);
|
---|
| 275 | for (int i = 0; i < instance.Dimension; i++) {
|
---|
| 276 | Capacities[i] = 1;
|
---|
| 277 | Demands[i] = 1;
|
---|
| 278 | }
|
---|
| 279 | InstallationCosts = new DoubleMatrix(instance.Dimension, instance.Dimension);
|
---|
| 280 | Weights = new DoubleMatrix(instance.Dimension, instance.Dimension);
|
---|
| 281 | for (int i = 0; i < instance.Dimension; i++)
|
---|
| 282 | Weights[i, (i + 1) % instance.Dimension] = 1;
|
---|
| 283 | Distances = new DoubleMatrix(instance.GetDistanceMatrix());
|
---|
| 284 |
|
---|
| 285 | TransportationCosts.Value = 1;
|
---|
| 286 |
|
---|
| 287 | if (instance.BestKnownTour != null) {
|
---|
| 288 | EvaluateAndLoadAssignment(instance.BestKnownTour);
|
---|
| 289 | } else {
|
---|
| 290 | BestKnownQuality = null;
|
---|
| 291 | BestKnownSolution = null;
|
---|
| 292 | BestKnownSolutions = null;
|
---|
| 293 | }
|
---|
| 294 | } catch {
|
---|
| 295 | return false;
|
---|
[7445] | 296 | }
|
---|
[7466] | 297 | return true;
|
---|
[7445] | 298 | }
|
---|
| 299 |
|
---|
[7466] | 300 | public bool LoadFrom(IATSPInstance instance) {
|
---|
| 301 | try {
|
---|
| 302 | Name = instance.Name;
|
---|
| 303 | Description = instance.Description;
|
---|
| 304 |
|
---|
| 305 | Capacities = new DoubleArray(instance.Dimension);
|
---|
| 306 | Demands = new DoubleArray(instance.Dimension);
|
---|
| 307 | for (int i = 0; i < instance.Dimension; i++) {
|
---|
| 308 | Capacities[i] = 1;
|
---|
| 309 | Demands[i] = 1;
|
---|
| 310 | }
|
---|
| 311 | InstallationCosts = new DoubleMatrix(instance.Dimension, instance.Dimension);
|
---|
| 312 | Weights = new DoubleMatrix(instance.Dimension, instance.Dimension);
|
---|
| 313 | for (int i = 0; i < instance.Dimension; i++)
|
---|
| 314 | Weights[i, (i + 1) % instance.Dimension] = 1;
|
---|
| 315 | Distances = new DoubleMatrix(instance.Distances);
|
---|
| 316 |
|
---|
| 317 | TransportationCosts.Value = 1;
|
---|
| 318 |
|
---|
| 319 | if (instance.BestKnownTour != null) {
|
---|
| 320 | EvaluateAndLoadAssignment(instance.BestKnownTour);
|
---|
| 321 | } else {
|
---|
| 322 | BestKnownQuality = null;
|
---|
| 323 | BestKnownSolution = null;
|
---|
| 324 | BestKnownSolutions = null;
|
---|
| 325 | }
|
---|
| 326 | } catch {
|
---|
| 327 | return false;
|
---|
| 328 | }
|
---|
| 329 | return true;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
[7445] | 332 | private void EvaluateAndLoadAssignment(int[] vector) {
|
---|
[7471] | 333 | EvaluateAndLoadAssignment(new IntegerVector(vector));
|
---|
| 334 | }
|
---|
| 335 | private void EvaluateAndLoadAssignment(IntegerVector assignment) {
|
---|
| 336 | if (!IsConfigurationValid()) return;
|
---|
[7445] | 337 | double flowDistanceQuality, installationQuality, overbookedCapacity;
|
---|
| 338 | GQAPEvaluator.Evaluate(assignment, Weights, Distances, InstallationCosts, Demands, Capacities,
|
---|
| 339 | out flowDistanceQuality, out installationQuality, out overbookedCapacity);
|
---|
| 340 | double quality = GQAPEvaluator.GetCombinedQuality(flowDistanceQuality, installationQuality, overbookedCapacity, TransportationCosts.Value, OverbookedCapacityPenalty.Value);
|
---|
[7471] | 341 | BestKnownSolution = new GQAPAssignment((IntegerVector)assignment.Clone(), new DoubleValue(quality),
|
---|
[7470] | 342 | new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality),
|
---|
| 343 | new DoubleValue(overbookedCapacity), EquipmentNames, LocationNames, Distances, Weights, InstallationCosts,
|
---|
| 344 | Demands, Capacities, TransportationCosts, OverbookedCapacityPenalty);
|
---|
[7445] | 345 | BestKnownQuality = new DoubleValue(quality);
|
---|
[7448] | 346 | BestKnownSolutions = new GQAPAssignmentArchive(EquipmentNames, LocationNames, Distances, Weights, InstallationCosts, Demands, Capacities, TransportationCosts, OverbookedCapacityPenalty);
|
---|
[7471] | 347 | BestKnownSolutions.Solutions.Add(new GQAPSolution((IntegerVector)assignment.Clone(), new DoubleValue(quality), new DoubleValue(flowDistanceQuality), new DoubleValue(installationQuality), new DoubleValue(overbookedCapacity)));
|
---|
[7445] | 348 | }
|
---|
| 349 |
|
---|
[6956] | 350 | #region Events
|
---|
[7311] | 351 | protected override void OnOperatorsChanged() {
|
---|
| 352 | base.OnOperatorsChanged();
|
---|
| 353 | Parameterize();
|
---|
| 354 | }
|
---|
| 355 | protected override void OnEvaluatorChanged() {
|
---|
| 356 | base.OnEvaluatorChanged();
|
---|
| 357 | Parameterize();
|
---|
| 358 | Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 359 | }
|
---|
| 360 | protected override void OnSolutionCreatorChanged() {
|
---|
| 361 | base.OnSolutionCreatorChanged();
|
---|
| 362 | Parameterize();
|
---|
[7407] | 363 | SolutionCreator.AssignmentParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
|
---|
[7311] | 364 | }
|
---|
| 365 |
|
---|
| 366 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 367 | Parameterize();
|
---|
| 368 | }
|
---|
| 369 | private void SolutionCreator_IntegerVectorParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 370 | Parameterize();
|
---|
| 371 | }
|
---|
[6956] | 372 | #endregion
|
---|
| 373 |
|
---|
| 374 | #region Helpers
|
---|
| 375 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[7412] | 376 | private void AfterDeserialization() {
|
---|
[7432] | 377 | RegisterEventHandlers();
|
---|
[6956] | 378 | }
|
---|
| 379 |
|
---|
[7432] | 380 | private void RegisterEventHandlers() {
|
---|
[7311] | 381 | Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
[7373] | 382 | SolutionCreator.AssignmentParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
|
---|
[6956] | 383 | }
|
---|
| 384 |
|
---|
| 385 | private void InitializeOperators() {
|
---|
[7437] | 386 | Operators.Clear();
|
---|
[7415] | 387 | Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPOperator>());
|
---|
[6956] | 388 | Operators.AddRange(ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>());
|
---|
| 389 | Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator);
|
---|
[7413] | 390 | Operators.AddRange(ApplicationManager.Manager.GetInstances<IGQAPMoveEvaluator>());
|
---|
[7311] | 391 | Parameterize();
|
---|
[6956] | 392 | }
|
---|
[7311] | 393 |
|
---|
| 394 | private void Parameterize() {
|
---|
| 395 |
|
---|
[7419] | 396 | var operators = Operators.Union(new IOperator[] { SolutionCreator, Evaluator }).ToArray();
|
---|
[7311] | 397 |
|
---|
[7419] | 398 | foreach (var op in operators.OfType<IAssignmentAwareGQAPOperator>()) {
|
---|
| 399 | op.AssignmentParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
| 400 | }
|
---|
| 401 | foreach (var op in operators.OfType<IAssignmentsAwareGQAPOperator>()) {
|
---|
| 402 | op.AssignmentParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
| 403 | }
|
---|
| 404 | foreach (var op in operators.OfType<IBestKnownQualityAwareGQAPOperator>()) {
|
---|
| 405 | op.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
|
---|
| 406 | }
|
---|
| 407 | foreach (var op in operators.OfType<IBestKnownSolutionAwareGQAPOperator>()) {
|
---|
| 408 | op.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
|
---|
| 409 | }
|
---|
[7438] | 410 | foreach (var op in operators.OfType<IBestKnownSolutionsAwareGQAPOperator>()) {
|
---|
| 411 | op.BestKnownSolutionsParameter.ActualName = BestKnownSolutionsParameter.Name;
|
---|
| 412 | }
|
---|
[7419] | 413 | foreach (var op in operators.OfType<ICapacitiesAwareGQAPOperator>()) {
|
---|
| 414 | op.CapacitiesParameter.ActualName = CapacitiesParameter.Name;
|
---|
| 415 | }
|
---|
| 416 | foreach (var op in operators.OfType<IDemandsAwareGQAPOperator>()) {
|
---|
[7407] | 417 | op.DemandsParameter.ActualName = DemandsParameter.Name;
|
---|
[7311] | 418 | }
|
---|
[7419] | 419 | foreach (var op in operators.OfType<IDistancesAwareGQAPOperator>()) {
|
---|
| 420 | op.DistancesParameter.ActualName = DistancesParameter.Name;
|
---|
| 421 | }
|
---|
| 422 | foreach (var op in operators.OfType<IEquipmentNamesAwareGQAPOperator>()) {
|
---|
| 423 | op.EquipmentNamesParameter.ActualName = EquipmentNamesParameter.Name;
|
---|
| 424 | }
|
---|
| 425 | foreach (var op in operators.OfType<IGQAPCrossover>()) {
|
---|
[7373] | 426 | op.ParentsParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
| 427 | op.ChildParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
[7319] | 428 | }
|
---|
[7419] | 429 | foreach (var op in operators.OfType<IInstallationCostsAwareGQAPOperator>()) {
|
---|
[7407] | 430 | op.InstallationCostsParameter.ActualName = InstallationCostsParameter.Name;
|
---|
| 431 | }
|
---|
[7419] | 432 | foreach (var op in operators.OfType<ILocationNamesAwareGQAPOperator>()) {
|
---|
| 433 | op.LocationNamesParameter.ActualName = LocationNamesParameter.Name;
|
---|
| 434 | }
|
---|
| 435 | var moveEvaluator = operators.OfType<IGQAPMoveEvaluator>().FirstOrDefault();
|
---|
| 436 | foreach (var op in operators.OfType<IGQAPMoveEvaluator>()) { // synchronize all move evaluators
|
---|
| 437 | if (moveEvaluator != null) {
|
---|
| 438 | op.MoveQualityParameter.ActualName = moveEvaluator.MoveQualityParameter.ActualName;
|
---|
| 439 | op.MoveFlowDistanceQualityParameter.ActualName = moveEvaluator.MoveFlowDistanceQualityParameter.ActualName;
|
---|
| 440 | op.MoveInstallationQualityParameter.ActualName = moveEvaluator.MoveInstallationQualityParameter.ActualName;
|
---|
| 441 | op.MoveOverbookedCapacityParameter.ActualName = moveEvaluator.MoveOverbookedCapacityParameter.ActualName;
|
---|
| 442 | }
|
---|
| 443 | }
|
---|
| 444 | foreach (var op in operators.OfType<IMoveQualityAwareGQAPOperator>()) {
|
---|
| 445 | if (moveEvaluator != null) {
|
---|
| 446 | op.MoveQualityParameter.ActualName = moveEvaluator.MoveQualityParameter.ActualName;
|
---|
| 447 | op.MoveFlowDistanceQualityParameter.ActualName = moveEvaluator.MoveFlowDistanceQualityParameter.ActualName;
|
---|
| 448 | op.MoveInstallationQualityParameter.ActualName = moveEvaluator.MoveInstallationQualityParameter.ActualName;
|
---|
| 449 | op.MoveOverbookedCapacityParameter.ActualName = moveEvaluator.MoveOverbookedCapacityParameter.ActualName;
|
---|
| 450 | }
|
---|
| 451 | op.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
| 452 | }
|
---|
| 453 | foreach (var op in operators.OfType<IOverbookedCapacityPenaltyAwareGQAPOperator>()) {
|
---|
| 454 | op.OverbookedCapacityPenaltyParameter.ActualName = OverbookedCapacityPenaltyParameter.Name;
|
---|
| 455 | }
|
---|
| 456 | foreach (var op in operators.OfType<IQualitiesAwareGQAPOperator>()) {
|
---|
[7412] | 457 | op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
| 458 | op.FlowDistanceQualityParameter.ActualName = Evaluator.FlowDistanceQualityParameter.ActualName;
|
---|
| 459 | op.InstallationQualityParameter.ActualName = Evaluator.InstallationQualityParameter.ActualName;
|
---|
| 460 | op.OverbookedCapacityParameter.ActualName = Evaluator.OverbookedCapacityParameter.ActualName;
|
---|
[7419] | 461 | op.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
[7407] | 462 | }
|
---|
[7419] | 463 | foreach (var op in operators.OfType<IQualityAwareGQAPOperator>()) {
|
---|
[7412] | 464 | op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
[7419] | 465 | op.FlowDistanceQualityParameter.ActualName = Evaluator.FlowDistanceQualityParameter.ActualName;
|
---|
| 466 | op.InstallationQualityParameter.ActualName = Evaluator.InstallationQualityParameter.ActualName;
|
---|
| 467 | op.OverbookedCapacityParameter.ActualName = Evaluator.OverbookedCapacityParameter.ActualName;
|
---|
[7412] | 468 | op.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
| 469 | }
|
---|
[7419] | 470 | foreach (var op in operators.OfType<ITransportationCostsAwareGQAPOperator>()) {
|
---|
| 471 | op.TransportationCostsParameter.ActualName = TransportationCostsParameter.Name;
|
---|
[7407] | 472 | }
|
---|
[7419] | 473 | foreach (var op in operators.OfType<IWeightsAwareGQAPOperator>()) {
|
---|
| 474 | op.WeightsParameter.ActualName = WeightsParameter.Name;
|
---|
[7319] | 475 | }
|
---|
[7407] | 476 |
|
---|
[7419] | 477 | foreach (var op in operators.OfType<IIntegerVectorCrossover>()) {
|
---|
[7407] | 478 | op.ParentsParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
| 479 | op.ChildParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
[7319] | 480 | }
|
---|
[7419] | 481 | foreach (var op in operators.OfType<IIntegerVectorManipulator>()) {
|
---|
[7407] | 482 | op.IntegerVectorParameter.ActualName = SolutionCreator.AssignmentParameter.ActualName;
|
---|
| 483 | }
|
---|
[6956] | 484 | }
|
---|
| 485 | #endregion
|
---|
[7471] | 486 |
|
---|
| 487 | private bool IsConfigurationValid() {
|
---|
| 488 | return Weights != null && Distances != null && Demands != null && Capacities != null && InstallationCosts != null
|
---|
| 489 | && Weights.Rows == Weights.Columns && Weights.Rows == InstallationCosts.Rows
|
---|
| 490 | && Distances.Rows == Distances.Columns && Distances.Rows == InstallationCosts.Columns
|
---|
| 491 | && Demands.Length == Weights.Rows && Capacities.Length == Distances.Rows;
|
---|
| 492 | }
|
---|
[6956] | 493 | }
|
---|
| 494 | }
|
---|