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());
}
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());
}
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());
}
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");
}
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());
}
Aggregations