Search in sources :

Example 6 with MoveToAction

use of aima.core.environment.map.MoveToAction in project aima-java by aimacode.

the class OnlineDFSAgentTest method testAlreadyAtGoal.

@Test
public void testAlreadyAtGoal() {
    MapEnvironment me = new MapEnvironment(aMap);
    OnlineSearchProblem<String, MoveToAction> problem = new GeneralProblem<>(null, MapFunctions.createActionsFunction(aMap), null, GoalTest.isEqual("A"), MapFunctions.createDistanceStepCostFunction(aMap));
    OnlineDFSAgent<String, MoveToAction> agent = new OnlineDFSAgent<>(problem, MapFunctions.createPerceptToStateFunction());
    me.addAgent(agent, "A");
    me.addEnvironmentView(new TestEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("Action[name==NoOp]->", envChanges.toString());
}
Also used : OnlineDFSAgent(aima.core.search.online.OnlineDFSAgent) MapEnvironment(aima.core.environment.map.MapEnvironment) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) MoveToAction(aima.core.environment.map.MoveToAction) GoalTest(aima.core.search.framework.problem.GoalTest) Test(org.junit.Test)

Example 7 with MoveToAction

use of aima.core.environment.map.MoveToAction in project aima-java by aimacode.

the class OnlineDFSAgentTest method testAIMA3eFig4_19.

@Test
public void testAIMA3eFig4_19() {
    aMap = new ExtendableMap();
    aMap.addBidirectionalLink("1,1", "1,2", 1.0);
    aMap.addBidirectionalLink("1,1", "2,1", 1.0);
    aMap.addBidirectionalLink("2,1", "3,1", 1.0);
    aMap.addBidirectionalLink("2,1", "2,2", 1.0);
    aMap.addBidirectionalLink("3,1", "3,2", 1.0);
    aMap.addBidirectionalLink("2,2", "2,3", 1.0);
    aMap.addBidirectionalLink("3,2", "3,3", 1.0);
    aMap.addBidirectionalLink("2,3", "1,3", 1.0);
    MapEnvironment me = new MapEnvironment(aMap);
    OnlineSearchProblem<String, MoveToAction> problem = new GeneralProblem<>(null, MapFunctions.createActionsFunction(aMap), null, GoalTest.isEqual("3,3"), MapFunctions.createDistanceStepCostFunction(aMap));
    OnlineDFSAgent<String, MoveToAction> agent = new OnlineDFSAgent<>(problem, MapFunctions.createPerceptToStateFunction());
    me.addAgent(agent, "1,1");
    me.addEnvironmentView(new TestEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("Action[name==moveTo, location==1,2]->Action[name==moveTo, location==1,1]->Action[name==moveTo, location==2,1]->Action[name==moveTo, location==1,1]->Action[name==moveTo, location==2,1]->Action[name==moveTo, location==2,2]->Action[name==moveTo, location==2,1]->Action[name==moveTo, location==3,1]->Action[name==moveTo, location==2,1]->Action[name==moveTo, location==3,1]->Action[name==moveTo, location==3,2]->Action[name==moveTo, location==3,1]->Action[name==moveTo, location==3,2]->Action[name==moveTo, location==3,3]->Action[name==NoOp]->", envChanges.toString());
}
Also used : OnlineDFSAgent(aima.core.search.online.OnlineDFSAgent) MapEnvironment(aima.core.environment.map.MapEnvironment) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) ExtendableMap(aima.core.environment.map.ExtendableMap) MoveToAction(aima.core.environment.map.MoveToAction) GoalTest(aima.core.search.framework.problem.GoalTest) Test(org.junit.Test)

Example 8 with MoveToAction

use of aima.core.environment.map.MoveToAction in project aima-java by aimacode.

the class MapAgentTest method testNormalSearchGraphSearchMinFrontier.

@Test
public void testNormalSearchGraphSearchMinFrontier() {
    MapEnvironment me = new MapEnvironment(aMap);
    UniformCostSearch<String, MoveToAction> ucSearch = new UniformCostSearch<>(new GraphSearchReducedFrontier<>());
    SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, ucSearch, new String[] { "D" });
    me.addAgent(ma, "A");
    me.addEnvironmentView(new TestEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("CurrentLocation=In(A), Goal=In(D):Action[name==moveTo, location==C]:Action[name==moveTo, location==D]:METRIC[pathCost]=13.0:METRIC[maxQueueSize]=2:METRIC[queueSize]=1:METRIC[nodesExpanded]=3:Action[name==NoOp]:", envChanges.toString());
}
Also used : UniformCostSearch(aima.core.search.uninformed.UniformCostSearch) SimpleMapAgent(aima.core.environment.map.SimpleMapAgent) MapEnvironment(aima.core.environment.map.MapEnvironment) MoveToAction(aima.core.environment.map.MoveToAction) Test(org.junit.Test)

Example 9 with MoveToAction

use of aima.core.environment.map.MoveToAction in project aima-java by aimacode.

the class MapEnvironmentTest method testTwoAgentsSupported.

@Test
public void testTwoAgentsSupported() {
    SimpleMapAgent ma1 = new SimpleMapAgent(me.getMap(), me, new UniformCostSearch(), new String[] { "A" });
    SimpleMapAgent ma2 = new SimpleMapAgent(me.getMap(), me, new UniformCostSearch(), new String[] { "A" });
    me.addAgent(ma1, "A");
    me.addAgent(ma2, "A");
    me.executeAction(ma1, new MoveToAction("B"));
    me.executeAction(ma2, new MoveToAction("C"));
    Assert.assertEquals(me.getAgentLocation(ma1), "B");
    Assert.assertEquals(me.getAgentLocation(ma2), "C");
}
Also used : UniformCostSearch(aima.core.search.uninformed.UniformCostSearch) SimpleMapAgent(aima.core.environment.map.SimpleMapAgent) MoveToAction(aima.core.environment.map.MoveToAction) Test(org.junit.Test)

Example 10 with MoveToAction

use of aima.core.environment.map.MoveToAction in project aima-java by aimacode.

the class MapFunctionsTest method testSuccessors.

@Test
public void testSuccessors() {
    ArrayList<String> locations = new ArrayList<>();
    // A
    locations.clear();
    locations.add("B");
    locations.add("C");
    for (MoveToAction a : actionsFn.apply("A")) {
        Assert.assertTrue(locations.contains(a.getToLocation()));
        Assert.assertTrue(locations.contains(resultFn.apply("A", a)));
    }
    // B
    locations.clear();
    locations.add("A");
    locations.add("C");
    locations.add("E");
    for (MoveToAction a : actionsFn.apply("B")) {
        Assert.assertTrue(locations.contains(a.getToLocation()));
        Assert.assertTrue(locations.contains(resultFn.apply("B", a)));
    }
    // C
    locations.clear();
    locations.add("A");
    locations.add("B");
    locations.add("D");
    for (MoveToAction a : actionsFn.apply("C")) {
        Assert.assertTrue(locations.contains(a.getToLocation()));
        Assert.assertTrue(locations.contains(resultFn.apply("C", a)));
    }
    // D
    locations.clear();
    locations.add("C");
    for (MoveToAction a : actionsFn.apply("D")) {
        Assert.assertTrue(locations.contains(a.getToLocation()));
        Assert.assertTrue(locations.contains(resultFn.apply("D", a)));
    }
    // E
    locations.clear();
    Assert.assertTrue(0 == actionsFn.apply("E").size());
}
Also used : ArrayList(java.util.ArrayList) MoveToAction(aima.core.environment.map.MoveToAction) Test(org.junit.Test)

Aggregations

MoveToAction (aima.core.environment.map.MoveToAction)14 Test (org.junit.Test)14 GeneralProblem (aima.core.search.framework.problem.GeneralProblem)10 GoalTest (aima.core.search.framework.problem.GoalTest)10 MapEnvironment (aima.core.environment.map.MapEnvironment)8 OnlineDFSAgent (aima.core.search.online.OnlineDFSAgent)4 Map (aima.core.environment.map.Map)3 SimplifiedRoadMapOfPartOfRomania (aima.core.environment.map.SimplifiedRoadMapOfPartOfRomania)3 SearchAgent (aima.core.search.framework.SearchAgent)3 LRTAStarAgent (aima.core.search.online.LRTAStarAgent)3 UniformCostSearch (aima.core.search.uninformed.UniformCostSearch)3 ExtendableMap (aima.core.environment.map.ExtendableMap)2 SimpleMapAgent (aima.core.environment.map.SimpleMapAgent)2 GreedyBestFirstSearch (aima.core.search.informed.GreedyBestFirstSearch)2 Node (aima.core.search.framework.Node)1 ArrayList (java.util.ArrayList)1