Exemplo n.º 1
0
        public static BenchmarkScenarioResult Run <TNode>(
            BenchmarkScenario <TNode> scenario, ILevelGeneratorFactory <TNode> levelGeneratorFactory, int repeats, Legacy.Benchmarks.BenchmarkOptions options = null)
        {
            if (options == null)
            {
                options = new Legacy.Benchmarks.BenchmarkOptions();
            }

            var benchmarkJobs = new List <BenchmarkJob>();
            var benchmark     = options.MultiThreaded
                ? new BenchmarkUtils.MultiThreadedBenchmark <BenchmarkJob, BenchmarkJobResult>(options.MaxDegreeOfParallelism)
                : new BenchmarkUtils.Benchmark <BenchmarkJob, BenchmarkJobResult>();

            benchmark.SetConsoleOutput(options.WithConsoleOutput, options.WithConsolePreview);

            // TODO: this should be more configurable
            if (options.WithFileOutput)
            {
                benchmark.AddFileOutput();
            }

            foreach (var input in scenario.LevelDescriptions)
            {
                var runner = levelGeneratorFactory.GetGeneratorRunner(input);

                benchmarkJobs.Add(new BenchmarkJob(runner, input.Name, repeats, 0.8));
            }

            var benchmarkJobResults = benchmark.Run(benchmarkJobs.ToArray(), $"{scenario.Name} - {levelGeneratorFactory.Name}");

            return(new BenchmarkScenarioResult($"{scenario.Name} - {levelGeneratorFactory.Name}",
                                               benchmarkJobResults.Select(x => new BenchmarkResult(x.InputName, x.Runs.ToList())).ToList()));
        }
Exemplo n.º 2
0
        protected virtual BenchmarkScenarioResult RunBenchmark <TNode>(BenchmarkScenario <TNode> scenario, ILevelGeneratorFactory <TNode> generator, int iterations)
        {
            var scenarioResult = BenchmarkRunner.Run(scenario, generator, iterations, new Legacy.Benchmarks.BenchmarkOptions()
            {
                WithConsolePreview     = Options.WithConsolePreview,
                MultiThreaded          = Options.MaxThreads > 1,
                MaxDegreeOfParallelism = Options.MaxThreads,
                WithFileOutput         = false,
            });

            var resultSaver = new BenchmarkResultSaver();

            resultSaver.SaveResultDefaultLocation(scenarioResult, directory: DirectoryFullPath, name: $"{Directory}_{scenario.Name}_{generator.Name}", withDatetime: false);

            return(scenarioResult);
        }
Exemplo n.º 3
0
 public Simulator(ILevelGeneratorFactory levelGeneratorFactory, IRoverFactory roverFactory, IAiFactory aiFactory)
 {
     LevelGeneratorFactory = levelGeneratorFactory ?? throw new ArgumentNullException(nameof(levelGeneratorFactory));
     RoverFactory          = roverFactory ?? throw new ArgumentNullException(nameof(roverFactory));
     AiFactory             = aiFactory ?? throw new ArgumentNullException(nameof(aiFactory));
 }
Exemplo n.º 4
0
 public OpenCheckingGeneratorFactory(ILevelGeneratorFactory wrappedFactory, Int32 minimumContiguousTiles)
 {
     _wrappedFactory        = wrappedFactory ?? throw new ArgumentNullException(nameof(wrappedFactory));
     MinimumContiguousTiles = minimumContiguousTiles >= 0 ? minimumContiguousTiles : throw new ArgumentOutOfRangeException(nameof(minimumContiguousTiles));
 }