protected Algorithm(int populationSize, StopCondition <TAlgorithm, TProblem, TSolution> stopCondition, MainOperator <TAlgorithm, TProblem, TSolution> mainOperator) { Assert(populationSize > 0); Stopwatch = new Stopwatch(); RunStatistic = new RunStatistic(); Problem = null; Population = new TSolution[populationSize]; for (int i = 0; i < Population.Length; i++) { Population[i] = new TSolution(); } Best = new TSolution { Fitness = double.MinValue }; Random = null; StopCondition = stopCondition.DeepClone(); MainOperator = mainOperator.DeepClone(); }
private FunctionStatistic TestCase(TAlgorithm algorithm, TProblem problem) { _progressCounter++; Console.WriteLine($"{_progressCounter}/{_maxProgress}"); var runStatistics = new RunStatistic[NumberOfRuns]; if (IsParallelTestingPossible && !algorithm.IsParallel) { Parallel.For(0, NumberOfRuns, i => runStatistics[i] = TestRun(algorithm, problem, i)); } else { for (var i = 0; i < NumberOfRuns; i++) { runStatistics[i] = TestRun(algorithm, problem, i); } } Writer.Write($"{algorithm.Name}_{problem.Name}", RunStatistic.Header, runStatistics); return(new FunctionStatistic(problem.Name, runStatistics)); }