Search in sources :

Example 1 with Problem

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());
}
Also used : Color(javafx.scene.paint.Color) java.util(java.util) IntegrableApplication(aima.gui.fx.framework.IntegrableApplication) Canvas(javafx.scene.canvas.Canvas) Action(aima.core.agent.Action) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) SimulationPaneBuilder(aima.gui.fx.framework.SimulationPaneBuilder) Function(java.util.function.Function) Platform(javafx.application.Platform) Scheduler(aima.core.search.local.Scheduler) Parameter(aima.gui.fx.framework.Parameter) Paint(javafx.scene.paint.Paint) SimulationPaneCtrl(aima.gui.fx.framework.SimulationPaneCtrl) FunctionPlotterCtrl(aima.gui.fx.views.FunctionPlotterCtrl) BorderPane(javafx.scene.layout.BorderPane) DynamicAction(aima.core.agent.impl.DynamicAction) Problem(aima.core.search.framework.problem.Problem) SimulatedAnnealingSearch(aima.core.search.local.SimulatedAnnealingSearch) Pane(javafx.scene.layout.Pane) Function(java.util.function.Function) Action(aima.core.agent.Action) DynamicAction(aima.core.agent.impl.DynamicAction) Scheduler(aima.core.search.local.Scheduler) DynamicAction(aima.core.agent.impl.DynamicAction) GeneralProblem(aima.core.search.framework.problem.GeneralProblem)

Example 2 with Problem

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]);
}
Also used : DecimalFormat(java.text.DecimalFormat) MessageLogger(aima.gui.swing.framework.MessageLogger) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) LRTAStarAgent(aima.core.search.online.LRTAStarAgent) MapAdapter(aimax.osm.routing.MapAdapter) SearchForActions(aima.core.search.framework.SearchForActions) MapAgentFrame(aima.gui.swing.applications.agent.map.MapAgentFrame) ArrayList(java.util.ArrayList) Point2D(aima.core.util.math.geom.shapes.Point2D) AgentAppController(aima.gui.swing.framework.AgentAppController) List(java.util.List) Node(aima.core.search.framework.Node) OnlineSearchProblem(aima.core.search.framework.problem.OnlineSearchProblem) MapWayAttFilter(aimax.osm.data.MapWayAttFilter) ToDoubleFunction(java.util.function.ToDoubleFunction) MapNode(aimax.osm.data.entities.MapNode) Agent(aima.core.agent.Agent) SimulationThread(aima.gui.swing.framework.SimulationThread) aima.core.environment.map(aima.core.environment.map) Problem(aima.core.search.framework.problem.Problem) SearchFactory(aima.gui.util.SearchFactory) LRTAStarAgent(aima.core.search.online.LRTAStarAgent) Agent(aima.core.agent.Agent) MapNode(aimax.osm.data.entities.MapNode) aima.core.environment.map(aima.core.environment.map) Point2D(aima.core.util.math.geom.shapes.Point2D) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) MapAgentFrame(aima.gui.swing.applications.agent.map.MapAgentFrame)

Aggregations

GeneralProblem (aima.core.search.framework.problem.GeneralProblem)2 Problem (aima.core.search.framework.problem.Problem)2 Action (aima.core.agent.Action)1 Agent (aima.core.agent.Agent)1 DynamicAction (aima.core.agent.impl.DynamicAction)1 aima.core.environment.map (aima.core.environment.map)1 Node (aima.core.search.framework.Node)1 SearchForActions (aima.core.search.framework.SearchForActions)1 OnlineSearchProblem (aima.core.search.framework.problem.OnlineSearchProblem)1 Scheduler (aima.core.search.local.Scheduler)1 SimulatedAnnealingSearch (aima.core.search.local.SimulatedAnnealingSearch)1 LRTAStarAgent (aima.core.search.online.LRTAStarAgent)1 Point2D (aima.core.util.math.geom.shapes.Point2D)1 IntegrableApplication (aima.gui.fx.framework.IntegrableApplication)1 Parameter (aima.gui.fx.framework.Parameter)1 SimulationPaneBuilder (aima.gui.fx.framework.SimulationPaneBuilder)1 SimulationPaneCtrl (aima.gui.fx.framework.SimulationPaneCtrl)1 FunctionPlotterCtrl (aima.gui.fx.views.FunctionPlotterCtrl)1 MapAgentFrame (aima.gui.swing.applications.agent.map.MapAgentFrame)1 AgentAppController (aima.gui.swing.framework.AgentAppController)1