use of aima.core.environment.nqueens.QueenAction in project aima-java by aimacode.
the class NQueensSearchDemo method startExperiment.
public void startExperiment(SearchForActions<NQueensBoard, QueenAction> search) {
search.addNodeListener(n -> notifyProgressTrackers(n.getState(), search.getMetrics()));
Problem<NQueensBoard, QueenAction> problem;
if (board.getNumberOfQueensOnBoard() == 0)
problem = new GeneralProblem<>(board, NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
else
problem = new GeneralProblem<>(board, NQueensFunctions::getCSFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
List<QueenAction> actions = search.findActions(problem);
for (QueenAction action : actions) board = NQueensFunctions.getResult(board, action);
notifyProgressTrackers(board, search.getMetrics());
}
use of aima.core.environment.nqueens.QueenAction in project aima-java by aimacode.
the class UniformCostSearchTest method testUniformCostSuccesfulSearch.
@Test
public void testUniformCostSuccesfulSearch() throws Exception {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(8), 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(8, actions.size());
Assert.assertEquals("1965", agent.getInstrumentation().getProperty("nodesExpanded"));
Assert.assertEquals("8.0", agent.getInstrumentation().getProperty("pathCost"));
}
use of aima.core.environment.nqueens.QueenAction in project aima-java by aimacode.
the class NQueensFunctionsTest method testComplexBoardSuccessorGenerator.
@Test
public void testComplexBoardSuccessorGenerator() {
List<QueenAction> actions = new ArrayList<>(actionsFn.apply(eightBoard));
Assert.assertEquals(8, actions.size());
NQueensBoard next = resultFn.apply(eightBoard, actions.get(0));
Assert.assertEquals(1, next.getNumberOfQueensOnBoard());
actions = new ArrayList<>(actionsFn.apply(next));
Assert.assertEquals(6, actions.size());
}
use of aima.core.environment.nqueens.QueenAction in project aima-java by aimacode.
the class DepthFirstSearchTest method testDepthFirstSuccesfulSearch.
@Test
public void testDepthFirstSuccesfulSearch() throws Exception {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(8), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
SearchForActions<NQueensBoard, QueenAction> search = new DepthFirstSearch<>(new GraphSearch<>());
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 DepthLimitedSearchTest method testFailure.
@Test
public void testFailure() throws Exception {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(3), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
DepthLimitedSearch<NQueensBoard, QueenAction> search = new DepthLimitedSearch<>(5);
SearchAgent<NQueensBoard, QueenAction> agent = new SearchAgent<>(problem, search);
List<Action> actions = agent.getActions();
Assert.assertEquals(true, SearchUtils.isFailure(actions));
}
Aggregations