static int _runFinder(IFinder finder, IHeuristic h, IMap map, bool window, bool noshow, int blocksize, int sleep) { if (!noshow) { if (sleep > 0) { finder.SleepUITimeInMs = sleep; } var viewer = window ? ViewerFactory.GetOpenGlViewerImplementation(blocksize) : ViewerFactory.GetConsoleViewerImplementation(); viewer.SetFinder(finder); viewer.Run(map, h); } else { if (finder.Find(map, h)) { var path = map.GetPath(); AbstractViewer.ShowEndLog(finder, path, new Pathfinder.Abstraction.FinderEventArgs { Finded = true, GridMap = map, ExpandedNodesCount = map.GetMaxExpandedNodes(), PassedTimeInMs = finder.GetProcessedTime(), Step = 0 }); var result = FileTool.GetTextRepresentation(map, false, path); if (!window) { Console.WriteLine(result); } else { MapViewWindow.OpenGlWindow(result, blocksize); } } else { Console.WriteLine("Cant find a path"); } } return(0); }
static TextWrapper RunStep(TextWrapper baseScv, int i, int fileCount, IMap map, IHeuristic h, IFinder finder, string path, string mapName, string plus = "") { var csv = baseScv; csv.MapNumber = i.ToString(); csv.MapTypeGenerate = map.MapType.ToString(); csv.Alg = finder.Name; csv.Heuristic = h.GetType().Name; csv.MapDiagonal = map.Diagonal.ToString(); csv.MapSize = $"{map.Width}x{map.Height}"; Console.CursorLeft = 0; if (Console.CursorTop > 0) { Console.Write(new string(' ', 80)); Console.CursorLeft = 0; } Console.WriteLine($" ({i}) {csv.Alg} - { csv.Heuristic } - {csv.MapDiagonal} ({csv.MapSize}/{csv.MapTypeGenerate})"); DrawTextProgressBar(i, fileCount); if (finder.Find(map, h)) { csv.PathLength = map.GetPath().OrderBy(x => x.G).Last().G.ToString(); Console.ForegroundColor = ConsoleColor.Green; csv.Solution = "Yes"; } else { csv.Solution = "No"; csv.PathLength = "-1"; Console.ForegroundColor = ConsoleColor.Red; } map.Clear(); csv.Time = finder.GetProcessedTime().ToString(); csv.MaxNodes = map.GetMaxExpandedNodes().ToString(); Console.CursorTop -= 1; Console.CursorLeft = 0; Console.WriteLine($"{csv.Solution}-{csv.Time}ms"); Console.ForegroundColor = ConsoleColor.White; // save solutions var solutionPath = Path.Combine(path, "solutions", map.MapType.ToString(), finder.GetType().Name, h.GetType().Name); var fileName = mapName; if (finder is IGeneticAlgorithm ga) { solutionPath = Path.Combine(solutionPath, ga.Fitness.GetType().Name, ga.Selection.GetType().Name); fileName = $"{Path.GetFileNameWithoutExtension(fileName)}_{ga.Mutate.GetType().Name}_{ga.Crossover.GetType().Name}_{i}.txt"; } if (!Directory.Exists(solutionPath)) { Directory.CreateDirectory(solutionPath); } var text = FileTool.GetTextRepresentation(map, false, map.GetPath()); File.WriteAllText(Path.Combine(solutionPath, fileName), text); return(csv); }
public static void ShowEndLog(IFinder finder, IEnumerable <Node> path, FinderEventArgs e) { if (path?.Any(x => !x.Walkable) ?? false) { throw new Exception("Why is there a wall on the path?"); } Console.WriteLine($"Alg={finder.Name}\nDiagonal={e.GridMap.Diagonal.ToString()}\nMax Expanded Nodes = {e.GridMap.GetMaxExpandedNodes()}\nProcess Time = {finder.GetProcessedTime()} ms\nSteps|Generation:{e.Step}"); if (e.Finded) { Console.WriteLine($"Path Length: {path.OrderBy(x => x.G).Last().G}"); } else { Console.WriteLine("CANT FIND A PATH!"); } Console.ReadKey(); }
public static void ShowStepLog(IFinder finder, FinderEventArgs e) { Console.WriteLine($"Alg={finder.Name}\nDiagonal={e.GridMap.Diagonal.ToString()}\nMax Expanded Nodes = {e.GridMap.GetMaxExpandedNodes()}\nProcess Time = {finder.GetProcessedTime()} ms\nSteps|Generations:{e.Step} "); }