use of aima.core.environment.nqueens.QueenAction 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));
}
use of aima.core.environment.nqueens.QueenAction in project aima-java by aimacode.
the class IterativeDeepeningSearchTest method testIterativeDeepeningSearch.
@Test
public void testIterativeDeepeningSearch() {
try {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(8), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
SearchForActions<NQueensBoard, QueenAction> search = new IterativeDeepeningSearch<>();
List<QueenAction> actions = search.findActions(problem);
assertCorrectPlacement(actions);
Assert.assertEquals("3656", search.getMetrics().get("nodesExpanded"));
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception should not occur");
}
}
use of aima.core.environment.nqueens.QueenAction in project aima-java by aimacode.
the class UniformCostSearchTest method testUniformCostUnSuccesfulSearch.
@Test
public void testUniformCostUnSuccesfulSearch() throws Exception {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(3), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
SearchForActions<NQueensBoard, QueenAction> search = new UniformCostSearch<>();
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"));
// Will be 0 as did not reach goal state.
Assert.assertEquals("0", agent.getInstrumentation().getProperty("pathCost"));
}
Aggregations