Search in sources :

Example 6 with QueenAction

use of aima.core.environment.nqueens.QueenAction 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 7 with QueenAction

use of aima.core.environment.nqueens.QueenAction 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());
}
Also used : QueenAction(aima.core.environment.nqueens.QueenAction) ArrayList(java.util.ArrayList) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) Test(org.junit.Test) GoalTest(aima.core.search.framework.problem.GoalTest)

Example 8 with QueenAction

use of aima.core.environment.nqueens.QueenAction in project aima-java by aimacode.

the class BreadthFirstSearchTest method testBreadthFirstSuccesfulSearch.

@Test
public void testBreadthFirstSuccesfulSearch() throws Exception {
    Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(8), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
    SearchForActions<NQueensBoard, QueenAction> search = new BreadthFirstSearch<>(new TreeSearch<>());
    List<QueenAction> actions = search.findActions(problem);
    assertCorrectPlacement(actions);
    Assert.assertEquals("1665", search.getMetrics().get("nodesExpanded"));
    Assert.assertEquals("8.0", search.getMetrics().get("pathCost"));
}
Also used : NQueensFunctions(aima.core.environment.nqueens.NQueensFunctions) BreadthFirstSearch(aima.core.search.uninformed.BreadthFirstSearch) QueenAction(aima.core.environment.nqueens.QueenAction) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) Test(org.junit.Test)

Example 9 with QueenAction

use of aima.core.environment.nqueens.QueenAction in project aima-java by aimacode.

the class BreadthFirstSearchTest method testBreadthFirstUnSuccesfulSearch.

@Test
public void testBreadthFirstUnSuccesfulSearch() throws Exception {
    Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(3), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
    SearchForActions<NQueensBoard, QueenAction> search = new BreadthFirstSearch<>(new TreeSearch<>());
    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"));
    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) BreadthFirstSearch(aima.core.search.uninformed.BreadthFirstSearch) 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)

Example 10 with QueenAction

use of aima.core.environment.nqueens.QueenAction 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)13 QueenAction (aima.core.environment.nqueens.QueenAction)13 Test (org.junit.Test)12 NQueensFunctions (aima.core.environment.nqueens.NQueensFunctions)11 GeneralProblem (aima.core.search.framework.problem.GeneralProblem)11 Action (aima.core.agent.Action)5 SearchAgent (aima.core.search.framework.SearchAgent)5 GoalTest (aima.core.search.framework.problem.GoalTest)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 IterativeDeepeningSearch (aima.core.search.uninformed.IterativeDeepeningSearch)1