Search in sources :

Example 1 with DynamicAction

use of aima.core.agent.impl.DynamicAction 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 DynamicAction

use of aima.core.agent.impl.DynamicAction in project aima-java by aimacode.

the class VacuumView method paintComponent.

/**
	 * Creates a 2D-graphics showing the agent in its environment. Locations are
	 * represented as rectangles, dirt as grey background color, and the agent
	 * as red Pacman.
	 */
@Override
public void paintComponent(Graphics g) {
    List<String> locations = getLocations();
    adjustTransformation(0, 0, 11 * locations.size() - 1, 10);
    Graphics2D g2 = (Graphics2D) g;
    g2.setBackground(Color.white);
    g2.clearRect(0, 0, getWidth(), getHeight());
    for (int i = 0; i < locations.size(); i++) {
        String location = locations.get(i);
        Agent agent = getAgent(location);
        if (isDirty(location)) {
            g2.setColor(Color.LIGHT_GRAY);
            g2.fillRect(x(11 * i), y(0), scale(10), scale(10));
        }
        g2.setColor(Color.black);
        g2.drawRect(x(11 * i), y(0), scale(10), scale(10));
        g2.drawString(location.toString(), x(11 * i) + 10, y(0) + 20);
        if (agent != null) {
            Action action = lastActions.get(agent);
            g2.setColor(Color.RED);
            if (action == null || !((DynamicAction) action).getAttribute("name").equals("Suck"))
                g2.fillArc(x(11 * i + 2), y(2), scale(6), scale(6), 200, 320);
            else
                g2.fillOval(x(11 * i + 2), y(2), scale(6), scale(6));
        }
    }
}
Also used : Agent(aima.core.agent.Agent) Action(aima.core.agent.Action) DynamicAction(aima.core.agent.impl.DynamicAction) Graphics2D(java.awt.Graphics2D)

Aggregations

Action (aima.core.agent.Action)2 DynamicAction (aima.core.agent.impl.DynamicAction)2 Agent (aima.core.agent.Agent)1 GeneralProblem (aima.core.search.framework.problem.GeneralProblem)1 Problem (aima.core.search.framework.problem.Problem)1 Scheduler (aima.core.search.local.Scheduler)1 SimulatedAnnealingSearch (aima.core.search.local.SimulatedAnnealingSearch)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 Graphics2D (java.awt.Graphics2D)1 java.util (java.util)1 Function (java.util.function.Function)1 Platform (javafx.application.Platform)1 Canvas (javafx.scene.canvas.Canvas)1 BorderPane (javafx.scene.layout.BorderPane)1 Pane (javafx.scene.layout.Pane)1 Color (javafx.scene.paint.Color)1