Question: This is the code for 8 puzzle public class EightPuzzleDemo { static EightPuzzleBoard boardWithThreeMoveSolution = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 4, 0,
This is the code for 8 puzzle
public class EightPuzzleDemo { static EightPuzzleBoard boardWithThreeMoveSolution = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 4, 0, 6, 7, 8 });;
static EightPuzzleBoard random1 = new EightPuzzleBoard(new int[] { 1, 4, 2, 7, 5, 8, 3, 0, 6 });
static EightPuzzleBoard extreme = new EightPuzzleBoard(new int[] { 0, 8, 7, 6, 5, 4, 3, 2, 1 });
public static void main(String[] args) { eightPuzzleDLSDemo(); eightPuzzleIDLSDemo(); eightPuzzleGreedyBestFirstDemo(); eightPuzzleGreedyBestFirstManhattanDemo(); eightPuzzleAStarDemo(); eightPuzzleAStarManhattanDemo(); eightPuzzleSimulatedAnnealingDemo(); }
private static void eightPuzzleDLSDemo() { System.out.println(" EightPuzzleDemo recursive DLS (9) -->"); try { Problem problem = new Problem(boardWithThreeMoveSolution, EightPuzzleFunctionFactory.getActionsFunction(), EightPuzzleFunctionFactory.getResultFunction(), new EightPuzzleGoalTest()); SearchForActions search = new DepthLimitedSearch(9); SearchAgent agent = new SearchAgent(problem, search); printActions(agent.getActions()); printInstrumentation(agent.getInstrumentation()); } catch (Exception e) { e.printStackTrace(); }
}
private static void eightPuzzleIDLSDemo() { System.out.println(" EightPuzzleDemo Iterative DLS -->"); try { Problem problem = new Problem(random1, EightPuzzleFunctionFactory.getActionsFunction(), EightPuzzleFunctionFactory.getResultFunction(), new EightPuzzleGoalTest()); SearchForActions search = new IterativeDeepeningSearch(); SearchAgent agent = new SearchAgent(problem, search); printActions(agent.getActions()); printInstrumentation(agent.getInstrumentation()); } catch (Exception e) { e.printStackTrace(); }
}
private static void eightPuzzleGreedyBestFirstDemo() { System.out.println(" EightPuzzleDemo Greedy Best First Search (MisplacedTileHeursitic)-->"); try { Problem problem = new Problem(boardWithThreeMoveSolution, EightPuzzleFunctionFactory.getActionsFunction(), EightPuzzleFunctionFactory.getResultFunction(), new EightPuzzleGoalTest()); SearchForActions search = new GreedyBestFirstSearch(new GraphSearch(), new MisplacedTilleHeuristicFunction()); SearchAgent agent = new SearchAgent(problem, search); printActions(agent.getActions()); printInstrumentation(agent.getInstrumentation()); } catch (Exception e) { e.printStackTrace(); }
}
private static void eightPuzzleGreedyBestFirstManhattanDemo() { System.out.println(" EightPuzzleDemo Greedy Best First Search (ManhattanHeursitic)-->"); try { Problem problem = new Problem(boardWithThreeMoveSolution, EightPuzzleFunctionFactory.getActionsFunction(), EightPuzzleFunctionFactory.getResultFunction(), new EightPuzzleGoalTest()); SearchForActions search = new GreedyBestFirstSearch(new GraphSearch(), new ManhattanHeuristicFunction()); SearchAgent agent = new SearchAgent(problem, search); printActions(agent.getActions()); printInstrumentation(agent.getInstrumentation()); } catch (Exception e) { e.printStackTrace(); }
}
private static void eightPuzzleAStarDemo() { System.out.println(" EightPuzzleDemo AStar Search (MisplacedTileHeursitic)-->"); try { Problem problem = new Problem(random1, EightPuzzleFunctionFactory.getActionsFunction(), EightPuzzleFunctionFactory.getResultFunction(), new EightPuzzleGoalTest()); SearchForActions search = new AStarSearch(new GraphSearch(), new MisplacedTilleHeuristicFunction()); SearchAgent agent = new SearchAgent(problem, search); printActions(agent.getActions()); printInstrumentation(agent.getInstrumentation()); } catch (Exception e) { e.printStackTrace(); }
}
private static void eightPuzzleSimulatedAnnealingDemo() { System.out.println(" EightPuzzleDemo Simulated Annealing Search -->"); try { Problem problem = new Problem(random1, EightPuzzleFunctionFactory.getActionsFunction(), EightPuzzleFunctionFactory.getResultFunction(), new EightPuzzleGoalTest()); SimulatedAnnealingSearch search = new SimulatedAnnealingSearch(new ManhattanHeuristicFunction()); SearchAgent agent = new SearchAgent(problem, search); printActions(agent.getActions()); System.out.println("Search Outcome=" + search.getOutcome()); System.out.println("Final State= " + search.getLastSearchState()); printInstrumentation(agent.getInstrumentation()); } catch (Exception e) { e.printStackTrace(); } }
private static void eightPuzzleAStarManhattanDemo() { System.out.println(" EightPuzzleDemo AStar Search (ManhattanHeursitic)-->"); try { Problem problem = new Problem(random1, EightPuzzleFunctionFactory.getActionsFunction(), EightPuzzleFunctionFactory.getResultFunction(), new EightPuzzleGoalTest()); SearchForActions search = new AStarSearch(new GraphSearch(), new ManhattanHeuristicFunction()); SearchAgent agent = new SearchAgent(problem, search); printActions(agent.getActions()); printInstrumentation(agent.getInstrumentation()); } catch (Exception e) { e.printStackTrace(); }
}
private static void printInstrumentation(Properties properties) { Iterator
}
private static void printActions(List
}
2nd Code Random 8 puzzle
package aima.gui.demo.search;
import java.util.Random;
import aima.core.environment.eightpuzzle.EightPuzzleBoard;
/** * @author Ravi Mohan * */
public class GenerateRandomEightPuzzleDemo { public static void main(String[] args) { Random r = new Random(); EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }); for (int i = 0; i < 50; i++) { int th = r.nextInt(4); if (th == 0) { board.moveGapUp(); } if (th == 1) { board.moveGapDown(); } if (th == 2) { board.moveGapLeft(); } if (th == 3) { board.moveGapRight(); } } System.out.println(board); }
}
Question:
- Modify the DLS to simulate depth-first search. Find the best depth-limit prove that this is indeed the best depth-limit. Find the worth depth-limit based on your experiments. Provide a log of all experiments and the results to support you answer.
- Compare the performance of A* and recursive best-first search on a set of randomly generated problems with Manhattan distance heuristic. Discuss your results.
- Compare the performance of A* with Manhattan distance and A* with Misplaced tiles Heuristic on randomly generated problems. Explain the differences.
If you could help in this really thankfull to u
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
