Search in sources :

Example 1 with Agent

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

the class VacuumEnvironmentViewCtrl method updateEnvStateView.

@Override
protected void updateEnvStateView(Environment env) {
    if (env instanceof VacuumEnvironment) {
        VacuumEnvironment vEnv = (VacuumEnvironment) env;
        for (String loc : locations) {
            BorderPane pane = getLocPane(loc);
            if (vEnv.getLocationState(loc).equals(LocationState.Dirty))
                pane.setStyle("-fx-background-color: lightgrey");
            else
                pane.setStyle("-fx-background-color: white");
            pane.setCenter(null);
        }
        for (Agent agent : vEnv.getAgents()) {
            BorderPane pane = getLocPane(vEnv.getAgentLocation(agent));
            pane.setCenter(createAgentRep(agent == agentInAction));
        }
    }
}
Also used : Agent(aima.core.agent.Agent) BorderPane(javafx.scene.layout.BorderPane) VacuumEnvironment(aima.core.environment.vacuum.VacuumEnvironment)

Example 2 with Agent

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

the class MapEnvironmentViewCtrl method update.

protected void update() {
    envStateView.getChildren().clear();
    if (env != null) {
        double scale = adjustTransform();
        Map map = env.getMap();
        // print connections
        for (String loc1 : map.getLocations()) {
            Point2D pt1 = map.getPosition(loc1);
            for (String loc2 : map.getPossibleNextLocations(loc1)) {
                Point2D pt2 = map.getPosition(loc2);
                Shape line = new Line(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY());
                line.setStroke(Color.LIGHTGRAY);
                envStateView.getChildren().add(line);
            }
        }
        // print track of first agent
        if (!env.getAgents().isEmpty()) {
            String aLoc = env.getAgentLocation(env.getAgents().get(0));
            if (track.isEmpty() || !Objects.equals(track.get(track.size() - 1), aLoc))
                track.add(aLoc);
            for (int i = 1; i < track.size(); i++) {
                Point2D pt1 = map.getPosition(track.get(i - 1));
                Point2D pt2 = map.getPosition(track.get(i));
                Shape line = new Line(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY());
                line.setStroke(Color.RED);
                line.setStrokeWidth(2);
                envStateView.getChildren().add(line);
            }
        }
        // print locations
        for (String loc : map.getLocations()) {
            Point2D point = map.getPosition(loc);
            Text text = new Text(point.getX() + 10 / scale, point.getY(), loc);
            text.setFont(new Font(12.0 / scale));
            envStateView.getChildren().add(text);
            envStateView.getChildren().add(new Circle(point.getX(), point.getY(), 2 / scale));
        }
        // print agent locations
        for (Agent agent : env.getAgents()) {
            String loc = env.getAgentLocation(agent);
            if (loc != null) {
                Point2D pt = map.getPosition(loc);
                envStateView.getChildren().add(new Circle(pt.getX(), pt.getY(), 8 / scale, Color.RED));
            }
        }
        // print goal
        if (goal != null) {
            Point2D pt = map.getPosition(goal);
            envStateView.getChildren().add(new Circle(pt.getX(), pt.getY(), 6 / scale, Color.GREEN));
        }
    }
}
Also used : Line(javafx.scene.shape.Line) Circle(javafx.scene.shape.Circle) Agent(aima.core.agent.Agent) Shape(javafx.scene.shape.Shape) Point2D(aima.core.util.math.geom.shapes.Point2D) Text(javafx.scene.text.Text) Map(aima.core.environment.map.Map) Font(javafx.scene.text.Font)

Example 3 with Agent

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

the class AbstractEnvironment method step.

/**
	 * Central template method for controlling agent simulation. The concrete
	 * behavior is determined by the primitive operations
	 * {@link #getPerceptSeenBy(Agent)}, {@link #executeAction(Agent, Action)},
	 * and {@link #createExogenousChange()}.
	 */
public void step() {
    for (Agent agent : agents) {
        if (agent.isAlive()) {
            Percept percept = getPerceptSeenBy(agent);
            Action anAction = agent.execute(percept);
            executeAction(agent, anAction);
            notifyEnvironmentViews(agent, percept, anAction);
        }
    }
    createExogenousChange();
}
Also used : Agent(aima.core.agent.Agent) Action(aima.core.agent.Action) Percept(aima.core.agent.Percept)

Example 4 with Agent

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

the class TrivialVacuumDemo method main.

public static void main(String[] args) {
    // create environment with random state of cleaning.
    Environment env = new VacuumEnvironment();
    EnvironmentView view = new SimpleEnvironmentView();
    env.addEnvironmentView(view);
    Agent a = null;
    a = new ModelBasedReflexVacuumAgent();
    // a = new ReflexVacuumAgent();
    // a = new SimpleReflexVacuumAgent();
    // a = new TableDrivenVacuumAgent();
    env.addAgent(a);
    env.step(16);
    env.notifyViews("Performance=" + env.getPerformanceMeasure(a));
}
Also used : ModelBasedReflexVacuumAgent(aima.core.environment.vacuum.ModelBasedReflexVacuumAgent) Agent(aima.core.agent.Agent) VacuumEnvironment(aima.core.environment.vacuum.VacuumEnvironment) ModelBasedReflexVacuumAgent(aima.core.environment.vacuum.ModelBasedReflexVacuumAgent) EnvironmentView(aima.core.agent.EnvironmentView) SimpleEnvironmentView(aima.core.agent.impl.SimpleEnvironmentView) VacuumEnvironment(aima.core.environment.vacuum.VacuumEnvironment) Environment(aima.core.agent.Environment) SimpleEnvironmentView(aima.core.agent.impl.SimpleEnvironmentView)

Example 5 with Agent

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

the class MapAgentView method getAgentLocs.

/** Returns the locations of all agents. */
protected List<String> getAgentLocs() {
    List<String> result = new ArrayList<String>();
    MapEnvironment mEnv = getMapEnv();
    for (Agent a : mEnv.getAgents()) result.add(mEnv.getAgentLocation(a));
    return result;
}
Also used : Agent(aima.core.agent.Agent) ArrayList(java.util.ArrayList) MapEnvironment(aima.core.environment.map.MapEnvironment)

Aggregations

Agent (aima.core.agent.Agent)10 Action (aima.core.agent.Action)2 Map (aima.core.environment.map.Map)2 VacuumEnvironment (aima.core.environment.vacuum.VacuumEnvironment)2 Point2D (aima.core.util.math.geom.shapes.Point2D)2 ArrayList (java.util.ArrayList)2 Environment (aima.core.agent.Environment)1 EnvironmentView (aima.core.agent.EnvironmentView)1 Percept (aima.core.agent.Percept)1 DynamicAction (aima.core.agent.impl.DynamicAction)1 SimpleEnvironmentView (aima.core.agent.impl.SimpleEnvironmentView)1 aima.core.environment.map (aima.core.environment.map)1 MapEnvironment (aima.core.environment.map.MapEnvironment)1 ModelBasedReflexVacuumAgent (aima.core.environment.vacuum.ModelBasedReflexVacuumAgent)1 Node (aima.core.search.framework.Node)1 SearchForActions (aima.core.search.framework.SearchForActions)1 GeneralProblem (aima.core.search.framework.problem.GeneralProblem)1 OnlineSearchProblem (aima.core.search.framework.problem.OnlineSearchProblem)1 Problem (aima.core.search.framework.problem.Problem)1 LRTAStarAgent (aima.core.search.online.LRTAStarAgent)1