public void TranslocationMoveEvaluatorTest() { var evaluator = new TSPRoundedEuclideanPathEvaluator(); var moveEvaluator = new TSPTranslocationMoveRoundedEuclideanPathEvaluator(); double beforeMatrix = TSPDistanceMatrixEvaluator.Apply(distances, tour); double beforeCoordinates = TSPCoordinatesPathEvaluator.Apply(evaluator, coordinates, tour); Assert.IsTrue(beforeMatrix.IsAlmost(beforeCoordinates), "Evaluation differs between using the coordinates and using the distance matrix."); for (int i = 0; i < 500; i++) { var move = StochasticTranslocationSingleMoveGenerator.Apply(tour, random); double moveMatrix = TSPTranslocationMovePathEvaluator.EvaluateByDistanceMatrix(tour, move, distances); double moveCoordinates = TSPTranslocationMovePathEvaluator.EvaluateByCoordinates(tour, move, coordinates, moveEvaluator); Assert.IsTrue(moveMatrix.IsAlmost(moveCoordinates), "Evaluation differs between using the coordinates and using the distance matrix."); string failureString = string.Format(@"Translocation move is calculated with quality {0}, but actual difference is {5}. The move would move the segment between {1} and {2} in the tour {3} to the new index {4}.", moveMatrix.ToString(), tour[move.Index1].ToString(), tour[move.Index2].ToString(), tour.ToString(), move.Index3.ToString(), "{0}"); TranslocationManipulator.Apply(tour, move.Index1, move.Index2, move.Index3); double afterMatrix = TSPDistanceMatrixEvaluator.Apply(distances, tour); double afterCoordinates = TSPCoordinatesPathEvaluator.Apply(evaluator, coordinates, tour); Assert.IsTrue(afterMatrix.IsAlmost(afterCoordinates), "Evaluation differs between using the coordinates and using the distance matrix."); Assert.IsTrue(moveMatrix.IsAlmost(afterMatrix - beforeMatrix), string.Format(failureString, (afterMatrix - beforeMatrix).ToString())); beforeMatrix = afterMatrix; beforeCoordinates = afterCoordinates; } }
public void TranslocationMoveEvaluatorTest() { var evaluator = new TSPRoundedEuclideanPathEvaluator(); var moveEvaluator = new TSPTranslocationMoveRoundedEuclideanPathEvaluator(); double beforeMatrix = TSPDistanceMatrixEvaluator.Apply(distances, tour); double beforeCoordinates = TSPCoordinatesPathEvaluator.Apply(evaluator, coordinates, tour); Assert.IsTrue(beforeMatrix.IsAlmost(beforeCoordinates), "Evaluation differs between using the coordinates and using the distance matrix."); for (int i = 0; i < 500; i++) { var move = StochasticTranslocationSingleMoveGenerator.Apply(tour, random); double moveMatrix = TSPTranslocationMovePathEvaluator.EvaluateByDistanceMatrix(tour, move, distances); double moveCoordinates = TSPTranslocationMovePathEvaluator.EvaluateByCoordinates(tour, move, coordinates, moveEvaluator); Assert.IsTrue(moveMatrix.IsAlmost(moveCoordinates), "Evaluation differs between using the coordinates and using the distance matrix."); string failureString = string.Format(@"Translocation move is calculated with quality {0}, but actual difference is {5}. The move would move the segment between {1} and {2} in the tour {3} to the new index {4}.", moveMatrix.ToString(), tour[move.Index1].ToString(), tour[move.Index2].ToString(), tour.ToString(), move.Index3.ToString(), "{0}"); TranslocationManipulator.Apply(tour, move.Index1, move.Index2, move.Index3); double afterMatrix = TSPDistanceMatrixEvaluator.Apply(distances, tour); double afterCoordinates = TSPCoordinatesPathEvaluator.Apply(evaluator, coordinates, tour); Assert.IsTrue(afterMatrix.IsAlmost(afterCoordinates), "Evaluation differs between using the coordinates and using the distance matrix."); Assert.IsTrue(moveMatrix.IsAlmost(afterMatrix - beforeMatrix), string.Format(failureString, (afterMatrix - beforeMatrix).ToString())); beforeMatrix = afterMatrix; beforeCoordinates = afterCoordinates; } }