use of aima.core.environment.nqueens.QueenAction in project aima-java by aimacode.
the class DepthLimitedSearchTest method testSuccessfulDepthLimitedSearch.
@Test
public void testSuccessfulDepthLimitedSearch() throws Exception {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(8), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
SearchForActions<NQueensBoard, QueenAction> search = new DepthLimitedSearch<>(8);
List<QueenAction> actions = search.findActions(problem);
assertCorrectPlacement(actions);
Assert.assertEquals("113", search.getMetrics().get("nodesExpanded"));
}
use of aima.core.environment.nqueens.QueenAction in project aima-java by aimacode.
the class NQueensFunctionsTest method testSimpleBoardSuccessorGenerator.
@Test
public void testSimpleBoardSuccessorGenerator() {
List<QueenAction> actions = new ArrayList<>(actionsFn.apply(oneBoard));
Assert.assertEquals(1, actions.size());
NQueensBoard next = resultFn.apply(oneBoard, actions.get(0));
Assert.assertEquals(1, next.getNumberOfQueensOnBoard());
}
use of aima.core.environment.nqueens.QueenAction 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.environment.nqueens.QueenAction 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.environment.nqueens.QueenAction 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"));
}
Aggregations