jadex.quickstart.cleanerworld.single.CleanerBDIAgentA2 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-quickstart Show documentation
Show all versions of jadex-applications-quickstart Show documentation
The Jadex quickstart package contains the ready to use "Cleanerworld" environment as a testbed for experimenting with autonomous agents and intelligent behavior.
package jadex.quickstart.cleanerworld.single;
import jadex.bdiv3.annotation.Goal;
import jadex.bdiv3.annotation.Plan;
import jadex.bdiv3.annotation.Trigger;
import jadex.bdiv3.features.IBDIAgentFeature;
import jadex.bridge.service.annotation.OnStart;
import jadex.micro.annotation.Agent;
import jadex.quickstart.cleanerworld.environment.SensorActuator;
import jadex.quickstart.cleanerworld.gui.SensorGui;
/**
* Use the recur flag to execute goals periodically.
*/
@Agent(type="bdi") // This annotation makes the java class and agent and enabled BDI features
public class CleanerBDIAgentA2
{
//-------- fields holding agent data --------
/** The sensor/actuator object gives access to the environment of the cleaner robot. */
private SensorActuator actsense = new SensorActuator();
//-------- simple example behavior --------
/**
* The body is executed when the agent is started.
* @param bdifeature Provides access to bdi specific methods
*/
@OnStart // This annotation informs the Jadex platform to call this method once the agent is started
private void exampleBehavior(IBDIAgentFeature bdi)
{
// Open a window showing the agent's perceptions
new SensorGui(actsense).setVisible(true);
// Create and dispatch a goal.
bdi.dispatchTopLevelGoal(new PerformPatrol());
}
//-------- inner classes that represent agent goals --------
/**
* A goal to patrol around in the museum.
*/
@Goal(recur=true) // The goal annotation allows instances of a Java class to be dispatched as goals of the agent.
class PerformPatrol {}
//-------- methods that represent plans (i.e. predefined recipes for working on certain goals) --------
/**
* Declare a plan for the PerformPatrol goal by using a method with @Plan and @Trigger annotation.
*/
@Plan(trigger=@Trigger(goals=PerformPatrol.class)) // The plan annotation makes a method or class a plan. The trigger states, when the plan should considered for execution.
private void performPatrolPlan()
{
// Follow a simple path around the four corners of the museum and back to the first corner.
System.out.println("Starting performPatrolPlan()");
actsense.moveTo(0.1, 0.1);
actsense.moveTo(0.1, 0.9);
actsense.moveTo(0.9, 0.9);
actsense.moveTo(0.9, 0.1);
actsense.moveTo(0.1, 0.1);
}
}