private static void Main(string[] args) { // the maze size 100x100 int col = 100; int row = 100; // create maze with DFSMazeGenerator DFSMazeGenerator generator = new DFSMazeGenerator(); Maze maze = generator.Generate(col, row); // print the maze Console.Write(maze.ToString()); // adapt the maze and solve it with BFS ISearchable <Position> adapter = new MazeAdapter(maze); ISearcher <Position> bfsSearcher = new BestFirstSearch <Position>(); bfsSearcher.Search(adapter); int bfsNumOfStases = bfsSearcher.GetNumberOfNodesEvaluated(); // solve the maze with DFS ISearcher <Position> dfsSearcher = new DepthFirstSearch <Position>(); dfsSearcher.Search(adapter); int dfsNumOfStases = dfsSearcher.GetNumberOfNodesEvaluated(); // print the num of evalueted nodes for BFS and DFS Console.WriteLine("number of BFS states:" + bfsNumOfStases); Console.WriteLine("number of DFS states:" + dfsNumOfStases); Console.Read(); }
/// <summary> /// Solves the maze BFS. /// </summary> /// <param name="name">The name.</param> /// <returns>Solution</returns> public Solution <Position> solveMazeBFS(string name) { modelData.mutexBfs.WaitOne(); Solution <Position> solution = null; // Check if the maze exist. if (modelData.Mazes.ContainsKey(name)) { ISearchable <Position> mazeObjectAdapter = new MazeAdapter(modelData.Mazes[name]); ISearcher <Position> BFS = new BestFirstSearch <Position>(); // Check if the solution exist. if (modelData.BfsSolutions.ContainsKey(name)) { solution = modelData.BfsSolutions[name]; } else { // Calculate the solution. solution = BFS.Search(mazeObjectAdapter); modelData.BfsSolutions.Add(name, solution); } } State <Position> .StatePool.Clear(); modelData.mutexBfs.ReleaseMutex(); return(solution); }
public LinkedList <string> calcFastestWay(string source, string dest) { BestFirstSearch bfs = new BestFirstSearch(); bfs.BuildGraph(); bfs.Search(source, dest, "time"); return(bfs.path); }
/// <summary> /// Compares the solvers. /// </summary> public static void CompareSolvers() { DFSMazeGenerator generator = new DFSMazeGenerator(); Maze maze = generator.Generate(10, 10); //Console.WriteLine(maze); ISearchable <Position> mazeAdapter = new MazeAdapter(maze); ISearcher <Position> bfs = new BestFirstSearch <Position>(); ISearcher <Position> dfs = new Dfs <Position>(); Solution <Position> solution = bfs.Search(mazeAdapter); Console.WriteLine("bfs sol:" + solution.EvaluatedNodes); Console.WriteLine(mazeAdapter.ToString(solution)); solution = dfs.Search(mazeAdapter); Console.WriteLine("dfs sol:" + solution.EvaluatedNodes); Console.WriteLine(mazeAdapter.ToString(solution)); }
public IEnumerable <Operator> GetBestFirst() { AbstractSearch searcher = new BestFirstSearch(); return(searcher.Search()); }