Search in sources :

Example 1 with AStarSearch

use of aima.core.search.informed.AStarSearch 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)

Aggregations

Action (aima.core.agent.Action)1 BidirectionalEightPuzzleProblem (aima.core.environment.eightpuzzle.BidirectionalEightPuzzleProblem)1 EightPuzzleBoard (aima.core.environment.eightpuzzle.EightPuzzleBoard)1 SearchAgent (aima.core.search.framework.SearchAgent)1 GoalTest (aima.core.search.framework.problem.GoalTest)1 AStarSearch (aima.core.search.informed.AStarSearch)1 Test (org.junit.Test)1