Changeset 5210 for trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Evaluators/TSPCoordinatesPathEvaluator.cs
- Timestamp:
- 01/05/11 00:49:56 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Evaluators/TSPCoordinatesPathEvaluator.cs
r4825 r5210 34 34 [StorableClass] 35 35 public abstract class TSPCoordinatesPathEvaluator : TSPEvaluator, ITSPCoordinatesPathEvaluator { 36 private object locker = new object(); 37 36 38 public ILookupParameter<Permutation> PermutationParameter { 37 39 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } … … 77 79 78 80 if (dm == null) { // calculate distance matrix 79 DoubleMatrix c = CoordinatesParameter.ActualValue; 80 81 dm = new DistanceMatrix(c.Rows, c.Rows); 82 for (int i = 0; i < dm.Rows; i++) { 83 for (int j = 0; j < dm.Columns; j++) 84 dm[i, j] = CalculateDistance(c[i, 0], c[i, 1], c[j, 0], c[j, 1]); 81 lock (locker) { 82 dm = DistanceMatrixParameter.ActualValue; 83 if (dm == null) { // check again to avoid race condition 84 DoubleMatrix c = CoordinatesParameter.ActualValue; 85 dm = new DistanceMatrix(c.Rows, c.Rows); 86 for (int i = 0; i < dm.Rows; i++) { 87 for (int j = 0; j < dm.Columns; j++) 88 dm[i, j] = CalculateDistance(c[i, 0], c[i, 1], c[j, 0], c[j, 1]); 89 } 90 DistanceMatrixParameter.ActualValue = (DistanceMatrix)dm.AsReadOnly(); 91 } 85 92 } 86 DistanceMatrixParameter.ActualValue = (DistanceMatrix)dm.AsReadOnly();87 93 } 88 94
Note: See TracChangeset
for help on using the changeset viewer.