Search in sources :

Example 1 with DepthFirstSearch

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

Example 2 with DepthFirstSearch

use of aima.core.search.uninformed.DepthFirstSearch in project aima-java by aimacode.

the class DepthFirstSearchTest method testDepthFirstUnSuccessfulSearch.

@Test
public void testDepthFirstUnSuccessfulSearch() throws Exception {
    Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(3), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
    SearchForActions<NQueensBoard, QueenAction> search = new DepthFirstSearch<>(new GraphSearch<>());
    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"));
}
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) DepthFirstSearch(aima.core.search.uninformed.DepthFirstSearch) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) Test(org.junit.Test)

Aggregations

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