use of aima.core.environment.nqueens.NQueensBoard 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.NQueensBoard 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));
}
use of aima.core.environment.nqueens.NQueensBoard 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.NQueensBoard 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.NQueensBoard in project aima-java by aimacode.
the class NQueensCspApp method initialize.
/**
* Displays the initialized board on the state view.
*/
@Override
public void initialize() {
csp = new NQueensCSP(simPaneCtrl.getParamAsInt(PARAM_BOARD_SIZE));
Object strategy = simPaneCtrl.getParamValue(PARAM_STRATEGY);
if (strategy.equals("Backtracking")) {
FlexibleBacktrackingSolver<Variable, Integer> bSolver = new FlexibleBacktrackingSolver<>();
switch((String) simPaneCtrl.getParamValue(PARAM_VAR_SELECT)) {
case "MRV":
bSolver.set(CspHeuristics.mrv());
break;
case "DEG":
bSolver.set(CspHeuristics.deg());
break;
case "MRV&DEG":
bSolver.set(CspHeuristics.mrvDeg());
break;
}
switch((String) simPaneCtrl.getParamValue(PARAM_VAL_SELECT)) {
case "LCV":
bSolver.set(CspHeuristics.lcv());
break;
}
switch((String) simPaneCtrl.getParamValue(PARAM_INFERENCE)) {
case "Forward Checking":
bSolver.set(new ForwardCheckingStrategy<>());
break;
case "AC3":
bSolver.set(new AC3Strategy<>());
break;
}
solver = bSolver;
} else if (strategy.equals("Min-Conflicts")) {
solver = new MinConflictsSolver<>(1000);
}
solver.addCspListener(stepCounter);
solver.addCspListener((csp, assign, var) -> {
if (assign != null)
updateStateView(getBoard(assign));
});
stepCounter.reset();
stateViewCtrl.update(new NQueensBoard(csp.getVariables().size()));
simPaneCtrl.setStatus("");
}
Aggregations