- Timestamp:
- 07/08/10 11:23:02 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Evaluators/VRPEvaluator.cs
r3947 r4015 143 143 } 144 144 145 private static double CalculateDistance(int start, int end, DoubleMatrix coordinates) {146 double distance = 0.0;147 148 distance =149 Math.Sqrt(150 Math.Pow(coordinates[start, 0] - coordinates[end, 0], 2) +151 Math.Pow(coordinates[start, 1] - coordinates[end, 1], 2));152 153 return distance;154 }155 156 private static DoubleMatrix CreateDistanceMatrix(DoubleMatrix coordinates)157 {158 DoubleMatrix distanceMatrix = new DoubleMatrix(coordinates.Rows, coordinates.Rows);159 160 for (int i = 0; i < distanceMatrix.Rows; i++) {161 for (int j = i; j < distanceMatrix.Columns; j++) {162 double distance = CalculateDistance(i, j, coordinates);163 164 distanceMatrix[i, j] = distance;165 distanceMatrix[j, i] = distance;166 }167 }168 169 return distanceMatrix;170 }171 172 private static double GetDistance(int start, int end,173 DoubleMatrix coordinates, ILookupParameter<DoubleMatrix> distanceMatrix, BoolValue useDistanceMatrix) {174 double distance = 0.0;175 176 if (useDistanceMatrix.Value) {177 if (distanceMatrix.ActualValue == null) {178 distanceMatrix.ActualValue = CreateDistanceMatrix(coordinates);179 }180 181 distance = distanceMatrix.ActualValue[start, end];182 } else {183 distance = CalculateDistance(start, end, coordinates);184 }185 186 return distance;187 }188 189 145 private static TourEvaluation EvaluateTour(Tour tour, DoubleArray dueTimeArray, 190 146 DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity, … … 210 166 211 167 //drive there 212 double currentDistace = GetDistance(start, end, coordinates, distanceMatrix, useDistanceMatrix);168 double currentDistace = VehicleRoutingProblem.GetDistance(start, end, coordinates, distanceMatrix, useDistanceMatrix); 213 169 distance += currentDistace; 214 170 time += currentDistace;
Note: See TracChangeset
for help on using the changeset viewer.