Search in sources :

Example 11 with MoveToAction

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

the class LRTAStarAgentTest method testNoPath.

@Test
public void testNoPath() {
    MapEnvironment me = new MapEnvironment(aMap);
    OnlineSearchProblem<String, MoveToAction> problem = new GeneralProblem<>(null, MapFunctions.createActionsFunction(aMap), null, GoalTest.isEqual("G"), MapFunctions.createDistanceStepCostFunction(aMap));
    LRTAStarAgent<String, MoveToAction> agent = new LRTAStarAgent<>(problem, MapFunctions.createPerceptToStateFunction(), h);
    me.addAgent(agent, "A");
    me.addEnvironmentView(new TestEnvironmentView());
    // Note: Will search forever if no path is possible,
    // Therefore restrict the number of steps to something
    // reasonablbe, against which to test.
    me.step(14);
    Assert.assertEquals("Action[name==moveTo, location==B]->Action[name==moveTo, location==A]->Action[name==moveTo, location==B]->Action[name==moveTo, location==C]->Action[name==moveTo, location==B]->Action[name==moveTo, location==C]->Action[name==moveTo, location==D]->Action[name==moveTo, location==C]->Action[name==moveTo, location==D]->Action[name==moveTo, location==E]->Action[name==moveTo, location==D]->Action[name==moveTo, location==E]->Action[name==moveTo, location==F]->Action[name==moveTo, location==E]->", envChanges.toString());
}
Also used : MapEnvironment(aima.core.environment.map.MapEnvironment) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) LRTAStarAgent(aima.core.search.online.LRTAStarAgent) MoveToAction(aima.core.environment.map.MoveToAction) Test(org.junit.Test) GoalTest(aima.core.search.framework.problem.GoalTest)

Example 12 with MoveToAction

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

the class LRTAStarAgentTest 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));
    LRTAStarAgent<String, MoveToAction> agent = new LRTAStarAgent<>(problem, MapFunctions.createPerceptToStateFunction(), h);
    me.addAgent(agent, "A");
    me.addEnvironmentView(new TestEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("Action[name==NoOp]->", envChanges.toString());
}
Also used : MapEnvironment(aima.core.environment.map.MapEnvironment) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) LRTAStarAgent(aima.core.search.online.LRTAStarAgent) MoveToAction(aima.core.environment.map.MoveToAction) Test(org.junit.Test) GoalTest(aima.core.search.framework.problem.GoalTest)

Example 13 with MoveToAction

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

the class OnlineDFSAgentTest method testNoPath.

@Test
public void testNoPath() {
    aMap = new ExtendableMap();
    aMap.addBidirectionalLink("A", "B", 1.0);
    MapEnvironment me = new MapEnvironment(aMap);
    OnlineSearchProblem<String, MoveToAction> problem = new GeneralProblem<>(null, MapFunctions.createActionsFunction(aMap), null, GoalTest.isEqual("X"), 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==moveTo, location==B]->Action[name==moveTo, location==A]->Action[name==moveTo, location==B]->Action[name==moveTo, location==A]->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 14 with MoveToAction

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

the class GreedyBestFirstSearchTest method testAIMA3eFigure3_23.

@Test
public void testAIMA3eFigure3_23() throws Exception {
    Map romaniaMap = new SimplifiedRoadMapOfPartOfRomania();
    Problem<String, MoveToAction> problem = new GeneralProblem<>(SimplifiedRoadMapOfPartOfRomania.ARAD, MapFunctions.createActionsFunction(romaniaMap), MapFunctions.createResultFunction(), GoalTest.isEqual(SimplifiedRoadMapOfPartOfRomania.BUCHAREST), MapFunctions.createDistanceStepCostFunction(romaniaMap));
    SearchForActions<String, MoveToAction> search = new GreedyBestFirstSearch<>(new TreeSearch<>(), MapFunctions.createSLDHeuristicFunction(SimplifiedRoadMapOfPartOfRomania.BUCHAREST, romaniaMap));
    SearchAgent<String, MoveToAction> agent = new SearchAgent<>(problem, search);
    Assert.assertEquals("[Action[name==moveTo, location==Sibiu], Action[name==moveTo, location==Fagaras], Action[name==moveTo, location==Bucharest]]", agent.getActions().toString());
    Assert.assertEquals(3, agent.getActions().size());
    Assert.assertEquals("3", agent.getInstrumentation().getProperty("nodesExpanded"));
    Assert.assertEquals("6", agent.getInstrumentation().getProperty("queueSize"));
    Assert.assertEquals("7", agent.getInstrumentation().getProperty("maxQueueSize"));
}
Also used : SimplifiedRoadMapOfPartOfRomania(aima.core.environment.map.SimplifiedRoadMapOfPartOfRomania) SearchAgent(aima.core.search.framework.SearchAgent) GreedyBestFirstSearch(aima.core.search.informed.GreedyBestFirstSearch) Map(aima.core.environment.map.Map) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) MoveToAction(aima.core.environment.map.MoveToAction) Test(org.junit.Test) GoalTest(aima.core.search.framework.problem.GoalTest)

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