Search in sources :

Example 6 with SimpleMapAgent

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

the class BidirectionalSearchTest method test_ABCDE_OriginalOnlyPath.

//
// Test I(A)->(B)->(C)<->(D)<->G(E)
@Test
public void test_ABCDE_OriginalOnlyPath() {
    ExtendableMap aMap = new ExtendableMap();
    aMap.addBidirectionalLink("A", "B", 5.0);
    aMap.addUnidirectionalLink("B", "C", 5.0);
    aMap.addBidirectionalLink("C", "D", 5.0);
    aMap.addBidirectionalLink("D", "E", 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==moveTo, location==B]:Action[name==moveTo, location==C]:Action[name==moveTo, location==D]:Action[name==moveTo, location==E]:METRIC[pathCost]=20.0:METRIC[maxQueueSize]=2:METRIC[queueSize]=1:METRIC[nodesExpanded]=5: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 7 with SimpleMapAgent

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

the class BidirectionalSearchTest method test_ABCDEF_OriginalFirst.

/**
	 * <code>
	 * Test I(A)<->(B)<->(C)<->(D)<->(E)<->(F)<->(G)<->G(H)
	 *              |                                    +
	 *              --------------------------------------
	 * </code>
	 */
@Test
public void test_ABCDEF_OriginalFirst() {
    ExtendableMap aMap = new ExtendableMap();
    aMap.addBidirectionalLink("A", "B", 5.0);
    aMap.addBidirectionalLink("B", "C", 5.0);
    aMap.addBidirectionalLink("C", "D", 5.0);
    aMap.addBidirectionalLink("D", "E", 5.0);
    aMap.addBidirectionalLink("E", "F", 5.0);
    aMap.addBidirectionalLink("F", "G", 5.0);
    aMap.addBidirectionalLink("G", "H", 5.0);
    aMap.addUnidirectionalLink("B", "H", 5.0);
    MapEnvironment me = new MapEnvironment(aMap);
    SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, search, new String[] { "H" });
    me.addAgent(ma, "A");
    me.addEnvironmentView(new BDSEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("CurrentLocation=In(A), Goal=In(H):Action[name==moveTo, location==B]:Action[name==moveTo, location==H]:METRIC[pathCost]=10.0:METRIC[maxQueueSize]=2:METRIC[queueSize]=2:METRIC[nodesExpanded]=3: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 8 with SimpleMapAgent

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

the class BidirectionalSearchTest method test_ABC_BothWaysPath.

//
// Test I(A)<->(B)<->G(C)
@Test
public void test_ABC_BothWaysPath() {
    ExtendableMap aMap = new ExtendableMap();
    aMap.addBidirectionalLink("A", "B", 5.0);
    aMap.addBidirectionalLink("B", "C", 5.0);
    MapEnvironment me = new MapEnvironment(aMap);
    SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, search, new String[] { "C" });
    me.addAgent(ma, "A");
    me.addEnvironmentView(new BDSEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("CurrentLocation=In(A), Goal=In(C):Action[name==moveTo, location==B]:Action[name==moveTo, location==C]:METRIC[pathCost]=10.0:METRIC[maxQueueSize]=2: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) ExtendableMap(aima.core.environment.map.ExtendableMap) Test(org.junit.Test)

Example 9 with SimpleMapAgent

use of aima.core.environment.map.SimpleMapAgent 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());
}
Also used : UniformCostSearch(aima.core.search.uninformed.UniformCostSearch) SimpleMapAgent(aima.core.environment.map.SimpleMapAgent) MapEnvironment(aima.core.environment.map.MapEnvironment) MoveToAction(aima.core.environment.map.MoveToAction) Test(org.junit.Test)

Example 10 with SimpleMapAgent

use of aima.core.environment.map.SimpleMapAgent 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");
}
Also used : UniformCostSearch(aima.core.search.uninformed.UniformCostSearch) SimpleMapAgent(aima.core.environment.map.SimpleMapAgent) MoveToAction(aima.core.environment.map.MoveToAction) Test(org.junit.Test)

Aggregations

SimpleMapAgent (aima.core.environment.map.SimpleMapAgent)20 MapEnvironment (aima.core.environment.map.MapEnvironment)19 Test (org.junit.Test)19 ExtendableMap (aima.core.environment.map.ExtendableMap)15 UniformCostSearch (aima.core.search.uninformed.UniformCostSearch)3 MoveToAction (aima.core.environment.map.MoveToAction)2 Before (org.junit.Before)1