Search in sources :

Example 6 with NQueensBoard

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

the class UniformCostSearchTest method testUniformCostSuccesfulSearch.

@Test
public void testUniformCostSuccesfulSearch() throws Exception {
    Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(8), 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(8, actions.size());
    Assert.assertEquals("1965", agent.getInstrumentation().getProperty("nodesExpanded"));
    Assert.assertEquals("8.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)

Example 7 with NQueensBoard

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

the class NQueensFunctionsTest method testSingleSquareBoard.

@Test
public void testSingleSquareBoard() {
    board = new NQueensBoard(1);
    Assert.assertFalse(goalTest.test(board));
    board.addQueenAt(new XYLocation(0, 0));
    Assert.assertTrue(goalTest.test(board));
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) Test(org.junit.Test) GoalTest(aima.core.search.framework.problem.GoalTest)

Example 8 with NQueensBoard

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

the class NQueensGenAlgoUtilTest method test_getBoardForIndividual.

@Test
public void test_getBoardForIndividual() {
    NQueensBoard board = NQueensGenAlgoUtil.getBoardForIndividual(new Individual<>(Arrays.asList(5, 6, 1, 3, 6, 4, 7, 7)));
    Assert.assertEquals(" -  -  -  -  -  -  -  - \n" + " -  -  Q  -  -  -  -  - \n" + " -  -  -  -  -  -  -  - \n" + " -  -  -  Q  -  -  -  - \n" + " -  -  -  -  -  Q  -  - \n" + " Q  -  -  -  -  -  -  - \n" + " -  Q  -  -  Q  -  -  - \n" + " -  -  -  -  -  -  Q  Q \n", board.getBoardPic());
    Assert.assertEquals("--------\n" + "--Q-----\n" + "--------\n" + "---Q----\n" + "-----Q--\n" + "Q-------\n" + "-Q--Q---\n" + "------QQ\n", board.toString());
}
Also used : NQueensBoard(aima.core.environment.nqueens.NQueensBoard) GoalTest(aima.core.search.framework.problem.GoalTest) Test(org.junit.Test)

Example 9 with NQueensBoard

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

the class NQueensFunctionsTest method setUp.

@Before
public void setUp() {
    oneBoard = new NQueensBoard(1);
    eightBoard = new NQueensBoard(8);
    board = new NQueensBoard(8);
    actionsFn = NQueensFunctions::getIFActions;
    resultFn = NQueensFunctions::getResult;
    goalTest = NQueensFunctions::testGoal;
}
Also used : NQueensFunctions(aima.core.environment.nqueens.NQueensFunctions) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) Before(org.junit.Before)

Example 10 with NQueensBoard

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

the class NQueensFunctionsTest method testComplexBoardSuccessorGenerator.

@Test
public void testComplexBoardSuccessorGenerator() {
    List<QueenAction> actions = new ArrayList<>(actionsFn.apply(eightBoard));
    Assert.assertEquals(8, actions.size());
    NQueensBoard next = resultFn.apply(eightBoard, actions.get(0));
    Assert.assertEquals(1, next.getNumberOfQueensOnBoard());
    actions = new ArrayList<>(actionsFn.apply(next));
    Assert.assertEquals(6, actions.size());
}
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)

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