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());
}
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));
}
}
}
Aggregations