Changeset 5838 for branches/QAP/HeuristicLab.Problems.QuadraticAssignment
- Timestamp:
- 03/28/11 15:34:30 (14 years ago)
- Location:
- branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Analyzers/BestQAPSolutionAnalyzer.cs
r5583 r5838 89 89 90 90 public override IOperation Apply() { 91 DoubleMatrix coordinates = CoordinatesParameter.ActualValue;92 91 DoubleMatrix distances = DistancesParameter.ActualValue; 93 92 DoubleMatrix weights = WeightsParameter.ActualValue; … … 113 112 if (assignment == null) { 114 113 assignment = new QAPAssignment(weights, (Permutation)permutations[i].Clone(), new DoubleValue(qualities[i].Value)); 115 assignment.Coordinates = coordinates;116 114 assignment.Distances = distances; 117 115 BestSolutionParameter.ActualValue = assignment; … … 120 118 if (max && assignment.Quality.Value < qualities[i].Value || 121 119 !max && assignment.Quality.Value > qualities[i].Value) { 122 assignment.Coordinates = coordinates;123 120 assignment.Distances = distances; 124 121 assignment.Weights = weights; -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Evaluators/QAPEvaluator.cs
r5598 r5838 35 35 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } 36 36 } 37 public ILookupParameter<DoubleMatrix> DistanceMatrixParameter { 38 get { return (ILookupParameter<DoubleMatrix>)Parameters["DistanceMatrix"]; } 39 } 40 public ILookupParameter<DoubleMatrix> CoordinatesParameter { 41 get { return (ILookupParameter<DoubleMatrix>)Parameters["Coordinates"]; } 37 public ILookupParameter<DoubleMatrix> DistancesParameter { 38 get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; } 42 39 } 43 40 public ILookupParameter<DoubleMatrix> WeightsParameter { … … 53 50 public QAPEvaluator() { 54 51 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation that represents the current solution.")); 55 Parameters.Add(new LookupParameter<DoubleMatrix>("DistanceMatrix", "The distance matrix that contains the distances between the locations.")); 56 Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The coordinates in case the distance matrix should not be used.")); 52 Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", "The distance matrix that contains the distances between the locations.")); 57 53 Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", "The matrix with the weights between the facilities, that is how strongly they're connected to each other.")); 58 54 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value aka fitness value of the solution.")); … … 76 72 Permutation assignment = PermutationParameter.ActualValue; 77 73 DoubleMatrix weights = WeightsParameter.ActualValue; 78 DoubleMatrix distanceMatrix = Distance MatrixParameter.ActualValue;74 DoubleMatrix distanceMatrix = DistancesParameter.ActualValue; 79 75 80 76 double quality = Apply(assignment, weights, distanceMatrix); -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Evaluators/QAPInversionMoveEvaluator.cs
r5785 r5838 73 73 if (move == null) throw new InvalidOperationException("Inversion move is not found."); 74 74 Permutation assignment = PermutationParameter.ActualValue; 75 DoubleMatrix distances = Distance MatrixParameter.ActualValue;75 DoubleMatrix distances = DistancesParameter.ActualValue; 76 76 DoubleMatrix weights = WeightsParameter.ActualValue; 77 77 -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Evaluators/QAPMoveEvaluator.cs
r5785 r5838 49 49 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } 50 50 } 51 public ILookupParameter<DoubleMatrix> Distance MatrixParameter {52 get { return (ILookupParameter<DoubleMatrix>)Parameters["Distance Matrix"]; }51 public ILookupParameter<DoubleMatrix> DistancesParameter { 52 get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; } 53 53 } 54 54 public ILookupParameter<DoubleMatrix> WeightsParameter { … … 64 64 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The evaluated quality of a move on a QAP solution.")); 65 65 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation.")); 66 Parameters.Add(new LookupParameter<DoubleMatrix>("Distance Matrix", "The matrix which contains the distances between the facilities."));66 Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", "The matrix which contains the distances between the facilities.")); 67 67 Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", "The matrix with the weights between the facilities, that is how strongly they're connected to each other.")); 68 68 } -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Evaluators/QAPSwapMoveEvaluator.cs
r5785 r5838 29 29 30 30 namespace HeuristicLab.Problems.QuadraticAssignment { 31 [Item("QAPSwap MoveEvaluator", "Evaluated a swapmove on a QAP solution.")]31 [Item("QAPSwap2MoveEvaluator", "Evaluated a swap-2 move on a QAP solution.")] 32 32 [StorableClass] 33 public class QAPSwap MoveEvaluator : QAPMoveEvaluator, IPermutationSwapMoveOperator {34 public ILookupParameter<Swap Move> SwapMoveParameter {35 get { return (ILookupParameter<Swap Move>)Parameters["SwapMove"]; }33 public class QAPSwap2MoveEvaluator : QAPMoveEvaluator, IPermutationSwap2MoveOperator { 34 public ILookupParameter<Swap2Move> Swap2MoveParameter { 35 get { return (ILookupParameter<Swap2Move>)Parameters["Swap2Move"]; } 36 36 } 37 37 38 38 [StorableConstructor] 39 protected QAPSwap MoveEvaluator(bool deserializing) : base(deserializing) { }40 protected QAPSwap MoveEvaluator(QAPSwapMoveEvaluator original, Cloner cloner)39 protected QAPSwap2MoveEvaluator(bool deserializing) : base(deserializing) { } 40 protected QAPSwap2MoveEvaluator(QAPSwap2MoveEvaluator original, Cloner cloner) 41 41 : base(original, cloner) { 42 42 } 43 public QAPSwap MoveEvaluator() {44 Parameters.Add(new LookupParameter<Swap Move>("SwapMove", "The move to evaluate."));43 public QAPSwap2MoveEvaluator() { 44 Parameters.Add(new LookupParameter<Swap2Move>("Swap2Move", "The move to evaluate.")); 45 45 } 46 46 47 47 public override IDeepCloneable Clone(Cloner cloner) { 48 return new QAPSwap MoveEvaluator(this, cloner);48 return new QAPSwap2MoveEvaluator(this, cloner); 49 49 } 50 50 51 public static double Apply(Permutation assignment, Swap Move move, DoubleMatrix weights, DoubleMatrix distances) {51 public static double Apply(Permutation assignment, Swap2Move move, DoubleMatrix weights, DoubleMatrix distances) { 52 52 if (move.Index1 == move.Index2) return 0; 53 53 double moveQuality = 0; … … 70 70 71 71 public override IOperation Apply() { 72 Swap Move move = SwapMoveParameter.ActualValue;73 if (move == null) throw new InvalidOperationException("Swap move is not found.");72 Swap2Move move = Swap2MoveParameter.ActualValue; 73 if (move == null) throw new InvalidOperationException("Swap-2 move is not found."); 74 74 Permutation assignment = PermutationParameter.ActualValue; 75 DoubleMatrix distances = Distance MatrixParameter.ActualValue;75 DoubleMatrix distances = DistancesParameter.ActualValue; 76 76 DoubleMatrix weights = WeightsParameter.ActualValue; 77 77 -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Evaluators/QAPTranslocationMoveEvaluator.cs
r5801 r5838 85 85 if (move == null) throw new InvalidOperationException("Translocation move is not found."); 86 86 Permutation assignment = PermutationParameter.ActualValue; 87 DoubleMatrix distances = Distance MatrixParameter.ActualValue;87 DoubleMatrix distances = DistancesParameter.ActualValue; 88 88 DoubleMatrix weights = WeightsParameter.ActualValue; 89 89 -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Interfaces/IQAPEvaluator.cs
r5598 r5838 28 28 public interface IQAPEvaluator : ISingleObjectiveEvaluator { 29 29 ILookupParameter<Permutation> PermutationParameter { get; } 30 ILookupParameter<DoubleMatrix> DistanceMatrixParameter { get; } 31 ILookupParameter<DoubleMatrix> CoordinatesParameter { get; } 30 ILookupParameter<DoubleMatrix> DistancesParameter { get; } 32 31 ILookupParameter<DoubleMatrix> WeightsParameter { get; } 33 32 } -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Interfaces/IQAPMoveEvaluator.cs
r5785 r5838 28 28 public interface IQAPMoveEvaluator : ISingleObjectiveMoveEvaluator, IMoveOperator { 29 29 ILookupParameter<Permutation> PermutationParameter { get; } 30 ILookupParameter<DoubleMatrix> Distance MatrixParameter { get; }30 ILookupParameter<DoubleMatrix> DistancesParameter { get; } 31 31 ILookupParameter<DoubleMatrix> WeightsParameter { get; } 32 32 } -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Parsers/QAPLIBParser.cs
r5648 r5838 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2011 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; 2 23 using System.IO; 3 24 -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Parsers/QAPLIBSolutionParser.cs
r5814 r5838 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2011 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; 2 23 using System.Globalization; 3 24 using System.IO; -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Plugin.cs.frame
r5563 r5838 25 25 [Plugin("HeuristicLab.Problems.QuadraticAssignment", "3.3.3.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.QuadraticAssignment-3.3.dll", PluginFileType.Assembly)] 27 [PluginDependency("HeuristicLab.Collections", "3.3 .3")]28 [PluginDependency("HeuristicLab.Common", "3.3 .3")]29 [PluginDependency("HeuristicLab.Common.Resources", "3.3 .3")]30 [PluginDependency("HeuristicLab.Core", "3.3 .3")]31 [PluginDependency("HeuristicLab.Data", "3.3 .3")]32 [PluginDependency("HeuristicLab.Encodings.PermutationEncoding", "3.3 .3")]33 [PluginDependency("HeuristicLab.Operators", "3.3 .3")]34 [PluginDependency("HeuristicLab.Optimization", "3.3 .3")]35 [PluginDependency("HeuristicLab.Parameters", "3.3 .3")]36 [PluginDependency("HeuristicLab.Persistence", "3.3 .3")]27 [PluginDependency("HeuristicLab.Collections", "3.3")] 28 [PluginDependency("HeuristicLab.Common", "3.3")] 29 [PluginDependency("HeuristicLab.Common.Resources", "3.3")] 30 [PluginDependency("HeuristicLab.Core", "3.3")] 31 [PluginDependency("HeuristicLab.Data", "3.3")] 32 [PluginDependency("HeuristicLab.Encodings.PermutationEncoding", "3.3")] 33 [PluginDependency("HeuristicLab.Operators", "3.3")] 34 [PluginDependency("HeuristicLab.Optimization", "3.3")] 35 [PluginDependency("HeuristicLab.Parameters", "3.3")] 36 [PluginDependency("HeuristicLab.Persistence", "3.3")] 37 37 public class HeuristicLabProblemsQuadraticAssignmentPlugin : PluginBase { } 38 38 } -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/QAPAssignment.cs
r5648 r5838 10 10 [StorableClass] 11 11 public sealed class QAPAssignment : Item, INotifyPropertyChanged { 12 [Storable]13 private DoubleMatrix coordinates;14 public DoubleMatrix Coordinates {15 get { return coordinates; }16 set {17 bool changed = (coordinates != value);18 coordinates = value;19 if (changed) OnPropertyChanged("Coordinates");20 }21 }22 12 23 13 [Storable] … … 69 59 private QAPAssignment(QAPAssignment original, Cloner cloner) 70 60 : base(original, cloner) { 71 coordinates = cloner.Clone(original.coordinates);72 61 distances = cloner.Clone(original.distances); 73 62 weights = cloner.Clone(original.weights); -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r5814 r5838 36 36 37 37 namespace HeuristicLab.Problems.QuadraticAssignment { 38 [Item("Quadratic Assignment Problem", "The Quadratic Assignment Problem (QAP) is the problem of assigning N facilities to N fixed locations such that there is exactly one facility in each location and thatthe distances multiplied by the connection strength between the facilities becomes minimal.")]38 [Item("Quadratic Assignment Problem", "The Quadratic Assignment Problem (QAP) can be described as the problem of assigning N facilities to N fixed locations such that there is exactly one facility in each location and that the sum of the distances multiplied by the connection strength between the facilities becomes minimal.")] 39 39 [Creatable("Problems")] 40 40 [StorableClass] … … 56 56 get { return (IValueParameter<DoubleMatrix>)Parameters["Weights"]; } 57 57 } 58 public IValueParameter<DoubleMatrix> Distance MatrixParameter {59 get { return (IValueParameter<DoubleMatrix>)Parameters["Distance Matrix"]; }58 public IValueParameter<DoubleMatrix> DistancesParameter { 59 get { return (IValueParameter<DoubleMatrix>)Parameters["Distances"]; } 60 60 } 61 61 #endregion … … 74 74 set { WeightsParameter.Value = value; } 75 75 } 76 public DoubleMatrix Distance Matrix{77 get { return Distance MatrixParameter.Value; }78 set { Distance MatrixParameter.Value = value; }76 public DoubleMatrix Distances { 77 get { return DistancesParameter.Value; } 78 set { DistancesParameter.Value = value; } 79 79 } 80 80 … … 106 106 Parameters.Add(new ValueParameter<DoubleMatrix>("Coordinates", "The coordinates of the locations. If this is changed the distance matrix is calculated automatically using the euclidean distance.")); 107 107 Parameters.Add(new ValueParameter<DoubleMatrix>("Weights", "The strength of the connection between the facilities.", new DoubleMatrix(5, 5))); 108 Parameters.Add(new ValueParameter<DoubleMatrix>("Distance Matrix", "The distance matrix which can either be specified directly without the coordinates, or can be calculated automatically from the coordinates.", new DoubleMatrix(5, 5)));108 Parameters.Add(new ValueParameter<DoubleMatrix>("Distances", "The distance matrix which can either be specified directly without the coordinates, or can be calculated automatically from the coordinates.", new DoubleMatrix(5, 5))); 109 109 110 110 Maximization = new BoolValue(false); … … 126 126 }); 127 127 128 Distance Matrix= new DoubleMatrix(new double[,] {128 Distances = new DoubleMatrix(new double[,] { 129 129 { 0, 360, 582, 582, 360 }, 130 130 { 360, 0, 360, 582, 582 }, … … 231 231 if (Evaluator != null) { 232 232 Evaluator.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 233 Evaluator.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name; 234 Evaluator.CoordinatesParameter.ActualName = CoordinatesParameter.Name; 233 Evaluator.DistancesParameter.ActualName = DistancesParameter.Name; 235 234 Evaluator.WeightsParameter.ActualName = WeightsParameter.Name; 236 235 } … … 240 239 BestQAPSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 241 240 BestQAPSolutionAnalyzer.CoordinatesParameter.ActualName = CoordinatesParameter.Name; 242 BestQAPSolutionAnalyzer.DistancesParameter.ActualName = Distance MatrixParameter.Name;241 BestQAPSolutionAnalyzer.DistancesParameter.ActualName = DistancesParameter.Name; 243 242 BestQAPSolutionAnalyzer.WeightsParameter.ActualName = WeightsParameter.Name; 244 243 BestQAPSolutionAnalyzer.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; … … 267 266 foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>()) 268 267 op.TranslocationMoveParameter.ActualName = translocationMove; 269 string swapMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationSwap MoveOperator>().First().SwapMoveParameter.ActualName;270 foreach (IPermutationSwap MoveOperator op in Operators.OfType<IPermutationSwapMoveOperator>()) {271 op.Swap MoveParameter.ActualName = swapMove;268 string swapMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationSwap2MoveOperator>().First().Swap2MoveParameter.ActualName; 269 foreach (IPermutationSwap2MoveOperator op in Operators.OfType<IPermutationSwap2MoveOperator>()) { 270 op.Swap2MoveParameter.ActualName = swapMove; 272 271 } 273 272 } … … 282 281 double dy = Coordinates[i, 1] - Coordinates[j, 1]; 283 282 distance[i, j] = Math.Sqrt(dx * dx + dy * dy); 284 distance[j, i] = Distance Matrix[i, j];283 distance[j, i] = Distances[i, j]; 285 284 } 286 285 } 287 Distance Matrix= distance;286 Distances = distance; 288 287 } 289 288 } … … 295 294 if (parser.Error != null) throw parser.Error; 296 295 Coordinates = new DoubleMatrix(); 297 Distance Matrix= new DoubleMatrix(parser.Distances);296 Distances = new DoubleMatrix(parser.Distances); 298 297 Weights = new DoubleMatrix(parser.Weights); 299 298 Name = "Quadratic Assignment Problem (imported from " + Path.GetFileNameWithoutExtension(filename) + ")"; … … 311 310 if (parser.Error != null) throw parser.Error; 312 311 Coordinates = new DoubleMatrix(); 313 Distance Matrix= new DoubleMatrix(parser.Distances);312 Distances = new DoubleMatrix(parser.Distances); 314 313 Weights = new DoubleMatrix(parser.Weights); 315 314 Name = "Quadratic Assignment Problem (loaded instance " + instance + ")"; … … 327 326 solParser.Parse(solStream, false); // most sln's seem to be of the type index = location => value = facility 328 327 if (solParser.Error != null) throw solParser.Error; 329 if (!solParser.Quality.IsAlmost(QAPEvaluator.Apply(new Permutation(PermutationTypes.Absolute, solParser.Assignment), Weights, Distance Matrix))) {328 if (!solParser.Quality.IsAlmost(QAPEvaluator.Apply(new Permutation(PermutationTypes.Absolute, solParser.Assignment), Weights, Distances))) { 330 329 solStream.Seek(0, SeekOrigin.Begin); 331 330 solParser.Parse(solStream, true); // some sln's seem to be of the type index = facility => value = location 332 331 if (solParser.Error != null) throw solParser.Error; 333 if (solParser.Quality.IsAlmost(QAPEvaluator.Apply(new Permutation(PermutationTypes.Absolute, solParser.Assignment), Weights, Distance Matrix))) {332 if (solParser.Quality.IsAlmost(QAPEvaluator.Apply(new Permutation(PermutationTypes.Absolute, solParser.Assignment), Weights, Distances))) { 334 333 BestKnownQuality = new DoubleValue(solParser.Quality); 335 334 BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment); -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Tests/QAPLIBInstancesTest.cs
r5814 r5838 35 35 double quality = double.NaN; 36 36 try { 37 quality = QAPEvaluator.Apply(qap.BestKnownSolution, qap.Weights, qap.Distance Matrix);37 quality = QAPEvaluator.Apply(qap.BestKnownSolution, qap.Weights, qap.Distances); 38 38 } catch (Exception ex) { 39 39 failedInstances.AppendLine("An unknown problem occurred evaluating solution of instance " + instance + ": " + ex.Message); -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Tests/QAPMoveEvaluatorTest.cs
r5801 r5838 97 97 double after = QAPEvaluator.Apply(assignment, weights, distances); 98 98 // evaluate swap back 99 double move = QAPSwap MoveEvaluator.Apply(assignment, new SwapMove(index1, index2, assignment), weights, distances);99 double move = QAPSwap2MoveEvaluator.Apply(assignment, new Swap2Move(index1, index2, assignment), weights, distances); 100 100 Assert.IsTrue(move.IsAlmost(before - after)); 101 101 }
Note: See TracChangeset
for help on using the changeset viewer.