Exemple #1
0
        private void PrintResults(ExperimentResult result)
        {
            _outputWriter.Print($"Average shortest path - { result.AverageShortestPath } ");
            _outputWriter.Print($"Average generation time - { result.AverageGenerationTime } ");
            _outputWriter.Print("Average direction weightings: ");
            var strings = result.DirectionWeightings.Select(x => $"{x.Key} - {x.Value}");

            _outputWriter.Print(string.Join(", ", strings) + " ");
            _outputWriter.PrintLn($"Average cells filled in - { result.AverageCellsFilledIn }");
        }
Exemple #2
0
        private ExperimentResult RunExperiment(MazeGenerationSettings settings, int iterations, bool parallel)
        {
            var batch = iterations / 100;
            int count = 0;
            List <MazeResults> items = null;

            if (parallel)
            {
                items = GenerateMazesParallel(settings, iterations).Select(x =>
                {
                    count++;
                    if (count % batch == 0)
                    {
                        _outputWriter.Print($"{count/batch}% ");
                    }

                    return(x);
                }).ToList();
            }
            else
            {
                items = GenerateMazes(settings, iterations).Select(x =>
                {
                    count++;
                    if (count % batch == 0)
                    {
                        _outputWriter.Print($"{count / batch}% ");
                    }

                    return(x);
                }).ToList();
            }
            var  doubleAverageTicks = _arrayHelper.Average(items, x => x.TotalTime.Ticks);
            long longAverageTicks   = Convert.ToInt64(doubleAverageTicks);
            var  result             = new ExperimentResult
            {
                AverageShortestPath   = _arrayHelper.Average(items, x => x.ShortestPath),
                AverageGenerationTime = new TimeSpan(longAverageTicks),
                DirectionWeightings   = _directionsFlagParser.Directions.ToDictionary(x => x, y => _arrayHelper.Average(items, z => z.Stats.DirectionsUsed[y])),
                AverageCellsFilledIn  = _arrayHelper.Average(items, x => x.TotalCellsFilledIn)
            };

            return(result);
        }