Search in sources :

Example 1 with DepthLimitedSearch

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

Example 2 with DepthLimitedSearch

use of aima.core.search.uninformed.DepthLimitedSearch 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"));
}
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 3 with DepthLimitedSearch

use of aima.core.search.uninformed.DepthLimitedSearch 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)

Aggregations

NQueensBoard (aima.core.environment.nqueens.NQueensBoard)3 NQueensFunctions (aima.core.environment.nqueens.NQueensFunctions)3 QueenAction (aima.core.environment.nqueens.QueenAction)3 GeneralProblem (aima.core.search.framework.problem.GeneralProblem)3 DepthLimitedSearch (aima.core.search.uninformed.DepthLimitedSearch)3 Test (org.junit.Test)3 Action (aima.core.agent.Action)1 SearchAgent (aima.core.search.framework.SearchAgent)1