use of aima.gui.swing.framework.MessageLogger 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