Changeset 7621 for trunk/sources/HeuristicLab.Problems.TravelingSalesman
- Timestamp:
- 03/15/12 14:29:53 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Analyzers/TSPAlleleFrequencyAnalyzer.cs
r7259 r7621 60 60 DoubleMatrix coords = CoordinatesParameter.ActualValue; 61 61 DistanceMatrix dm = DistanceMatrixParameter.ActualValue; 62 if (dm == null && coords == null) throw new InvalidOperationException("Neither a distance matrix nor coordinates were given."); 62 63 int source, target, h; 63 64 double impact; -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Evaluators/TSPCoordinatesPathEvaluator.cs
r7558 r7621 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 93 94 if (dm == null) { // check again to avoid race condition 94 95 DoubleMatrix c = CoordinatesParameter.ActualValue; 96 if (c == null) throw new InvalidOperationException("Neither a distance matrix nor coordinates were given."); 95 97 dm = new DistanceMatrix(c.Rows, c.Rows); 96 98 for (int i = 0; i < dm.Rows; i++) { … … 111 113 Permutation p = PermutationParameter.ActualValue; 112 114 DoubleMatrix c = CoordinatesParameter.ActualValue; 113 115 if (c == null) throw new InvalidOperationException("No coordinates were given."); 114 116 double length = 0; 115 117 for (int i = 0; i < p.Length - 1; i++) -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/MoveEvaluators/TSPPathMoveEvaluator.cs
r7259 r7621 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 78 79 DistanceMatrix distanceMatrix = DistanceMatrixParameter.ActualValue; 79 80 if (distanceMatrix == null) { 81 if (coordinates == null) throw new InvalidOperationException("Neither a distance matrix nor coordinates were given."); 80 82 distanceMatrix = CalculateDistanceMatrix(coordinates); 81 83 DistanceMatrixParameter.ActualValue = distanceMatrix; 82 84 } 83 85 relativeQualityDifference = EvaluateByDistanceMatrix(permutation, distanceMatrix); 84 } else relativeQualityDifference = EvaluateByCoordinates(permutation, coordinates); 86 } else { 87 if (coordinates == null) throw new InvalidOperationException("No coordinates were given."); 88 relativeQualityDifference = EvaluateByCoordinates(permutation, coordinates); 89 } 85 90 DoubleValue moveQuality = MoveQualityParameter.ActualValue; 86 91 if (moveQuality == null) MoveQualityParameter.ActualValue = new DoubleValue(QualityParameter.ActualValue.Value + relativeQualityDifference); -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs
r7558 r7621 44 44 45 45 #region Parameter Properties 46 public ValueParameter<DoubleMatrix> CoordinatesParameter {47 get { return ( ValueParameter<DoubleMatrix>)Parameters["Coordinates"]; }46 public OptionalValueParameter<DoubleMatrix> CoordinatesParameter { 47 get { return (OptionalValueParameter<DoubleMatrix>)Parameters["Coordinates"]; } 48 48 } 49 49 public OptionalValueParameter<DistanceMatrix> DistanceMatrixParameter { … … 110 110 public TravelingSalesmanProblem() 111 111 : base(new TSPRoundedEuclideanPathEvaluator(), new RandomPermutationCreator()) { 112 Parameters.Add(new ValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities."));112 Parameters.Add(new OptionalValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.")); 113 113 Parameters.Add(new OptionalValueParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities.")); 114 114 Parameters.Add(new ValueParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false.", new BoolValue(true))); … … 148 148 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 149 149 ParameterizeEvaluator(); 150 ParameterizeSolutionCreator(); 150 151 UpdateMoveEvaluators(); 151 152 ParameterizeAnalyzers(); … … 153 154 } 154 155 private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) { 155 Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged); 156 Coordinates.Reset += new EventHandler(Coordinates_Reset); 156 if (Coordinates != null) { 157 Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged); 158 Coordinates.Reset += new EventHandler(Coordinates_Reset); 159 } 157 160 ParameterizeSolutionCreator(); 158 161 ClearDistanceMatrix(); … … 197 200 } 198 201 202 ValueParameter<DoubleMatrix> oldCoordinates = (Parameters["Coordinates"] as ValueParameter<DoubleMatrix>); 203 if (oldCoordinates != null) { 204 Parameters.Remove(oldCoordinates); 205 Parameters.Add(new OptionalValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.", oldCoordinates.Value, oldCoordinates.GetsCollected)); 206 } 207 199 208 if (Operators.Count == 0) InitializeOperators(); 200 209 #endregion … … 204 213 private void RegisterEventHandlers() { 205 214 CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged); 206 Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged); 207 Coordinates.Reset += new EventHandler(Coordinates_Reset); 215 if (Coordinates != null) { 216 Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged); 217 Coordinates.Reset += new EventHandler(Coordinates_Reset); 218 } 208 219 SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged); 209 220 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); … … 229 240 } 230 241 private void ParameterizeSolutionCreator() { 231 SolutionCreator.LengthParameter.Value = new IntValue(Coordinates.Rows); 232 SolutionCreator.LengthParameter.Hidden = true; 242 if (Evaluator is ITSPDistanceMatrixEvaluator && DistanceMatrix != null) 243 SolutionCreator.LengthParameter.Value = new IntValue(DistanceMatrix.Rows); 244 else if (Evaluator is ITSPCoordinatesPathEvaluator && Coordinates != null) 245 SolutionCreator.LengthParameter.Value = new IntValue(Coordinates.Rows); 246 else SolutionCreator.LengthParameter.Value = null; 247 SolutionCreator.LengthParameter.Hidden = SolutionCreator.LengthParameter.Value != null; 233 248 SolutionCreator.PermutationTypeParameter.Value = new PermutationType(PermutationTypes.RelativeUndirected); 234 249 SolutionCreator.PermutationTypeParameter.Hidden = true; … … 324 339 public void Load(TSPData data) { 325 340 if (data.Coordinates == null && data.Distances == null) 326 throw new System.IO.InvalidDataException("The given instance does not specify neither coordinatesor distances!");341 throw new System.IO.InvalidDataException("The given instance specifies neither coordinates nor distances!"); 327 342 if (data.Dimension > DistanceMatrixSizeLimit && (data.DistanceMeasure == TSPDistanceMeasure.Att 328 343 || data.DistanceMeasure == TSPDistanceMeasure.Manhattan … … 338 353 if (data.Coordinates != null && data.Coordinates.GetLength(0) > 0) 339 354 Coordinates = new DoubleMatrix(data.Coordinates); 355 else Coordinates = null; 340 356 341 357 TSPEvaluator evaluator; … … 392 408 393 409 double quality; 394 if (Evaluator is TSPDistanceMatrixEvaluator) {410 if (Evaluator is ITSPDistanceMatrixEvaluator) { 395 411 quality = TSPDistanceMatrixEvaluator.Apply(DistanceMatrix, route); 396 } else if (Evaluator is TSPCoordinatesPathEvaluator) {412 } else if (Evaluator is ITSPCoordinatesPathEvaluator) { 397 413 quality = TSPCoordinatesPathEvaluator.Apply((TSPCoordinatesPathEvaluator)Evaluator, Coordinates, route); 398 414 } else {
Note: See TracChangeset
for help on using the changeset viewer.