Search in sources :

Example 1 with MapEnvironment

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

the class MapAgentView method getAgentLocs.

/** Returns the locations of all agents. */
protected List<String> getAgentLocs() {
    List<String> result = new ArrayList<String>();
    MapEnvironment mEnv = getMapEnv();
    for (Agent a : mEnv.getAgents()) result.add(mEnv.getAgentLocation(a));
    return result;
}
Also used : Agent(aima.core.agent.Agent) ArrayList(java.util.ArrayList) MapEnvironment(aima.core.environment.map.MapEnvironment)

Example 2 with MapEnvironment

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

the class MapAgentTest method testNoPath.

@Test
public void testNoPath() {
    MapEnvironment me = new MapEnvironment(aMap);
    SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, new UniformCostSearch<>(), new String[] { "A" });
    me.addAgent(ma, "E");
    me.addEnvironmentView(new TestEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("CurrentLocation=In(E), Goal=In(A):Action[name==NoOp]:METRIC[pathCost]=0:METRIC[maxQueueSize]=1:METRIC[queueSize]=0:METRIC[nodesExpanded]=1:Action[name==NoOp]:", envChanges.toString());
}
Also used : SimpleMapAgent(aima.core.environment.map.SimpleMapAgent) MapEnvironment(aima.core.environment.map.MapEnvironment) Test(org.junit.Test)

Example 3 with MapEnvironment

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

the class MapAgentTest method testAlreadyAtGoal.

@Test
public void testAlreadyAtGoal() {
    MapEnvironment me = new MapEnvironment(aMap);
    SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, new UniformCostSearch<>(), new String[] { "A" });
    me.addAgent(ma, "A");
    me.addEnvironmentView(new TestEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("CurrentLocation=In(A), Goal=In(A):Action[name==NoOp]:METRIC[pathCost]=0.0:METRIC[maxQueueSize]=1:METRIC[queueSize]=0:METRIC[nodesExpanded]=0:Action[name==NoOp]:", envChanges.toString());
}
Also used : SimpleMapAgent(aima.core.environment.map.SimpleMapAgent) MapEnvironment(aima.core.environment.map.MapEnvironment) Test(org.junit.Test)

Example 4 with MapEnvironment

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

the class MapAgentTest method testNormalSearch.

@Test
public void testNormalSearch() {
    MapEnvironment me = new MapEnvironment(aMap);
    SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, new UniformCostSearch<>(), 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]=3:METRIC[queueSize]=1:METRIC[nodesExpanded]=3:Action[name==NoOp]:", envChanges.toString());
}
Also used : SimpleMapAgent(aima.core.environment.map.SimpleMapAgent) MapEnvironment(aima.core.environment.map.MapEnvironment) Test(org.junit.Test)

Example 5 with MapEnvironment

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

the class LRTAStarAgentTest method testNormalSearch.

@Test
public void testNormalSearch() {
    MapEnvironment me = new MapEnvironment(aMap);
    OnlineSearchProblem<String, MoveToAction> problem = new GeneralProblem<>(null, MapFunctions.createActionsFunction(aMap), null, GoalTest.isEqual("F"), 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==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==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)

Aggregations

MapEnvironment (aima.core.environment.map.MapEnvironment)31 Test (org.junit.Test)25 SimpleMapAgent (aima.core.environment.map.SimpleMapAgent)19 ExtendableMap (aima.core.environment.map.ExtendableMap)17 MoveToAction (aima.core.environment.map.MoveToAction)8 GeneralProblem (aima.core.search.framework.problem.GeneralProblem)7 GoalTest (aima.core.search.framework.problem.GoalTest)7 LRTAStarAgent (aima.core.search.online.LRTAStarAgent)4 OnlineDFSAgent (aima.core.search.online.OnlineDFSAgent)4 UniformCostSearch (aima.core.search.uninformed.UniformCostSearch)2 ArrayList (java.util.ArrayList)2 Agent (aima.core.agent.Agent)1 Point2D (aima.core.util.math.geom.shapes.Point2D)1 MapNode (aimax.osm.data.entities.MapNode)1 Before (org.junit.Before)1