use of aima.core.search.framework.problem.Problem in project aima-java by aimacode.
the class SimulatedAnnealingMaximumFinderApp method simulate.
/** Starts the experiment. */
@SuppressWarnings("unchecked")
public void simulate() {
List<Action> actions = new ArrayList<>(1);
actions.add(new DynamicAction("Move"));
Problem<Double, Action> problem = new GeneralProblem<>(getRandomState(), s -> actions, (s, a) -> getSuccessor(s), s -> false);
Function<Double, Double> func = (Function<Double, Double>) simPaneCtrl.getParamValue(PARAM_FUNC_SELECT);
Scheduler scheduler = new Scheduler(simPaneCtrl.getParamAsInt(PARAM_K), simPaneCtrl.getParamAsDouble(PARAM_LAMBDA), simPaneCtrl.getParamAsInt(PARAM_MAX_ITER));
search = new SimulatedAnnealingSearch<>(n -> 1 - func.apply(n.getState()), scheduler);
search.addNodeListener(n -> updateStateView(n.getState()));
search.findActions(problem);
updateStateView(search.getLastSearchState());
}
use of aima.core.search.framework.problem.Problem 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