use of aima.core.search.uninformed.UniformCostSearch in project aima-java by aimacode.
the class UniformCostSearchTest method testUniformCostSuccesfulSearch.
@Test
public void testUniformCostSuccesfulSearch() throws Exception {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(8), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
SearchForActions<NQueensBoard, QueenAction> search = new UniformCostSearch<>();
SearchAgent<NQueensBoard, QueenAction> agent = new SearchAgent<>(problem, search);
List<Action> actions = agent.getActions();
Assert.assertEquals(8, actions.size());
Assert.assertEquals("1965", agent.getInstrumentation().getProperty("nodesExpanded"));
Assert.assertEquals("8.0", agent.getInstrumentation().getProperty("pathCost"));
}
use of aima.core.search.uninformed.UniformCostSearch in project aima-java by aimacode.
the class SolutionTesterTest method testMultiGoalProblem.
@Test
public void testMultiGoalProblem() throws Exception {
Map romaniaMap = new SimplifiedRoadMapOfPartOfRomania();
Problem<String, MoveToAction> problem = new GeneralProblem<String, MoveToAction>(SimplifiedRoadMapOfPartOfRomania.ARAD, MapFunctions.createActionsFunction(romaniaMap), MapFunctions.createResultFunction(), GoalTest.<String>isEqual(SimplifiedRoadMapOfPartOfRomania.BUCHAREST).or(GoalTest.isEqual(SimplifiedRoadMapOfPartOfRomania.HIRSOVA)), MapFunctions.createDistanceStepCostFunction(romaniaMap)) {
@Override
public boolean testSolution(Node<String, MoveToAction> node) {
return testGoal(node.getState()) && node.getPathCost() > 550;
// accept paths to goal only if their costs are above 550
}
};
SearchForActions<String, MoveToAction> search = new UniformCostSearch<>(new GraphSearch<>());
SearchAgent<String, MoveToAction> agent = new SearchAgent<>(problem, search);
Assert.assertEquals("[Action[name==moveTo, location==Sibiu], Action[name==moveTo, location==RimnicuVilcea], Action[name==moveTo, location==Pitesti], Action[name==moveTo, location==Bucharest], Action[name==moveTo, location==Urziceni], Action[name==moveTo, location==Hirsova]]", agent.getActions().toString());
Assert.assertEquals(6, agent.getActions().size());
Assert.assertEquals("15", agent.getInstrumentation().getProperty("nodesExpanded"));
Assert.assertEquals("1", agent.getInstrumentation().getProperty("queueSize"));
Assert.assertEquals("5", agent.getInstrumentation().getProperty("maxQueueSize"));
}
use of aima.core.search.uninformed.UniformCostSearch 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.search.uninformed.UniformCostSearch 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.search.uninformed.UniformCostSearch in project aima-java by aimacode.
the class MapEnvironmentTest 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);
me = new MapEnvironment(aMap);
ma = new SimpleMapAgent(me.getMap(), me, new UniformCostSearch(), new String[] { "A" });
}
Aggregations