Search in sources :

Example 1 with OnlineDFSAgent

use of aima.core.search.online.OnlineDFSAgent in project aima-java by aimacode.

the class OnlineDFSAgentTest method testNormalSearch.

@Test
public void testNormalSearch() {
    MapEnvironment me = new MapEnvironment(aMap);
    OnlineSearchProblem<String, MoveToAction> problem = new GeneralProblem<>(null, MapFunctions.createActionsFunction(aMap), null, GoalTest.isEqual("G"), 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==C]->Action[name==moveTo, location==A]->Action[name==moveTo, location==C]->Action[name==moveTo, location==A]->Action[name==moveTo, location==B]->Action[name==moveTo, location==D]->Action[name==moveTo, location==B]->Action[name==moveTo, location==E]->Action[name==moveTo, location==B]->Action[name==moveTo, location==E]->Action[name==moveTo, location==B]->Action[name==moveTo, location==D]->Action[name==moveTo, location==F]->Action[name==moveTo, location==D]->Action[name==moveTo, location==G]->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 2 with OnlineDFSAgent

use of aima.core.search.online.OnlineDFSAgent 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 3 with OnlineDFSAgent

use of aima.core.search.online.OnlineDFSAgent 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 4 with OnlineDFSAgent

use of aima.core.search.online.OnlineDFSAgent 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)

Aggregations

MapEnvironment (aima.core.environment.map.MapEnvironment)4 MoveToAction (aima.core.environment.map.MoveToAction)4 GeneralProblem (aima.core.search.framework.problem.GeneralProblem)4 GoalTest (aima.core.search.framework.problem.GoalTest)4 OnlineDFSAgent (aima.core.search.online.OnlineDFSAgent)4 Test (org.junit.Test)4 ExtendableMap (aima.core.environment.map.ExtendableMap)2