use of aima.core.search.informed.GreedyBestFirstSearch in project aima-java by aimacode.
the class GreedyBestFirstSearchTest method testGreedyBestFirstSearch.
@Test
public void testGreedyBestFirstSearch() {
try {
// EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
// {2,0,5,6,4,8,3,7,1});
// EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
// {0,8,7,6,5,4,3,2,1});
EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8, 0, 4, 6, 2, 3, 5 });
Problem<EightPuzzleBoard, Action> problem = new BidirectionalEightPuzzleProblem(board);
SearchForActions<EightPuzzleBoard, Action> search = new GreedyBestFirstSearch<>(new GraphSearch<>(), EightPuzzleFunctions.createManhattanHeuristicFunction());
SearchAgent<EightPuzzleBoard, Action> agent = new SearchAgent<>(problem, search);
// GraphSearchReducedFrontier: "49"
Assert.assertEquals(49, agent.getActions().size());
// GraphSearchReducedFrontier: "197"
Assert.assertEquals(// GraphSearchReducedFrontier: "197"
"332", agent.getInstrumentation().getProperty("nodesExpanded"));
// GraphSearchReducedFrontier: "140"
Assert.assertEquals(// GraphSearchReducedFrontier: "140"
"241", agent.getInstrumentation().getProperty("queueSize"));
// GraphSearchReducedFrontier: "141"
Assert.assertEquals(// GraphSearchReducedFrontier: "141"
"242", agent.getInstrumentation().getProperty("maxQueueSize"));
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception thrown.");
}
}
use of aima.core.search.informed.GreedyBestFirstSearch in project aima-java by aimacode.
the class GreedyBestFirstSearchTest method testAIMA3eFigure3_23_using_GraphSearch.
@Test
public void testAIMA3eFigure3_23_using_GraphSearch() throws Exception {
Map romaniaMap = new SimplifiedRoadMapOfPartOfRomania();
Problem<String, MoveToAction> problem = new GeneralProblem<>(SimplifiedRoadMapOfPartOfRomania.ARAD, MapFunctions.createActionsFunction(romaniaMap), MapFunctions.createResultFunction(), GoalTest.isEqual(SimplifiedRoadMapOfPartOfRomania.BUCHAREST), MapFunctions.createDistanceStepCostFunction(romaniaMap));
SearchForActions<String, MoveToAction> search = new GreedyBestFirstSearch<>(new GraphSearch<>(), MapFunctions.createSLDHeuristicFunction(SimplifiedRoadMapOfPartOfRomania.BUCHAREST, romaniaMap));
SearchAgent<String, MoveToAction> agent = new SearchAgent<>(problem, search);
Assert.assertEquals("[Action[name==moveTo, location==Sibiu], Action[name==moveTo, location==Fagaras], Action[name==moveTo, location==Bucharest]]", agent.getActions().toString());
Assert.assertEquals(3, agent.getActions().size());
Assert.assertEquals("3", agent.getInstrumentation().getProperty("nodesExpanded"));
Assert.assertEquals("4", agent.getInstrumentation().getProperty("queueSize"));
Assert.assertEquals("5", agent.getInstrumentation().getProperty("maxQueueSize"));
}
use of aima.core.search.informed.GreedyBestFirstSearch in project aima-java by aimacode.
the class GreedyBestFirstSearchTest method testAIMA3eFigure3_23.
@Test
public void testAIMA3eFigure3_23() throws Exception {
Map romaniaMap = new SimplifiedRoadMapOfPartOfRomania();
Problem<String, MoveToAction> problem = new GeneralProblem<>(SimplifiedRoadMapOfPartOfRomania.ARAD, MapFunctions.createActionsFunction(romaniaMap), MapFunctions.createResultFunction(), GoalTest.isEqual(SimplifiedRoadMapOfPartOfRomania.BUCHAREST), MapFunctions.createDistanceStepCostFunction(romaniaMap));
SearchForActions<String, MoveToAction> search = new GreedyBestFirstSearch<>(new TreeSearch<>(), MapFunctions.createSLDHeuristicFunction(SimplifiedRoadMapOfPartOfRomania.BUCHAREST, romaniaMap));
SearchAgent<String, MoveToAction> agent = new SearchAgent<>(problem, search);
Assert.assertEquals("[Action[name==moveTo, location==Sibiu], Action[name==moveTo, location==Fagaras], Action[name==moveTo, location==Bucharest]]", agent.getActions().toString());
Assert.assertEquals(3, agent.getActions().size());
Assert.assertEquals("3", agent.getInstrumentation().getProperty("nodesExpanded"));
Assert.assertEquals("6", agent.getInstrumentation().getProperty("queueSize"));
Assert.assertEquals("7", agent.getInstrumentation().getProperty("maxQueueSize"));
}
use of aima.core.search.informed.GreedyBestFirstSearch in project aima-java by aimacode.
the class GreedyBestFirstSearchTest method testGreedyBestFirstSearchReducedFrontier.
@Test
public void testGreedyBestFirstSearchReducedFrontier() {
try {
// EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
// {2,0,5,6,4,8,3,7,1});
// EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
// {0,8,7,6,5,4,3,2,1});
EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8, 0, 4, 6, 2, 3, 5 });
Problem<EightPuzzleBoard, Action> problem = new BidirectionalEightPuzzleProblem(board);
QueueBasedSearch<EightPuzzleBoard, Action> search = new GreedyBestFirstSearch<>(new GraphSearchReducedFrontier<>(), EightPuzzleFunctions.createManhattanHeuristicFunction());
SearchAgent<EightPuzzleBoard, Action> agent = new SearchAgent<>(problem, search);
Assert.assertEquals(49, agent.getActions().size());
Assert.assertEquals("197", agent.getInstrumentation().getProperty("nodesExpanded"));
Assert.assertEquals("140", agent.getInstrumentation().getProperty("queueSize"));
Assert.assertEquals("141", agent.getInstrumentation().getProperty("maxQueueSize"));
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception thrown.");
}
}
Aggregations