private static void printTestToConsole(List <InputSet> inputsets, bool isLargeScale) { int bound = isLargeScale ? inputsets.Count - 1 : inputsets.Count; for (int i = 0; i < bound; i++) { Test.printTest(inputsets[i], i + 1, greedy.Solve(inputsets[i]), memory.Solve(inputsets[i]), dynamic.Solve(inputsets[i])); } }
public void Main() { while (true) { _seed = (new Random().Next(10000000, 99999999)); if (ShowMenu()) { break; } var rnd = new Random(_seed); MakeWorld(rnd); var worldSize = Math.Sqrt(_world.XSize * _world.XSize + _world.YSize + _world.YSize); var targetSize = (int)(worldSize * 0.95); Position randomFromNode = null; Position randomToNode = null; IList <Position> path = null; var tries = 0; while (path == null) { tries++; if (tries > 5000) { break; } do { randomFromNode = _world.GetPosition(rnd.Next(0, _world.XSize - 1), rnd.Next(0, _world.YSize - 1)); }while (randomFromNode == null); do { randomToNode = _world.GetPosition(rnd.Next(0, _world.XSize - 1), rnd.Next(0, _world.YSize - 1)); }while (randomToNode == null); var x = Math.Abs(randomFromNode.X - randomToNode.X); var y = Math.Abs(randomFromNode.Y - randomToNode.Y); var dist = Math.Sqrt(x * x + y * y); if (dist < targetSize) { continue; } Greedy <Position> .Solve(randomFromNode, randomToNode, out path); } if (path == null) { continue; } var aStars = new Dictionary <double, AStar <Position> >(); _worldWriter.DrawWorld(); _worldWriter.DrawSeed(_seed); var i = 0; foreach (var greedyFactor in _greedyFactors) { var timer = new Stopwatch(); var aStar = RunPathFinder(randomFromNode, randomToNode, greedyFactor, timer); aStars.Add(greedyFactor, aStar); _worldWriter.WriteResult(i, greedyFactor, aStar.PathCost, aStar.Ticks, timer.ElapsedTicks); i++; } IList <Position> previous = null; while (true) { var key = System.Console.ReadKey(true); if (key.Key == ConsoleKey.Q || key.Key == ConsoleKey.Enter) { break; } if (!int.TryParse(key.KeyChar.ToString(), out var num) && num < _greedyFactors.Count && aStars[_greedyFactors[num]].State == SolverState.Success) { continue; } if (previous != null) { ClearPath(previous); } if (num < _greedyFactors.Count) { previous = aStars[_greedyFactors[num]].Path; if (previous != null) { DrawPath(previous, num); } } } } }
public int Greedy() => greedy.Solve(inputSet);