public static bool VerificationTests() { var graph = new EuclideanCircularGraph(10, 100); if (Math.Abs(TspBruteForce(graph) - graph.ShortestRouteCost) > 0.05) { return(false); } return(true); }
private void AlgorithmTestRuntime(Algorithm algorithm, DoublingCalculator doublingCalc) { PrintHeader(algorithm); var currentStats = new AlgStats(); for (var n = NMin; n <= NMax; n *= 2) { currentStats.n = n; if (currentStats.TimeMicro > MaxMicroSecondsPerAlg) { PrintAlgorithmTerminationMessage(algorithm); break; } PrintIndexColumn(currentStats.n); int testCount = 1; int maxTest = 1000000; long tickCounter = 0; while (testCount <= maxTest && TicksToMicroseconds(tickCounter) < MaxMicroSecondsPerIteration) { Graph graph = new EuclideanCircularGraph(n, 100); _stopwatch.Restart(); currentStats.AlgResult = algorithm(graph); _stopwatch.Stop(); // HACK (this should be handled better) currentStats.CorrectnessRatio = ((EuclideanCircularGraph)graph).ShortestRouteCost / (double)currentStats.AlgResult; tickCounter += _stopwatch.ElapsedTicks; testCount++; } double averageTimeMicro = TicksToMicroseconds(tickCounter) / testCount; currentStats.PrevTimeMicro = currentStats.TimeMicro; currentStats.TimeMicro = averageTimeMicro; // Need to keep a dictionary of previous times for doubling calculation on this alg. currentStats.PrevTimesTable.TryAdd(currentStats.n, averageTimeMicro); doublingCalc(currentStats); PrintData(currentStats); // New Row Console.WriteLine(); } }