use of aima.core.environment.nqueens.NQueensFunctions 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.NQueensFunctions 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.NQueensFunctions in project aima-java by aimacode.
the class NQueensFunctionsTest method setUp.
@Before
public void setUp() {
oneBoard = new NQueensBoard(1);
eightBoard = new NQueensBoard(8);
board = new NQueensBoard(8);
actionsFn = NQueensFunctions::getIFActions;
resultFn = NQueensFunctions::getResult;
goalTest = NQueensFunctions::testGoal;
}
use of aima.core.environment.nqueens.NQueensFunctions 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.NQueensFunctions 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