Search in sources :

Example 11 with Action

use of aima.core.agent.Action 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 12 with Action

use of aima.core.agent.Action in project aima-java by aimacode.

the class KBAgent method execute.

// function KB-AGENT(percept) returns an action
@Override
public Action execute(Percept percept) {
    // TELL(KB, MAKE-PERCEPT-SENTENCE(percept, t))
    KB.tell(makePerceptSentence(percept, t));
    // action &lt;- ASK(KB, MAKE-ACTION-QUERY(t))
    Action action = ask(KB, makeActionQuery(t));
    // TELL(KB, MAKE-ACTION-SENTENCE(action, t))
    KB.tell(makeActionSentence(action, t));
    // t &lt;- t + 1
    t = t + 1;
    // return action
    return action;
}
Also used : Action(aima.core.agent.Action)

Example 13 with Action

use of aima.core.agent.Action in project aima-java by aimacode.

the class HybridWumpusAgentTest method testGrabAndClimb.

@Test
public void testGrabAndClimb() {
    HybridWumpusAgent hwa = new HybridWumpusAgent(2);
    // The gold is in the first square
    Action a = hwa.execute(new AgentPercept(true, true, true, false, false));
    Assert.assertTrue(a instanceof Grab);
    a = hwa.execute(new AgentPercept(true, true, true, false, false));
    Assert.assertTrue(a instanceof Climb);
}
Also used : HybridWumpusAgent(aima.core.environment.wumpusworld.HybridWumpusAgent) Action(aima.core.agent.Action) AgentPercept(aima.core.environment.wumpusworld.AgentPercept) Climb(aima.core.environment.wumpusworld.action.Climb) Grab(aima.core.environment.wumpusworld.action.Grab) Test(org.junit.Test)

Example 14 with Action

use of aima.core.agent.Action 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 15 with Action

use of aima.core.agent.Action 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)

Aggregations

Action (aima.core.agent.Action)26 Test (org.junit.Test)12 SearchAgent (aima.core.search.framework.SearchAgent)8 NoOpAction (aima.core.agent.impl.NoOpAction)6 GeneralProblem (aima.core.search.framework.problem.GeneralProblem)6 EightPuzzleBoard (aima.core.environment.eightpuzzle.EightPuzzleBoard)5 NQueensBoard (aima.core.environment.nqueens.NQueensBoard)5 NQueensFunctions (aima.core.environment.nqueens.NQueensFunctions)5 QueenAction (aima.core.environment.nqueens.QueenAction)5 GoalTest (aima.core.search.framework.problem.GoalTest)5 ArrayList (java.util.ArrayList)4 DynamicAction (aima.core.agent.impl.DynamicAction)3 BidirectionalEightPuzzleProblem (aima.core.environment.eightpuzzle.BidirectionalEightPuzzleProblem)3 Agent (aima.core.agent.Agent)2 Percept (aima.core.agent.Percept)2 MoveToAction (aima.core.environment.map.MoveToAction)2 Climb (aima.core.environment.wumpusworld.action.Climb)2 Grab (aima.core.environment.wumpusworld.action.Grab)2 TurnLeft (aima.core.environment.wumpusworld.action.TurnLeft)2 GreedyBestFirstSearch (aima.core.search.informed.GreedyBestFirstSearch)2