br.pucrio.inf.les.bdijade.core
Class Intention

java.lang.Object
  extended by br.pucrio.inf.les.bdijade.core.Intention

public class Intention
extends java.lang.Object

This class represents the intention abstraction from the BDI model. It represents a goal that the agent is committed to achieve. It has the associated goal and tries to execute plans to achieve it. It keeps a list of the executed plans, and after using all plans unsuccessfully, the goal is considered unachievable. When a plan fails, the BDI-interpreter cycle may invoke the tryToAchive() method again, so the intention tries another plan. During its execution, the intention can be set to no longer desired.

Author:
ingrid

Field Summary
private  PlanInstance currentPlan
           
private  java.util.Set<Plan> executedPlans
           
private  Goal goal
           
private  java.util.List<GoalListener> goalListeners
           
private  org.apache.commons.logging.Log log
           
private  BDIAgent myAgent
           
private  boolean noLongerDesired
           
private  Capability owner
           
private  boolean unachievable
           
private  boolean waiting
           
 
Constructor Summary
Intention(BDIAgent bdiAgent, Goal goal)
          Creates a new intention.
Intention(Goal goal, BDIAgent bdiAgent, Capability owner)
          Creates a new intention.
 
Method Summary
 void addGoalListener(GoalListener goalListener)
          Adds a listener to be notified when the given has achieve its end state.
protected  void dispatchPlan()
          Dispatches a new plan to try to achieve the intention goal.
 void doWait()
          Sets this intention to the GoalStatus.WAITING status.
private  void fireGoalEvent(GoalEvent goalEvent)
          Notify all listeners, if any, about a goal event.
 void fireGoalFinishedEvent()
          Fires a goal event when a goal has achieved its end state.
private  java.util.Set<Plan> getCanAchievePlans()
          Returns all plans from all capabilities that can achieve the goal.
 Goal getGoal()
           
 java.util.List<GoalListener> getGoalListeners()
           
 BDIAgent getMyAgent()
           
 GoalStatus getStatus()
          Returns the current goal status that this capability is committed to achieve.
 void noLongerDesire()
          Sets this intention as no longer desired.
 void removeGoalListener(GoalListener goalListener)
          Removes a goal listener to not be notified about the goal achievement anymore.
 void tryToAchive()
          Makes this intention starts to try to achieve the goal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentPlan

private PlanInstance currentPlan

executedPlans

private final java.util.Set<Plan> executedPlans

goal

private final Goal goal

goalListeners

private final java.util.List<GoalListener> goalListeners

log

private final org.apache.commons.logging.Log log

myAgent

private final BDIAgent myAgent

noLongerDesired

private boolean noLongerDesired

owner

private Capability owner

unachievable

private boolean unachievable

waiting

private boolean waiting
Constructor Detail

Intention

public Intention(BDIAgent bdiAgent,
                 Goal goal)
Creates a new intention. It is associated with an agent and the goal that it is committed to achieve.

Parameters:
goal - the goal to be achieved.
bdiAgent - the bdiAgent associated with this intention.

Intention

public Intention(Goal goal,
                 BDIAgent bdiAgent,
                 Capability owner)
Creates a new intention. It is associated with an agent and the goal that it is committed to achieve. It also receives a Capability as parameter indicating the owner of the goal (dispatched the goal).

Parameters:
goal - the goal to be achieved.
bdiAgent - the bdiAgent associated with this intention.
owner - the Capability that is owner of the goal.
Method Detail

addGoalListener

public void addGoalListener(GoalListener goalListener)
Adds a listener to be notified when the given has achieve its end state.

Parameters:
goalListener - the listener to be notified.

dispatchPlan

protected void dispatchPlan()
Dispatches a new plan to try to achieve the intention goal. It looks for plans that can achieve the goal that were not already tried and then starts the plan. If all possible plans were already executed, the intention is set to unachievable.


doWait

public void doWait()
Sets this intention to the GoalStatus.WAITING status. It may come from the GoalStatus.PLAN_FAILED or GoalStatus.TRYING_TO_ACHIEVE states.


fireGoalEvent

private void fireGoalEvent(GoalEvent goalEvent)
Notify all listeners, if any, about a goal event.

Parameters:
goalEvent -

fireGoalFinishedEvent

public void fireGoalFinishedEvent()
Fires a goal event when a goal has achieved its end state.

See Also:
GoalStatus

getCanAchievePlans

private java.util.Set<Plan> getCanAchievePlans()
Returns all plans from all capabilities that can achieve the goal.

Returns:
the set of plans that can achieve the goal.

getGoal

public Goal getGoal()
Returns:
the goal

getGoalListeners

public java.util.List<GoalListener> getGoalListeners()
Returns:
the goalListeners

getMyAgent

public BDIAgent getMyAgent()
Returns:
the myAgent

getStatus

public GoalStatus getStatus()
Returns the current goal status that this capability is committed to achieve.

Returns:
the current goal status.
See Also:
GoalStatus

noLongerDesire

public void noLongerDesire()
Sets this intention as no longer desired. It stops the current plan execution. It changes the goal status from GoalStatus.WAITING, GoalStatus.PLAN_FAILED or GoalStatus.TRYING_TO_ACHIEVE to GoalStatus.NO_LONGER_DESIRED.


removeGoalListener

public void removeGoalListener(GoalListener goalListener)
Removes a goal listener to not be notified about the goal achievement anymore.

Parameters:
goalListener - the goal listener to be removed.

tryToAchive

public void tryToAchive()
Makes this intention starts to try to achieve the goal. It changes the goal status from GoalStatus.WAITING or GoalStatus.PLAN_FAILED to GoalStatus.TRYING_TO_ACHIEVE.