Search in sources :

Example 21 with EightPuzzleBoard

use of aima.core.environment.eightpuzzle.EightPuzzleBoard in project aima-java by aimacode.

the class EightPuzzleBoardMoveTest method testPosition6MoveDown.

@Test
public void testPosition6MoveDown() {
    // { 6, 5, 4, 1, 8, 0, 7, 3, 2 }
    setGapToPosition6();
    board.moveGapDown();
    Assert.assertEquals(new EightPuzzleBoard(new int[] { 6, 5, 4, 1, 8, 2, 7, 3, 0 }), board);
}
Also used : EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) Test(org.junit.Test)

Example 22 with EightPuzzleBoard

use of aima.core.environment.eightpuzzle.EightPuzzleBoard in project aima-java by aimacode.

the class EightPuzzleBoardMoveTest method testPosition7MoveUp.

@Test
public void testPosition7MoveUp() {
    // { 6, 5, 4, 7, 1, 8, 0, 3, 2 }
    setGapToPosition7();
    board.moveGapUp();
    Assert.assertEquals(new EightPuzzleBoard(new int[] { 6, 5, 4, 0, 1, 8, 7, 3, 2 }), board);
}
Also used : EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) Test(org.junit.Test)

Example 23 with EightPuzzleBoard

use of aima.core.environment.eightpuzzle.EightPuzzleBoard in project aima-java by aimacode.

the class AStarSearchTest method testAStarSearch.

@Test
public void testAStarSearch() {
    // Thoughtworks and Xin Lu of UCI
    try {
        // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
        // {2,0,5,6,4,8,3,7,1});
        // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
        // {0,8,7,6,5,4,3,2,1});
        EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8, 0, 4, 6, 2, 3, 5 });
        Problem<EightPuzzleBoard, Action> problem = new BidirectionalEightPuzzleProblem(board);
        SearchForActions<EightPuzzleBoard, Action> search = new AStarSearch<>(new GraphSearch<>(), EightPuzzleFunctions.createManhattanHeuristicFunction());
        SearchAgent<EightPuzzleBoard, Action> agent = new SearchAgent<>(problem, search);
        Assert.assertEquals(23, agent.getActions().size());
        // "926" GraphSearchReduced Frontier
        Assert.assertEquals(// "926" GraphSearchReduced Frontier
        "1133", agent.getInstrumentation().getProperty("nodesExpanded"));
        // "534" GraphSearchReduced Frontier
        Assert.assertEquals(// "534" GraphSearchReduced Frontier
        "676", agent.getInstrumentation().getProperty("queueSize"));
        // "535" GraphSearchReduced Frontier
        Assert.assertEquals(// "535" GraphSearchReduced Frontier
        "677", agent.getInstrumentation().getProperty("maxQueueSize"));
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Exception thrown");
    }
}
Also used : AStarSearch(aima.core.search.informed.AStarSearch) Action(aima.core.agent.Action) EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) SearchAgent(aima.core.search.framework.SearchAgent) BidirectionalEightPuzzleProblem(aima.core.environment.eightpuzzle.BidirectionalEightPuzzleProblem) Test(org.junit.Test) GoalTest(aima.core.search.framework.problem.GoalTest)

Example 24 with EightPuzzleBoard

use of aima.core.environment.eightpuzzle.EightPuzzleBoard in project aima-java by aimacode.

the class GreedyBestFirstSearchTest method testGreedyBestFirstSearch.

@Test
public void testGreedyBestFirstSearch() {
    try {
        // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
        // {2,0,5,6,4,8,3,7,1});
        // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
        // {0,8,7,6,5,4,3,2,1});
        EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8, 0, 4, 6, 2, 3, 5 });
        Problem<EightPuzzleBoard, Action> problem = new BidirectionalEightPuzzleProblem(board);
        SearchForActions<EightPuzzleBoard, Action> search = new GreedyBestFirstSearch<>(new GraphSearch<>(), EightPuzzleFunctions.createManhattanHeuristicFunction());
        SearchAgent<EightPuzzleBoard, Action> agent = new SearchAgent<>(problem, search);
        // GraphSearchReducedFrontier: "49"
        Assert.assertEquals(49, agent.getActions().size());
        // GraphSearchReducedFrontier: "197"
        Assert.assertEquals(// GraphSearchReducedFrontier: "197"
        "332", agent.getInstrumentation().getProperty("nodesExpanded"));
        // GraphSearchReducedFrontier: "140"
        Assert.assertEquals(// GraphSearchReducedFrontier: "140"
        "241", agent.getInstrumentation().getProperty("queueSize"));
        // GraphSearchReducedFrontier: "141"
        Assert.assertEquals(// GraphSearchReducedFrontier: "141"
        "242", agent.getInstrumentation().getProperty("maxQueueSize"));
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Exception thrown.");
    }
}
Also used : Action(aima.core.agent.Action) MoveToAction(aima.core.environment.map.MoveToAction) EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) SearchAgent(aima.core.search.framework.SearchAgent) BidirectionalEightPuzzleProblem(aima.core.environment.eightpuzzle.BidirectionalEightPuzzleProblem) GreedyBestFirstSearch(aima.core.search.informed.GreedyBestFirstSearch) Test(org.junit.Test) GoalTest(aima.core.search.framework.problem.GoalTest)

Example 25 with EightPuzzleBoard

use of aima.core.environment.eightpuzzle.EightPuzzleBoard in project aima-java by aimacode.

the class EightPuzzleFunctionsTest method testGenerateCorrectWhenGapMovedRightward.

@Test
public void testGenerateCorrectWhenGapMovedRightward() {
    // gives { 1, 2, 5, 3, 0, 4, 6, 7, 8 }
    board.moveGapLeft();
    Assert.assertEquals(new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 0, 4, 6, 7, 8 }), board);
    List<Action> actions = new ArrayList<>(EightPuzzleFunctions.getActions(board));
    Assert.assertEquals(4, actions.size());
    EightPuzzleBoard expectedFourth = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 4, 0, 6, 7, 8 });
    EightPuzzleBoard actualFourth = (EightPuzzleBoard) EightPuzzleFunctions.getResult(board, actions.get(3));
    Assert.assertEquals(expectedFourth, actualFourth);
    Assert.assertEquals(EightPuzzleBoard.RIGHT, actions.get(3));
}
Also used : Action(aima.core.agent.Action) EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

EightPuzzleBoard (aima.core.environment.eightpuzzle.EightPuzzleBoard)43 Test (org.junit.Test)42 Action (aima.core.agent.Action)5 BidirectionalEightPuzzleProblem (aima.core.environment.eightpuzzle.BidirectionalEightPuzzleProblem)3 SearchAgent (aima.core.search.framework.SearchAgent)3 GoalTest (aima.core.search.framework.problem.GoalTest)3 MoveToAction (aima.core.environment.map.MoveToAction)2 GreedyBestFirstSearch (aima.core.search.informed.GreedyBestFirstSearch)2 ArrayList (java.util.ArrayList)2 Node (aima.core.search.framework.Node)1 AStarSearch (aima.core.search.informed.AStarSearch)1 Random (java.util.Random)1