use of aima.core.search.framework.problem.GeneralProblem in project aima-java by aimacode.
the class IterativeDeepeningSearchTest method testIterativeDeepeningSearch.
@Test
public void testIterativeDeepeningSearch() {
try {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(8), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
SearchForActions<NQueensBoard, QueenAction> search = new IterativeDeepeningSearch<>();
List<QueenAction> actions = search.findActions(problem);
assertCorrectPlacement(actions);
Assert.assertEquals("3656", search.getMetrics().get("nodesExpanded"));
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception should not occur");
}
}
use of aima.core.search.framework.problem.GeneralProblem in project aima-java by aimacode.
the class UniformCostSearchTest method testUniformCostUnSuccesfulSearch.
@Test
public void testUniformCostUnSuccesfulSearch() throws Exception {
Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(3), 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(0, actions.size());
Assert.assertEquals("6", agent.getInstrumentation().getProperty("nodesExpanded"));
// Will be 0 as did not reach goal state.
Assert.assertEquals("0", agent.getInstrumentation().getProperty("pathCost"));
}
use of aima.core.search.framework.problem.GeneralProblem in project aima-java by aimacode.
the class OsmAgentController method initAgents.
/** Creates new agents and adds them to the current environment. */
protected void initAgents(MessageLogger logger) {
List<MapNode> markers = map.getOsmMap().getMarkers();
if (markers.size() < 2) {
logger.log("Error: Please set two markers with mouse-left.");
return;
}
String[] locs = new String[markers.size()];
for (int i = 0; i < markers.size(); i++) {
MapNode node = markers.get(i);
Point2D pt = new Point2D(node.getLon(), node.getLat());
locs[i] = map.getNearestLocation(pt);
}
MapAgentFrame.SelectionState state = frame.getSelection();
heuristic = createHeuristic(state.getIndex(MapAgentFrame.HEURISTIC_SEL), locs[1]);
search = SearchFactory.getInstance().createSearch(state.getIndex(MapAgentFrame.SEARCH_SEL), state.getIndex(MapAgentFrame.Q_SEARCH_IMPL_SEL), heuristic);
Agent agent = null;
switch(state.getIndex(MapAgentFrame.AGENT_SEL)) {
case 0:
agent = new SimpleMapAgent(map, env, search, new String[] { locs[1] });
break;
case 1:
Problem<String, MoveToAction> p = new BidirectionalMapProblem(map, null, locs[1]);
OnlineSearchProblem<String, MoveToAction> osp = new GeneralProblem<>(null, p::getActions, null, p::testGoal, p::getStepCosts);
agent = new LRTAStarAgent<>(osp, MapFunctions.createPerceptToStateFunction(), s -> heuristic.applyAsDouble(new Node<>(s)));
break;
}
env.addAgent(agent, locs[0]);
}
Aggregations