Search in sources :

Example 26 with MapEnvironment

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

the class BidirectionalSearchTest method test_ABCDE_ReverseOnlyPath.

// Test I(A)<->(B)<->(C)<-(D)<-G(E)
@Test
public void test_ABCDE_ReverseOnlyPath() {
    ExtendableMap aMap = new ExtendableMap();
    aMap.addBidirectionalLink("A", "B", 5.0);
    aMap.addBidirectionalLink("B", "C", 5.0);
    aMap.addUnidirectionalLink("D", "C", 5.0);
    aMap.addUnidirectionalLink("E", "D", 5.0);
    MapEnvironment me = new MapEnvironment(aMap);
    SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, search, new String[] { "E" });
    me.addAgent(ma, "A");
    me.addEnvironmentView(new BDSEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("CurrentLocation=In(A), Goal=In(E):Action[name==NoOp]:METRIC[pathCost]=0:METRIC[maxQueueSize]=2:METRIC[queueSize]=0:METRIC[nodesExpanded]=4:Action[name==NoOp]:", envChanges.toString());
}
Also used : SimpleMapAgent(aima.core.environment.map.SimpleMapAgent) MapEnvironment(aima.core.environment.map.MapEnvironment) ExtendableMap(aima.core.environment.map.ExtendableMap) Test(org.junit.Test)

Example 27 with MapEnvironment

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

the class BidirectionalSearchTest method test_A_StartingAtGoal.

//
// Test IG(A)
@Test
public void test_A_StartingAtGoal() {
    ExtendableMap aMap = new ExtendableMap();
    MapEnvironment me = new MapEnvironment(aMap);
    SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, search, new String[] { "A" });
    me.addAgent(ma, "A");
    me.addEnvironmentView(new BDSEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("CurrentLocation=In(A), Goal=In(A):Action[name==NoOp]:METRIC[pathCost]=0.0:METRIC[maxQueueSize]=0: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) ExtendableMap(aima.core.environment.map.ExtendableMap) Test(org.junit.Test)

Example 28 with MapEnvironment

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

the class MapAgentView method agentActed.

/**
	 * Reacts on environment changes and updates the agent tracks. The command
	 * is always send to the message logger as string.
	 */
@Override
public void agentActed(Agent agent, Percept percept, Action command, Environment source) {
    MapEnvironment mEnv = getMapEnv();
    String msg = "";
    if (mEnv.getAgents().size() > 1)
        msg = "A" + mEnv.getAgents().indexOf(agent) + ": ";
    notify(msg + command.toString());
    updateTracks();
    repaint();
}
Also used : MapEnvironment(aima.core.environment.map.MapEnvironment)

Example 29 with MapEnvironment

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

the class AbstractMapAgentController method step.

/**
	 * Calls {@link #initAgents(MessageLogger)} if necessary and
	 * then executes one simulation step.
	 */
@Override
public void step(MessageLogger logger) {
    MapEnvironment env = scenario.getEnv();
    if (env.getAgents().isEmpty())
        initAgents(logger);
    env.step();
}
Also used : MapEnvironment(aima.core.environment.map.MapEnvironment)

Example 30 with MapEnvironment

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

the class AbstractMapAgentController method run.

/**
	 * Calls {@link #initAgents(MessageLogger)} if necessary and
	 * then starts simulation until done.
	 */
public void run(MessageLogger logger) {
    logger.log("<simulation-protocol>");
    logger.log("search: " + search.getClass().getName());
    if (heuristic != null)
        logger.log("heuristic: " + heuristic.getClass().getName());
    MapEnvironment env = scenario.getEnv();
    if (env.getAgents().isEmpty())
        initAgents(logger);
    try {
        while (!env.isDone() && !frame.simulationPaused()) {
            Thread.sleep(sleepTime);
            env.step();
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    logger.log("</simulation-protocol>\n");
}
Also used : MapEnvironment(aima.core.environment.map.MapEnvironment)

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