use of aima.core.search.framework.problem.GeneralProblem 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.framework.problem.GeneralProblem in project aima-java by aimacode.
the class BreadthFirstSearchTest method testBreadthFirstSuccesfulSearch.
@Test
public void testBreadthFirstSuccesfulSearch() throws Exception {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(8), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
SearchForActions<NQueensBoard, QueenAction> search = new BreadthFirstSearch<>(new TreeSearch<>());
List<QueenAction> actions = search.findActions(problem);
assertCorrectPlacement(actions);
Assert.assertEquals("1665", search.getMetrics().get("nodesExpanded"));
Assert.assertEquals("8.0", search.getMetrics().get("pathCost"));
}
use of aima.core.search.framework.problem.GeneralProblem in project aima-java by aimacode.
the class BreadthFirstSearchTest method testBreadthFirstUnSuccesfulSearch.
@Test
public void testBreadthFirstUnSuccesfulSearch() throws Exception {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(3), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
SearchForActions<NQueensBoard, QueenAction> search = new BreadthFirstSearch<>(new TreeSearch<>());
SearchAgent<NQueensBoard, QueenAction> agent = new SearchAgent<>(problem, search);
List<Action> actions = agent.getActions();
Assert.assertEquals(0, actions.size());
Assert.assertEquals("6", agent.getInstrumentation().getProperty("nodesExpanded"));
Assert.assertEquals("0", agent.getInstrumentation().getProperty("pathCost"));
}
use of aima.core.search.framework.problem.GeneralProblem in project aima-java by aimacode.
the class DepthFirstSearchTest method testDepthFirstUnSuccessfulSearch.
@Test
public void testDepthFirstUnSuccessfulSearch() throws Exception {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(3), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
SearchForActions<NQueensBoard, QueenAction> search = new DepthFirstSearch<>(new GraphSearch<>());
SearchAgent<NQueensBoard, QueenAction> agent = new SearchAgent<>(problem, search);
List<Action> actions = agent.getActions();
Assert.assertEquals(0, actions.size());
Assert.assertEquals("6", agent.getInstrumentation().getProperty("nodesExpanded"));
}
use of aima.core.search.framework.problem.GeneralProblem in project aima-java by aimacode.
the class DepthLimitedSearchTest method testCutOff.
@Test
public void testCutOff() throws Exception {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(8), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
DepthLimitedSearch<NQueensBoard, QueenAction> search = new DepthLimitedSearch<>(1);
Node<NQueensBoard, QueenAction> result = search.findNode(problem);
Assert.assertEquals(true, search.isCutoffNode(result));
}
Aggregations