Search in sources :

Example 21 with NQueensBoard

use of aima.core.environment.nqueens.NQueensBoard 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));
}
Also used : NQueensFunctions(aima.core.environment.nqueens.NQueensFunctions) QueenAction(aima.core.environment.nqueens.QueenAction) DepthLimitedSearch(aima.core.search.uninformed.DepthLimitedSearch) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) Test(org.junit.Test)

Example 22 with NQueensBoard

use of aima.core.environment.nqueens.NQueensBoard 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");
    }
}
Also used : NQueensFunctions(aima.core.environment.nqueens.NQueensFunctions) QueenAction(aima.core.environment.nqueens.QueenAction) IterativeDeepeningSearch(aima.core.search.uninformed.IterativeDeepeningSearch) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) Test(org.junit.Test)

Example 23 with NQueensBoard

use of aima.core.environment.nqueens.NQueensBoard 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"));
}
Also used : NQueensFunctions(aima.core.environment.nqueens.NQueensFunctions) Action(aima.core.agent.Action) QueenAction(aima.core.environment.nqueens.QueenAction) UniformCostSearch(aima.core.search.uninformed.UniformCostSearch) QueenAction(aima.core.environment.nqueens.QueenAction) SearchAgent(aima.core.search.framework.SearchAgent) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) Test(org.junit.Test) GoalTest(aima.core.search.framework.problem.GoalTest)

Aggregations

NQueensBoard (aima.core.environment.nqueens.NQueensBoard)23 Test (org.junit.Test)16 QueenAction (aima.core.environment.nqueens.QueenAction)13 NQueensFunctions (aima.core.environment.nqueens.NQueensFunctions)12 GeneralProblem (aima.core.search.framework.problem.GeneralProblem)11 GoalTest (aima.core.search.framework.problem.GoalTest)6 Action (aima.core.agent.Action)5 SearchAgent (aima.core.search.framework.SearchAgent)5 XYLocation (aima.core.util.datastructure.XYLocation)4 DepthLimitedSearch (aima.core.search.uninformed.DepthLimitedSearch)3 BreadthFirstSearch (aima.core.search.uninformed.BreadthFirstSearch)2 DepthFirstSearch (aima.core.search.uninformed.DepthFirstSearch)2 UniformCostSearch (aima.core.search.uninformed.UniformCostSearch)2 ArrayList (java.util.ArrayList)2 NQueensCSP (aima.core.search.csp.examples.NQueensCSP)1 IterativeDeepeningSearch (aima.core.search.uninformed.IterativeDeepeningSearch)1 Before (org.junit.Before)1