Пример #1
0
        private TotalTestResults runAllTestSuites(List<TestSuiteEntry> tests, BackgroundWorker worker)
        {
            int maxProgress = 0;
            foreach (TestSuiteEntry t in tests)
            {
                if (t.AlgorithmType.Equals("ALL"))
                {
                    maxProgress += (t.NumberOfIterations * _implementedMethods.Count);
                }
                else
                {
                    maxProgress += t.NumberOfIterations;
                }
            }
            TotalTestResults totalResults = new TotalTestResults();
            TestSuiteProgressData progressData = new TestSuiteProgressData(ReasonableTime, 1, 1, 1, maxProgress);
            progressData.MaxTestProgress = tests.Count;
            progressData.CurrentTestProgress = 0;
            worker.ReportProgress(0, progressData);
            for (int testIndex = 0; testIndex < tests.Count; testIndex++ )
            {
                TestSuiteEntry curTest = tests[testIndex];
                Log("Running test suite: {0}: {1}/{2}", curTest.ToString(), (testIndex+1), tests.Count);
                progressData.CurrentTest = curTest.ToString();
                progressData.MaxIterationProgress = curTest.NumberOfIterations;
                progressData.CurrentIterationProgress = 0;
                progressData.MaxMethodProgress = _implementedMethods.Count;
                progressData.CurrentMethodProgress = 0;
                progressData.CurrentTestProgress++;
                worker.ReportProgress(progressData.CompletionPercentage, progressData);

                if (curTest.AlgorithmType.Equals("ALL"))
                {
                    foreach (MethodInfo method in _implementedMethods)
                    {
                        progressData.CurrentMethodProgress++;
                        progressData.CurrentMethod = method.Name;
                        worker.ReportProgress(progressData.CompletionPercentage, progressData);
                        SingleTestResult average = runAllTestIterations(curTest, method, worker, progressData);
                        totalResults.StoreResult(curTest.NumberCities, method.Name, average);
                    }
                }
                else
                {
                    MethodInfo chosenMethod = null;
                    foreach (MethodInfo method in _implementedMethods)
                    {
                        if (method.Name.Equals(curTest.AlgorithmType))
                        {
                            chosenMethod = method;
                        }
                    }
                    if (chosenMethod != null)
                    {
                        progressData.MaxMethodProgress = 1;
                        progressData.CurrentMethodProgress++;
                        progressData.CurrentMethod = chosenMethod.Name;
                        worker.ReportProgress(progressData.CompletionPercentage, progressData);
                        SingleTestResult value = runAllTestIterations(curTest, chosenMethod, worker, progressData);
                        totalResults.StoreResult(curTest.NumberCities, chosenMethod.Name, value);
                    }
                    else
                    {
                        Log("Chosen Algorithm: {0} does not exist!", curTest.AlgorithmType);
                    }
                }

            }
            return totalResults;
        }
Пример #2
0
 private SingleTestResult runTestIteration(int seed, int numCities, MethodInfo implementation,
     BackgroundWorker worker, TestSuiteProgressData progressData)
 {
     ProblemAndSolver ps = new ProblemAndSolver(seed, numCities);
     ps.UpdateForm = false;
     Stopwatch sw = new Stopwatch();
     sw.Start();
     implementation.Invoke(ps, new object[]{});
     sw.Start();
     return new SingleTestResult(ps.costOfBssf(), sw.ElapsedMilliseconds / 1000d);
 }
Пример #3
0
        private SingleTestResult runAllTestIterations(TestSuiteEntry curTest, MethodInfo implementation,
            BackgroundWorker worker, TestSuiteProgressData progressData)
        {
            List<SingleTestResult> _allTestResults = new List<SingleTestResult>();

            for (int i = 0; i < curTest.NumberOfIterations; i++)
            {
                Log("Running {0} iteration: {1}/{2}", implementation.Name, (i + 1), curTest.NumberOfIterations);
                progressData.CurrentIterationProgress++;
                progressData.CurrentMaxProgress++;
                worker.ReportProgress(progressData.CompletionPercentage, progressData);
                Random random = new Random();
                int seed = random.Next(1000); // 3-digit random number
                SingleTestResult thisRun = runTestIteration(seed, curTest.NumberCities, implementation,
                    worker, progressData);
                _allTestResults.Add(thisRun);
                Log("Result was {0}", thisRun);
            }
            double averageTime = 0;
            double averageDistance = 0;
            foreach (SingleTestResult s in _allTestResults)
            {
                averageTime += s.TimeInSeconds;
                averageDistance += s.Distance;
            }
            averageTime /= curTest.NumberOfIterations;
            averageDistance /= curTest.NumberOfIterations;

            SingleTestResult averageTestResult = new SingleTestResult(averageDistance, averageTime);
            Log("Average test result was {0}", averageTestResult.ToString());
            progressData.MostRecentSolution = String.Format("{0} Number of cities with function {1} and {2} iterations" +
                " took {3} seconds with cost of {4}", curTest.NumberCities, implementation.Name, curTest.NumberOfIterations,
                averageTestResult.TimeInSeconds, averageTestResult.Distance);
            worker.ReportProgress(progressData.CompletionPercentage, progressData);
            return averageTestResult;
        }