Search in sources :

Example 1 with ExtendableMap

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

the class MapFunctionsTest method setUp.

@Before
public void setUp() {
    ExtendableMap aMap = new ExtendableMap();
    aMap.addBidirectionalLink("A", "B", 5.0);
    aMap.addBidirectionalLink("A", "C", 6.0);
    aMap.addBidirectionalLink("B", "C", 4.0);
    aMap.addBidirectionalLink("C", "D", 7.0);
    aMap.addUnidirectionalLink("B", "E", 14.0);
    actionsFn = MapFunctions.createActionsFunction(aMap);
    resultFn = MapFunctions.createResultFunction();
    stepCostFn = MapFunctions.createDistanceStepCostFunction(aMap);
}
Also used : ExtendableMap(aima.core.environment.map.ExtendableMap) Before(org.junit.Before)

Example 2 with ExtendableMap

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

the class MapTest method setUp.

@Before
public void setUp() {
    aMap = new ExtendableMap();
    aMap.addBidirectionalLink("A", "B", 5.0);
    aMap.addBidirectionalLink("A", "C", 6.0);
    aMap.addBidirectionalLink("B", "C", 4.0);
    aMap.addBidirectionalLink("C", "D", 7.0);
    aMap.addUnidirectionalLink("B", "E", 14.0);
}
Also used : ExtendableMap(aima.core.environment.map.ExtendableMap) Before(org.junit.Before)

Example 3 with ExtendableMap

use of aima.core.environment.map.ExtendableMap 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 ExtendableMap

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

the class BidirectionalSearchTest method test_ABCD_BothWaysPath.

//
// Test I(A)<->(B)<->(C)<->G(D)
@Test
public void test_ABCD_BothWaysPath() {
    ExtendableMap aMap = new ExtendableMap();
    aMap.addBidirectionalLink("A", "B", 5.0);
    aMap.addBidirectionalLink("B", "C", 5.0);
    aMap.addBidirectionalLink("C", "D", 5.0);
    MapEnvironment me = new MapEnvironment(aMap);
    SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, search, new String[] { "D" });
    me.addAgent(ma, "A");
    me.addEnvironmentView(new BDSEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("CurrentLocation=In(A), Goal=In(D):Action[name==moveTo, location==B]:Action[name==moveTo, location==C]:Action[name==moveTo, location==D]:METRIC[pathCost]=15.0:METRIC[maxQueueSize]=2:METRIC[queueSize]=1: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 5 with ExtendableMap

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

the class BidirectionalSearchTest method test_AB_ReverseOnlyPath.

//
// Test I(A)<-G(B)
@Test
public void test_AB_ReverseOnlyPath() {
    ExtendableMap aMap = new ExtendableMap();
    aMap.addUnidirectionalLink("B", "A", 5.0);
    MapEnvironment me = new MapEnvironment(aMap);
    SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, search, new String[] { "B" });
    me.addAgent(ma, "A");
    me.addEnvironmentView(new BDSEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("CurrentLocation=In(A), Goal=In(B):Action[name==NoOp]:METRIC[pathCost]=0:METRIC[maxQueueSize]=2:METRIC[queueSize]=0:METRIC[nodesExpanded]=2: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)

Aggregations

ExtendableMap (aima.core.environment.map.ExtendableMap)22 MapEnvironment (aima.core.environment.map.MapEnvironment)17 Test (org.junit.Test)16 SimpleMapAgent (aima.core.environment.map.SimpleMapAgent)15 Before (org.junit.Before)6 MoveToAction (aima.core.environment.map.MoveToAction)2 GeneralProblem (aima.core.search.framework.problem.GeneralProblem)2 GoalTest (aima.core.search.framework.problem.GoalTest)2 OnlineDFSAgent (aima.core.search.online.OnlineDFSAgent)2 UniformCostSearch (aima.core.search.uninformed.UniformCostSearch)1