bdi4jade
Changes
bdi-jade/APDescription.txt 1(+1 -0)
bdi-jade/MTPs-Main-Container.txt 1(+1 -0)
bdi-jade/src/bdi4jade/core/BDIAgent.java 37(+34 -3)
bdi-jade/src/bdi4jade/core/PlanLibrary.java 17(+17 -0)
bdi-jade/src/bdi4jade/extension/planselection/utilitybased/UtilityBasedPlanSelectionStrategy.java 15(+5 -10)
bdi-jade/src/bdi4jade/plan/AbstractPlan.java 23(+5 -18)
bdi-jade/src/bdi4jade/plan/AbstractPlanBody.java 352(+352 -0)
bdi-jade/src/bdi4jade/plan/Plan.java 5(+2 -3)
bdi-jade/src/bdi4jade/plan/PlanBody.java 248(+58 -190)
bdi-jade/src/bdi4jade/plan/SimplePlan.java 95(+47 -48)
Details
bdi-jade/APDescription.txt 1(+1 -0)
diff --git a/bdi-jade/APDescription.txt b/bdi-jade/APDescription.txt
new file mode 100644
index 0000000..398983c
--- /dev/null
+++ b/bdi-jade/APDescription.txt
@@ -0,0 +1 @@
+( ap-description :name "192.168.0.2:1099/JADE" :ap-services (set ( ap-service :name fipa.mts.mtp.http.std :type fipa.mts.mtp.http.std :addresses (sequence http://ingrid-asus:7778/acc))))
bdi-jade/MTPs-Main-Container.txt 1(+1 -0)
diff --git a/bdi-jade/MTPs-Main-Container.txt b/bdi-jade/MTPs-Main-Container.txt
new file mode 100644
index 0000000..6b6c35d
--- /dev/null
+++ b/bdi-jade/MTPs-Main-Container.txt
@@ -0,0 +1 @@
+http://ingrid-asus:7778/acc
diff --git a/bdi-jade/src/bdi4jade/belief/AbstractBelief.java b/bdi-jade/src/bdi4jade/belief/AbstractBelief.java
index 8e79d77..b8a8202 100644
--- a/bdi-jade/src/bdi4jade/belief/AbstractBelief.java
+++ b/bdi-jade/src/bdi4jade/belief/AbstractBelief.java
@@ -27,7 +27,7 @@ import java.util.HashSet;
import java.util.Set;
import bdi4jade.core.BeliefBase;
-import bdi4jade.util.MetadataElementImpl;
+import bdi4jade.core.MetadataElementImpl;
/**
* @author ingrid
diff --git a/bdi-jade/src/bdi4jade/belief/Belief.java b/bdi-jade/src/bdi4jade/belief/Belief.java
index 0a71eff..422c7e4 100644
--- a/bdi-jade/src/bdi4jade/belief/Belief.java
+++ b/bdi-jade/src/bdi4jade/belief/Belief.java
@@ -28,7 +28,7 @@ import java.io.Serializable;
import java.util.Set;
import bdi4jade.core.BeliefBase;
-import bdi4jade.util.MetadataElement;
+import bdi4jade.core.MetadataElement;
/**
* Represents a belief of the belief base. It has a name and a value associate
bdi-jade/src/bdi4jade/core/BDIAgent.java 37(+34 -3)
diff --git a/bdi-jade/src/bdi4jade/core/BDIAgent.java b/bdi-jade/src/bdi4jade/core/BDIAgent.java
index 679e93c..300a7c9 100644
--- a/bdi-jade/src/bdi4jade/core/BDIAgent.java
+++ b/bdi-jade/src/bdi4jade/core/BDIAgent.java
@@ -43,13 +43,13 @@ import bdi4jade.belief.Belief;
import bdi4jade.event.GoalListener;
import bdi4jade.goal.Goal;
import bdi4jade.goal.GoalStatus;
+import bdi4jade.goal.Softgoal;
import bdi4jade.message.BDIAgentMsgReceiver;
import bdi4jade.message.BDIAgentMsgReceiver.BDIAgentMatchExpression;
import bdi4jade.reasoning.BeliefRevisionStrategy;
import bdi4jade.reasoning.DeliberationFunction;
import bdi4jade.reasoning.OptionGenerationFunction;
import bdi4jade.reasoning.PlanSelectionStrategy;
-import bdi4jade.util.DefaultCapability;
import bdi4jade.util.reasoning.DefaultBeliefRevisionStrategy;
import bdi4jade.util.reasoning.DefaultDeliberationFunction;
import bdi4jade.util.reasoning.DefaultOptionGenerationFunction;
@@ -194,6 +194,7 @@ public class BDIAgent extends Agent {
private OptionGenerationFunction optionGenerationFunction;
private PlanSelectionStrategy planSelectionStrategy;
private final Capability rootCapability;
+ private final Set<Softgoal> softgoals;
/**
* Default constructor.
@@ -213,6 +214,7 @@ public class BDIAgent extends Agent {
this.optionGenerationFunction = new DefaultOptionGenerationFunction();
this.deliberationFunction = new DefaultDeliberationFunction();
this.planSelectionStrategy = new DefaultPlanSelectionStrategy();
+ this.softgoals = new HashSet<Softgoal>();
}
/**
@@ -293,6 +295,16 @@ public class BDIAgent extends Agent {
}
/**
+ * Adds a new softgoal to this agent.
+ *
+ * @param softgoal
+ * the softgoal to be pursued.
+ */
+ public void addSoftgoal(Softgoal softgoal) {
+ this.softgoals.add(softgoal);
+ }
+
+ /**
* Drops a given goal of this agent. If the goal is not part of the agent's
* current goals, no action is performed.
*
@@ -311,6 +323,18 @@ public class BDIAgent extends Agent {
}
/**
+ * Drops a given softgoal of this agent. If the softgoal is not part of the
+ * agent's current softgoals, no action is performed.
+ *
+ * @param softgoal
+ * the softgoal to be dropped.
+ */
+
+ public void dropSoftoal(Softgoal softgoal) {
+ this.softgoals.remove(softgoal);
+ }
+
+ /**
* Returns a collection of all beliefs from all capabilities of this agent.
* It may have two equivalent beliefs, i.e. beliefs with the same name.
*
@@ -369,6 +393,15 @@ public class BDIAgent extends Agent {
}
/**
+ * Gets all softgoals of this agent.
+ *
+ * @return the set of softgoals.
+ */
+ public Set<Softgoal> getAllSoftgoals() {
+ return this.softgoals;
+ }
+
+ /**
* @return the beliefRevisionStrategy
*/
public BeliefRevisionStrategy getBeliefRevisionStrategy() {
@@ -526,7 +559,6 @@ public class BDIAgent extends Agent {
this.addBehaviour(new BDIAgentMsgReceiver(this,
new BDIAgentMatchExpression()));
this.addBehaviour(bdiInterpreter);
- this.addCapability(new DefaultCapability());
init();
}
@@ -541,7 +573,6 @@ public class BDIAgent extends Agent {
rootCapability.removeChild(capability);
}
}
-
}
}
diff --git a/bdi-jade/src/bdi4jade/core/BeliefBase.java b/bdi-jade/src/bdi4jade/core/BeliefBase.java
index bf00ef4..1bea1c0 100644
--- a/bdi-jade/src/bdi4jade/core/BeliefBase.java
+++ b/bdi-jade/src/bdi4jade/core/BeliefBase.java
@@ -34,8 +34,8 @@ import java.util.Set;
import bdi4jade.belief.Belief;
import bdi4jade.event.BeliefEvent;
-import bdi4jade.event.BeliefListener;
import bdi4jade.event.BeliefEvent.Action;
+import bdi4jade.event.BeliefListener;
import bdi4jade.exception.BeliefAlreadyExistsException;
/**
diff --git a/bdi-jade/src/bdi4jade/core/Capability.java b/bdi-jade/src/bdi4jade/core/Capability.java
index 8cd179f..589f497 100644
--- a/bdi-jade/src/bdi4jade/core/Capability.java
+++ b/bdi-jade/src/bdi4jade/core/Capability.java
@@ -45,11 +45,11 @@ public class Capability implements Serializable {
protected final BeliefBase beliefBase;
protected final Set<Capability> children;
protected final String id;
+ private final Log log;
protected BDIAgent myAgent;
protected Capability parent;
protected final PlanLibrary planLibrary;
private boolean start;
- private final Log log;
/**
* Creates a new capability. It uses {@link BeliefBase} and
diff --git a/bdi-jade/src/bdi4jade/core/Intention.java b/bdi-jade/src/bdi4jade/core/Intention.java
index 2346610..88991c7 100644
--- a/bdi-jade/src/bdi4jade/core/Intention.java
+++ b/bdi-jade/src/bdi4jade/core/Intention.java
@@ -38,7 +38,7 @@ import bdi4jade.goal.Goal;
import bdi4jade.goal.GoalStatus;
import bdi4jade.plan.Plan;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBodyInterface;
+import bdi4jade.plan.PlanBody;
/**
* This class represents the intention abstraction from the BDI model. It
@@ -54,7 +54,7 @@ import bdi4jade.plan.PlanBodyInterface;
*/
public class Intention {
- private PlanBodyInterface currentPlan;
+ private PlanBody currentPlan;
private final Set<Plan> executedPlans;
private final Goal goal;
private final List<GoalListener> goalListeners;
bdi-jade/src/bdi4jade/core/PlanLibrary.java 17(+17 -0)
diff --git a/bdi-jade/src/bdi4jade/core/PlanLibrary.java b/bdi-jade/src/bdi4jade/core/PlanLibrary.java
index 87163c1..0c06b83 100644
--- a/bdi-jade/src/bdi4jade/core/PlanLibrary.java
+++ b/bdi-jade/src/bdi4jade/core/PlanLibrary.java
@@ -30,6 +30,11 @@ import java.util.Set;
import bdi4jade.goal.Goal;
import bdi4jade.plan.Plan;
+import bdi4jade.plan.SimplePlan;
+import bdi4jade.util.goal.ParallelGoal;
+import bdi4jade.util.goal.SequentialGoal;
+import bdi4jade.util.plan.ParallelGoalPlanBody;
+import bdi4jade.util.plan.SequentialGoalPlanBody;
/**
* This class represents the plan library of a capability. It aggregates the
@@ -67,10 +72,22 @@ public class PlanLibrary implements Serializable {
addPlan(plan);
}
}
+ addDefaultPlans();
init();
}
/**
+ * Adds a set of default plans to this library. It adds plans to achieve the
+ * sequential and parallel goals. This method may be overriden by children
+ * capabilities.
+ */
+ protected void addDefaultPlans() {
+ addPlan(new SimplePlan(SequentialGoal.class,
+ SequentialGoalPlanBody.class));
+ addPlan(new SimplePlan(ParallelGoal.class, ParallelGoalPlanBody.class));
+ }
+
+ /**
* Adds a plan to the plan library.
*
* @param plan
diff --git a/bdi-jade/src/bdi4jade/exception/BeliefAlreadyExistsException.java b/bdi-jade/src/bdi4jade/exception/BeliefAlreadyExistsException.java
index 0325242..af69221 100644
--- a/bdi-jade/src/bdi4jade/exception/BeliefAlreadyExistsException.java
+++ b/bdi-jade/src/bdi4jade/exception/BeliefAlreadyExistsException.java
@@ -60,4 +60,5 @@ public class BeliefAlreadyExistsException extends RuntimeException {
public String toString() {
return "Belief already exists exception: " + belief;
}
+
}
diff --git a/bdi-jade/src/bdi4jade/exception/PlanInstantiationException.java b/bdi-jade/src/bdi4jade/exception/PlanInstantiationException.java
index b798e24..51ef6fb 100644
--- a/bdi-jade/src/bdi4jade/exception/PlanInstantiationException.java
+++ b/bdi-jade/src/bdi4jade/exception/PlanInstantiationException.java
@@ -22,8 +22,6 @@
package bdi4jade.exception;
-import bdi4jade.plan.PlanBodyInterface;
-
/**
* This method represents an exception that occurred during the instantiation
* process of a {@link PlanBodyInterface}.
bdi-jade/src/bdi4jade/plan/AbstractPlan.java 23(+5 -18)
diff --git a/bdi-jade/src/bdi4jade/plan/AbstractPlan.java b/bdi-jade/src/bdi4jade/plan/AbstractPlan.java
index cdddf70..3bb155c 100644
--- a/bdi-jade/src/bdi4jade/plan/AbstractPlan.java
+++ b/bdi-jade/src/bdi4jade/plan/AbstractPlan.java
@@ -25,20 +25,14 @@ package bdi4jade.plan;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
+import bdi4jade.core.MetadataElementImpl;
import bdi4jade.core.PlanLibrary;
import bdi4jade.exception.PlanInstantiationException;
-import bdi4jade.extension.softgoal.core.Softgoal;
-import bdi4jade.extension.softgoal.plan.PlanContribution;
-import bdi4jade.extension.softgoal.plan.PlanGoalDependency;
import bdi4jade.goal.Goal;
import bdi4jade.message.MessageGoal;
-import bdi4jade.util.MetadataElementImpl;
/**
* This class represents the plan abstraction. It defines the goals that the
@@ -108,12 +102,6 @@ public abstract class AbstractPlan extends MetadataElementImpl implements Plan {
this.messageTemplates.add(messageTemplate);
}
initMessageTemplates();
-
- // Metadata
- putMetadata(DefaultMetadata.CONTRIBUTIONS,
- new HashMap<Softgoal, List<PlanContribution>>());
- putMetadata(DefaultMetadata.DEPENDENCIES,
- new ArrayList<PlanGoalDependency>());
}
/**
@@ -190,23 +178,22 @@ public abstract class AbstractPlan extends MetadataElementImpl implements Plan {
/**
* Instantiate the plan body of this plan. It must implement the
- * {@link PlanBodyInterface} interface.
+ * {@link PlanBody} interface.
*
* @return the instantiated plan body.
* @throws PlanInstantiationException
* if an error occurred during the instantiation process.
*/
- public abstract PlanBodyInterface createPlanBody()
- throws PlanInstantiationException;
+ public abstract PlanBody createPlanBody() throws PlanInstantiationException;
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
- if (!(obj instanceof AbstractPlan))
+ if (!(obj instanceof Plan))
return false;
- return this.id.equals(((AbstractPlan) obj).id);
+ return this.id.equals(((Plan) obj).getId());
}
/**
bdi-jade/src/bdi4jade/plan/AbstractPlanBody.java 352(+352 -0)
diff --git a/bdi-jade/src/bdi4jade/plan/AbstractPlanBody.java b/bdi-jade/src/bdi4jade/plan/AbstractPlanBody.java
new file mode 100644
index 0000000..acf778c
--- /dev/null
+++ b/bdi-jade/src/bdi4jade/plan/AbstractPlanBody.java
@@ -0,0 +1,352 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2011 Ingrid Nunes
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://inf.ufrgs.br/~ingridnunes/bdi4jade/
+//
+//----------------------------------------------------------------------------
+
+package bdi4jade.plan;
+
+import jade.core.behaviours.Behaviour;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import bdi4jade.core.BeliefBase;
+import bdi4jade.core.Intention;
+import bdi4jade.event.GoalEvent;
+import bdi4jade.event.GoalFinishedEvent;
+import bdi4jade.exception.PlanInstantiationException;
+import bdi4jade.goal.Goal;
+import bdi4jade.plan.Plan.EndState;
+
+/**
+ * This class represents a plan that has been instantiated to be executed.
+ *
+ * @author ingrid
+ */
+public abstract class AbstractPlanBody extends Behaviour implements PlanBody {
+
+ private static final long serialVersionUID = -6488256636028800227L;
+
+ private EndState endState;
+ private final List<GoalFinishedEvent> goalEventQueue;
+ private Intention intention;
+ private Plan plan;
+ private final List<Goal> subgoals;
+
+ /**
+ * Creates a new plan body instance.
+ */
+ public AbstractPlanBody() {
+ this.plan = null;
+ this.intention = null;
+ this.endState = null;
+ this.subgoals = new ArrayList<Goal>();
+ this.goalEventQueue = new LinkedList<GoalFinishedEvent>();
+ }
+
+ /**
+ * Dispatches a goal to be achieved.
+ *
+ * @param goal
+ * the goal to be dispatched.
+ */
+ public void dispatchGoal(Goal goal) {
+ this.intention.getMyAgent().addGoal(goal);
+ }
+
+ /**
+ * Dispatches a goal to be achieved, using the capability (or its children
+ * capabilities) associated with the plan.
+ *
+ * @param goal
+ * the goal to be dispatched.
+ */
+ public void dispatchProtectedGoal(Goal goal) {
+ this.intention.getMyAgent().addGoal(
+ this.plan.getPlanLibrary().getCapability(), goal);
+ }
+
+ /**
+ * Dispatches a subgoal to be achieved, using the capability (or its
+ * children capabilities) associated with the plan.
+ *
+ * @param subgoal
+ * the subgoal to be dispatched.
+ */
+ public void dispatchProtectedSubgoal(Goal subgoal) {
+ this.intention.getMyAgent().addGoal(
+ this.plan.getPlanLibrary().getCapability(), subgoal);
+ synchronized (subgoals) {
+ this.subgoals.add(subgoal);
+ }
+ }
+
+ /**
+ * Dispatches a subgoal to be achieved, using the capability (or its
+ * children capabilities) associated with the plan, and registers itself as
+ * a listener to receive a notification of the end of execution of the goal.
+ *
+ * @param subgoal
+ * the subgoal to be dispatched.
+ */
+ public void dispatchProtectedSubgoalAndListen(Goal subgoal) {
+ this.intention.getMyAgent().addGoal(
+ this.plan.getPlanLibrary().getCapability(), subgoal, this);
+ synchronized (subgoals) {
+ this.subgoals.add(subgoal);
+ }
+ }
+
+ /**
+ * Dispatches a subgoal to be achieved.
+ *
+ * @param subgoal
+ * the subgoal to be dispatched.
+ */
+ public void dispatchSubgoal(Goal subgoal) {
+ this.intention.getMyAgent().addGoal(subgoal);
+ synchronized (subgoals) {
+ this.subgoals.add(subgoal);
+ }
+ }
+
+ /**
+ * Dispatches a subgoal to be achieved and registers itself as a listener to
+ * receive a notification of the end of execution of the goal.
+ *
+ * @param subgoal
+ * the subgoal to be dispatched.
+ */
+ public void dispatchSubgoalAndListen(Goal subgoal) {
+ this.intention.getMyAgent().addGoal(subgoal, this);
+ synchronized (subgoals) {
+ this.subgoals.add(subgoal);
+ }
+ }
+
+ @Override
+ public final boolean done() {
+ synchronized (plan) {
+ return getEndState() != null;
+ }
+ }
+
+ /**
+ * Drops all current subgoals dispatched by this plan.
+ */
+ private void dropSubgoals() {
+ synchronized (subgoals) {
+ Iterator<Goal> it = subgoals.iterator();
+ while (it.hasNext()) {
+ Goal subgoal = it.next();
+ this.intention.getMyAgent().setNoLongerDesired(subgoal);
+ it.remove();
+ }
+ }
+ }
+
+ /**
+ * Returns the belief base of the capability.
+ *
+ * @return the belief base containing the beliefs.
+ */
+ public BeliefBase getBeliefBase() {
+ return this.plan.getPlanLibrary().getCapability().getBeliefBase();
+ }
+
+ /**
+ * Returns the end state of plan. A null value means that the plan is still
+ * in execution. If the plan body has come to an end state, it invokes the
+ * method to set the output parameters of the goal, in case the plan body
+ * implements the {@link OutputPlanBody} interface (this is invoked only
+ * once). If the plan body has come to an end state, it sets all of its
+ * subgoals as no longer desired, in case they are still trying to be
+ * achieved.
+ *
+ * @return the end state of the plan.
+ */
+ public EndState getEndState() {
+ synchronized (plan) {
+ return endState;
+ }
+ }
+
+ /**
+ * Returns the goal to be achieved by this plan instance.
+ *
+ * @return the goal.
+ */
+ public final Goal getGoal() {
+ return this.intention.getGoal();
+ }
+
+ /**
+ * Returns a goal event from the queue. If the queue is empty, the behavior
+ * associated with this plan instance is blocked.
+ *
+ * @return the goal event or null if the queue is empty.
+ */
+ public GoalFinishedEvent getGoalEvent() {
+ return getGoalEvent(true, -1);
+ }
+
+ /**
+ * Returns a goal event from the queue. If the queue is empty, the behavior
+ * associated with this plan instance is going to be blocked if the
+ * parameter passed to this method is true.
+ *
+ * @param block
+ * true if the behavior must be blocked if the queue is empty.
+ * @return the goal event or null if the queue is empty.
+ */
+ public GoalFinishedEvent getGoalEvent(boolean block) {
+ return getGoalEvent(block, -1);
+ }
+
+ /**
+ * Returns a goal event from the queue. If the block parameter is true, the
+ * behavior associated with this plan instance is going to be blocked if the
+ * queue is empty according to the specified milliseconds. specified
+ * milliseconds. If the time is lower then zero, the behavior is going to be
+ * blocked until an event happens ({@link Behaviour#block()}).
+ *
+ * @param block
+ * true if the behavior must be blocked if the queue is empty.
+ * @param ms
+ * the maximum amount of time that the behavior must be blocked.
+ * @return the goal event or null if the queue is empty.
+ */
+ private GoalFinishedEvent getGoalEvent(boolean block, long ms) {
+ synchronized (goalEventQueue) {
+ if (!this.goalEventQueue.isEmpty()) {
+ return this.goalEventQueue.remove(0);
+ } else {
+ if (block) {
+ if (ms < 0) {
+ block();
+ } else {
+ block(ms);
+ }
+ }
+ return null;
+ }
+ }
+ }
+
+ /**
+ * Returns a goal event from the queue. If the queue is empty, the behavior
+ * associated with this plan instance is going to be blocked for the
+ * specified milliseconds.
+ *
+ * @param ms
+ * the maximum amount of time that the behavior must be blocked.
+ * @return the goal event or null if the queue is empty.
+ */
+ public GoalFinishedEvent getGoalEvent(long ms) {
+ return getGoalEvent(true, ms);
+ }
+
+ /**
+ * Returns the {@link Plan} that is associated with this plan instance.
+ *
+ * @return the plan.
+ */
+ public final Plan getPlan() {
+ return plan;
+ }
+
+ /**
+ * @see bdi4jade.event.GoalListener#goalPerformed(bdi4jade.event.GoalEvent)
+ */
+ @Override
+ public synchronized void goalPerformed(GoalEvent event) {
+ if (event instanceof GoalFinishedEvent) {
+ synchronized (goalEventQueue) {
+ this.goalEventQueue.add((GoalFinishedEvent) event);
+ restart();
+ }
+ synchronized (subgoals) {
+ this.subgoals.remove(event.getGoal());
+ }
+ }
+ }
+
+ /**
+ * Initializes this plan body. It associates this plan body with a plan
+ * definition ({@link Plan}) and an {@link Intention}. If this plan body has
+ * already been initialized, this method throws a
+ * {@link PlanInstantiationException}.
+ *
+ * @param plan
+ * the plan associated this this plan body.
+ * @param intention
+ * the intention that this plan instance have to achieve.
+ * @throws PlanBodyInstantiationException
+ * if this plan body has already been initialized.
+ */
+ public final void init(Plan plan, Intention intention)
+ throws PlanInstantiationException {
+ if (this.plan != null || this.intention != null) {
+ throw new PlanInstantiationException(
+ "This plan body has already been initialized.");
+ }
+ this.plan = plan;
+ this.intention = intention;
+ }
+
+ /**
+ * @param endState
+ * the endState to set
+ */
+ protected final void setEndState(EndState endState) {
+ synchronized (plan) {
+ this.endState = endState;
+ if (this.endState != null) {
+ if (this instanceof OutputPlanBody) {
+ ((OutputPlanBody) this).setGoalOutput(getGoal());
+ }
+ dropSubgoals();
+ }
+ }
+ }
+
+ /**
+ * Starts the plan body, a {@link Behaviour}, associated with this plan.
+ */
+ public final void start() {
+ this.intention.getMyAgent().addBehaviour(this);
+ }
+
+ /**
+ * Stops the plan body, a {@link Behaviour}, associated with this plan. If
+ * the body implements the {@link DisposablePlanBody}, it invokes the method
+ * to about the plan body, so it can perform finalizations.
+ */
+ public final void stop() {
+ dropSubgoals();
+ this.intention.getMyAgent().removeBehaviour(this);
+ if (this instanceof DisposablePlanBody) {
+ ((DisposablePlanBody) this).onAbort();
+ }
+ }
+
+}
bdi-jade/src/bdi4jade/plan/Plan.java 5(+2 -3)
diff --git a/bdi-jade/src/bdi4jade/plan/Plan.java b/bdi-jade/src/bdi4jade/plan/Plan.java
index 155ed94..88db798 100644
--- a/bdi-jade/src/bdi4jade/plan/Plan.java
+++ b/bdi-jade/src/bdi4jade/plan/Plan.java
@@ -23,11 +23,11 @@
package bdi4jade.plan;
import jade.lang.acl.ACLMessage;
+import bdi4jade.core.MetadataElement;
import bdi4jade.core.PlanLibrary;
import bdi4jade.exception.PlanInstantiationException;
import bdi4jade.goal.Goal;
import bdi4jade.message.MessageGoal;
-import bdi4jade.util.MetadataElement;
/**
* This interfaces represents the plan abstraction. It defines the goals that
@@ -77,8 +77,7 @@ public interface Plan extends MetadataElement {
* @throws PlanInstantiationException
* if an error occurred during the instantiation process.
*/
- public abstract PlanBodyInterface createPlanBody()
- throws PlanInstantiationException;
+ public abstract PlanBody createPlanBody() throws PlanInstantiationException;
/**
* @return the id
bdi-jade/src/bdi4jade/plan/PlanBody.java 248(+58 -190)
diff --git a/bdi-jade/src/bdi4jade/plan/PlanBody.java b/bdi-jade/src/bdi4jade/plan/PlanBody.java
index ae4ba5a..6d36b8c 100644
--- a/bdi-jade/src/bdi4jade/plan/PlanBody.java
+++ b/bdi-jade/src/bdi4jade/plan/PlanBody.java
@@ -23,45 +23,22 @@
package bdi4jade.plan;
import jade.core.behaviours.Behaviour;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
import bdi4jade.core.BeliefBase;
import bdi4jade.core.Intention;
-import bdi4jade.event.GoalEvent;
import bdi4jade.event.GoalFinishedEvent;
+import bdi4jade.event.GoalListener;
import bdi4jade.exception.PlanInstantiationException;
import bdi4jade.goal.Goal;
import bdi4jade.plan.Plan.EndState;
/**
- * This class represents a plan that has been instantiated to be executed.
+ * This interface defines a PlanBody. Plans are executed as behaviors (
+ * {@link Behaviour}), but executed in the BDI context, these behaviors should
+ * also implement this interface.
*
* @author ingrid
*/
-public abstract class PlanBody extends Behaviour implements PlanBodyInterface {
-
- private static final long serialVersionUID = -6488256636028800227L;
-
- private EndState endState;
- private final List<GoalFinishedEvent> goalEventQueue;
- private Intention intention;
- private Plan plan;
- private final List<Goal> subgoals;
-
- /**
- * Creates a new plan body instance.
- */
- public PlanBody() {
- this.plan = null;
- this.intention = null;
- this.endState = null;
- this.subgoals = new ArrayList<Goal>();
- this.goalEventQueue = new LinkedList<GoalFinishedEvent>();
- }
+public interface PlanBody extends GoalListener {
/**
* Dispatches a goal to be achieved.
@@ -69,9 +46,7 @@ public abstract class PlanBody extends Behaviour implements PlanBodyInterface {
* @param goal
* the goal to be dispatched.
*/
- public void dispatchGoal(Goal goal) {
- this.intention.getMyAgent().addGoal(goal);
- }
+ public void dispatchGoal(Goal goal);
/**
* Dispatches a goal to be achieved, using the capability (or its children
@@ -80,10 +55,7 @@ public abstract class PlanBody extends Behaviour implements PlanBodyInterface {
* @param goal
* the goal to be dispatched.
*/
- public void dispatchProtectedGoal(Goal goal) {
- this.intention.getMyAgent().addGoal(
- this.plan.getPlanLibrary().getCapability(), goal);
- }
+ public void dispatchProtectedGoal(Goal goal);
/**
* Dispatches a subgoal to be achieved, using the capability (or its
@@ -92,13 +64,7 @@ public abstract class PlanBody extends Behaviour implements PlanBodyInterface {
* @param subgoal
* the subgoal to be dispatched.
*/
- public void dispatchProtectedSubgoal(Goal subgoal) {
- this.intention.getMyAgent().addGoal(
- this.plan.getPlanLibrary().getCapability(), subgoal);
- synchronized (subgoals) {
- this.subgoals.add(subgoal);
- }
- }
+ public void dispatchProtectedSubgoal(Goal subgoal);
/**
* Dispatches a subgoal to be achieved, using the capability (or its
@@ -108,13 +74,7 @@ public abstract class PlanBody extends Behaviour implements PlanBodyInterface {
* @param subgoal
* the subgoal to be dispatched.
*/
- public void dispatchProtectedSubgoalAndListen(Goal subgoal) {
- this.intention.getMyAgent().addGoal(
- this.plan.getPlanLibrary().getCapability(), subgoal, this);
- synchronized (subgoals) {
- this.subgoals.add(subgoal);
- }
- }
+ public void dispatchProtectedSubgoalAndListen(Goal subgoal);
/**
* Dispatches a subgoal to be achieved.
@@ -122,12 +82,7 @@ public abstract class PlanBody extends Behaviour implements PlanBodyInterface {
* @param subgoal
* the subgoal to be dispatched.
*/
- public void dispatchSubgoal(Goal subgoal) {
- this.intention.getMyAgent().addGoal(subgoal);
- synchronized (subgoals) {
- this.subgoals.add(subgoal);
- }
- }
+ public void dispatchSubgoal(Goal subgoal);
/**
* Dispatches a subgoal to be achieved and registers itself as a listener to
@@ -136,68 +91,28 @@ public abstract class PlanBody extends Behaviour implements PlanBodyInterface {
* @param subgoal
* the subgoal to be dispatched.
*/
- public void dispatchSubgoalAndListen(Goal subgoal) {
- this.intention.getMyAgent().addGoal(subgoal, this);
- synchronized (subgoals) {
- this.subgoals.add(subgoal);
- }
- }
-
- @Override
- public final boolean done() {
- synchronized (plan) {
- return getEndState() != null;
- }
- }
-
- /**
- * Drops all current subgoals dispatched by this plan.
- */
- private void dropSubgoals() {
- synchronized (subgoals) {
- Iterator<Goal> it = subgoals.iterator();
- while (it.hasNext()) {
- Goal subgoal = it.next();
- this.intention.getMyAgent().setNoLongerDesired(subgoal);
- it.remove();
- }
- }
- }
+ public void dispatchSubgoalAndListen(Goal subgoal);
/**
* Returns the belief base of the capability.
*
* @return the belief base containing the beliefs.
*/
- public BeliefBase getBeliefBase() {
- return this.plan.getPlanLibrary().getCapability().getBeliefBase();
- }
+ public BeliefBase getBeliefBase();
/**
- * Returns the end state of plan. A null value means that the plan is still
- * in execution. If the plan body has come to an end state, it invokes the
- * method to set the output parameters of the goal, in case the plan body
- * implements the {@link OutputPlanBody} interface (this is invoked only
- * once). If the plan body has come to an end state, it sets all of its
- * subgoals as no longer desired, in case they are still trying to be
- * achieved.
+ * Returns the end state of the execution of this plan.
*
- * @return the end state of the plan.
+ * @return the end state of this plan, or null if it has not finished yet.
*/
- public EndState getEndState() {
- synchronized (plan) {
- return endState;
- }
- }
+ public EndState getEndState();
/**
* Returns the goal to be achieved by this plan instance.
*
* @return the goal.
*/
- public Goal getGoal() {
- return this.intention.getGoal();
- }
+ public Goal getGoal();
/**
* Returns a goal event from the queue. If the queue is empty, the behavior
@@ -205,9 +120,7 @@ public abstract class PlanBody extends Behaviour implements PlanBodyInterface {
*
* @return the goal event or null if the queue is empty.
*/
- public GoalFinishedEvent getGoalEvent() {
- return getGoalEvent(true, -1);
- }
+ public GoalFinishedEvent getGoalEvent();
/**
* Returns a goal event from the queue. If the queue is empty, the behavior
@@ -218,39 +131,7 @@ public abstract class PlanBody extends Behaviour implements PlanBodyInterface {
* true if the behavior must be blocked if the queue is empty.
* @return the goal event or null if the queue is empty.
*/
- public GoalFinishedEvent getGoalEvent(boolean block) {
- return getGoalEvent(block, -1);
- }
-
- /**
- * Returns a goal event from the queue. If the block parameter is true, the
- * behavior associated with this plan instance is going to be blocked if the
- * queue is empty according to the specified milliseconds. specified
- * milliseconds. If the time is lower then zero, the behavior is going to be
- * blocked until an event happens ({@link Behaviour#block()}).
- *
- * @param block
- * true if the behavior must be blocked if the queue is empty.
- * @param ms
- * the maximum amount of time that the behavior must be blocked.
- * @return the goal event or null if the queue is empty.
- */
- private GoalFinishedEvent getGoalEvent(boolean block, long ms) {
- synchronized (goalEventQueue) {
- if (!this.goalEventQueue.isEmpty()) {
- return this.goalEventQueue.remove(0);
- } else {
- if (block) {
- if (ms < 0) {
- block();
- } else {
- block(ms);
- }
- }
- return null;
- }
- }
- }
+ public GoalFinishedEvent getGoalEvent(boolean block);
/**
* Returns a goal event from the queue. If the queue is empty, the behavior
@@ -261,34 +142,14 @@ public abstract class PlanBody extends Behaviour implements PlanBodyInterface {
* the maximum amount of time that the behavior must be blocked.
* @return the goal event or null if the queue is empty.
*/
- public GoalFinishedEvent getGoalEvent(long ms) {
- return getGoalEvent(true, ms);
- }
+ public GoalFinishedEvent getGoalEvent(long ms);
/**
* Returns the {@link Plan} that is associated with this plan instance.
*
* @return the plan.
*/
- public Plan getPlan() {
- return plan;
- }
-
- /**
- * @see bdi4jade.event.GoalListener#goalPerformed(bdi4jade.event.GoalEvent)
- */
- @Override
- public synchronized void goalPerformed(GoalEvent event) {
- if (event instanceof GoalFinishedEvent) {
- synchronized (goalEventQueue) {
- this.goalEventQueue.add((GoalFinishedEvent) event);
- restart();
- }
- synchronized (subgoals) {
- this.subgoals.remove(event.getGoal());
- }
- }
- }
+ public Plan getPlan();
/**
* Initializes this plan body. It associates this plan body with a plan
@@ -304,49 +165,56 @@ public abstract class PlanBody extends Behaviour implements PlanBodyInterface {
* if this plan body has already been initialized.
*/
public void init(Plan plan, Intention intention)
- throws PlanInstantiationException {
- if (this.plan != null || this.intention != null) {
- throw new PlanInstantiationException(
- "This plan body has already been initialized.");
- }
- this.plan = plan;
- this.intention = intention;
- }
+ throws PlanInstantiationException;
+
+ /**
+ * This method is invoked just once after this behaviour has ended.
+ * Therefore, it acts as an epilog for the task represented by this plan
+ * body. Note that onEnd is called after the plan body has already stopped
+ * its execution.
+ *
+ * @see Behaviour#onEnd()
+ *
+ * @return an integer code representing the termination value of the
+ * behaviour.
+ */
+ public int onEnd();
/**
- * @param endState
- * the endState to set
+ * This method is executed just once before starting this plan body
+ * execution. Therefore, it acts as a prolog to the task represented by this
+ * plan body.
+ *
+ * @see Behaviour#onStart()
+ */
+ public void onStart();
+
+ /**
+ * Restores plan body initial state. This method must be implemented by
+ * concrete subclasses in such a way that calling reset() on a plan body
+ * object is equivalent to destroying it and recreating it back.
+ *
+ * @see Behaviour#reset()
+ */
+ public void reset();
+
+ /**
+ * Restarts a blocked plan body.
+ *
+ * @see Behaviour#restart()
*/
- protected void setEndState(EndState endState) {
- synchronized (plan) {
- this.endState = endState;
- if (this.endState != null) {
- if (this instanceof OutputPlanBody) {
- ((OutputPlanBody) this).setGoalOutput(getGoal());
- }
- dropSubgoals();
- }
- }
- }
+ public void restart();
/**
* Starts the plan body, a {@link Behaviour}, associated with this plan.
*/
- public void start() {
- this.intention.getMyAgent().addBehaviour(this);
- }
+ public void start();
/**
* Stops the plan body, a {@link Behaviour}, associated with this plan. If
* the body implements the {@link DisposablePlanBody}, it invokes the method
* to about the plan body, so it can perform finalizations.
*/
- public void stop() {
- dropSubgoals();
- this.intention.getMyAgent().removeBehaviour(this);
- if (this instanceof DisposablePlanBody) {
- ((DisposablePlanBody) this).onAbort();
- }
- }
+ public void stop();
}
bdi-jade/src/bdi4jade/plan/SimplePlan.java 95(+47 -48)
diff --git a/bdi-jade/src/bdi4jade/plan/SimplePlan.java b/bdi-jade/src/bdi4jade/plan/SimplePlan.java
index f9da785..8ead9e8 100644
--- a/bdi-jade/src/bdi4jade/plan/SimplePlan.java
+++ b/bdi-jade/src/bdi4jade/plan/SimplePlan.java
@@ -37,24 +37,24 @@ import bdi4jade.goal.Goal;
*/
public class SimplePlan extends AbstractPlan {
- protected final Class<? extends PlanBodyInterface> planBodyClass;
+ protected final Class<? extends PlanBody> planBodyClass;
/**
* Creates a new Simple Plan. It is a plan whose body is the specified class
* and its id is the plan body class name. The class must also implement the
- * {@link PlanBodyInterface} interface, otherwise an exception is going to
- * be thrown during the instantiation process. It sets that this plan can
- * achieve the specified goal class, but more goals can be specified by
- * overriding the initGoals() method.
+ * {@link PlanBody} interface, otherwise an exception is going to be thrown
+ * during the instantiation process. It sets that this plan can achieve the
+ * specified goal class, but more goals can be specified by overriding the
+ * initGoals() method.
*
* @param goalClass
* the goal that this plan can achieve.
* @param planBodyClass
* the class of the plan body. It must have the Behavior as super
- * class and implement the {@link PlanBodyInterface} interface.
+ * class and implement the {@link PlanBody} interface.
*/
public SimplePlan(Class<? extends Goal> goalClass,
- Class<? extends PlanBodyInterface> planBodyClass) {
+ Class<? extends PlanBody> planBodyClass) {
super(planBodyClass.getSimpleName(), goalClass);
this.planBodyClass = planBodyClass;
}
@@ -62,11 +62,11 @@ public class SimplePlan extends AbstractPlan {
/**
* Creates a new Simple Plan. It is a plan whose body is the specified class
* and its id is the plan body class name. The class must also implement the
- * {@link PlanBodyInterface} interface, otherwise an exception is going to
- * be thrown during the instantiation process. It sets that this plan can
- * achieve the specified goal class, but more goals can be specified by
- * overriding the initGoals() method. The message templates is initialized
- * with the provided template.
+ * {@link PlanBody} interface, otherwise an exception is going to be thrown
+ * during the instantiation process. It sets that this plan can achieve the
+ * specified goal class, but more goals can be specified by overriding the
+ * initGoals() method. The message templates is initialized with the
+ * provided template.
*
* @param goalClass
* the goal that this plan can achieve.
@@ -74,11 +74,11 @@ public class SimplePlan extends AbstractPlan {
* the template of messages that this plan can process.
* @param planBodyClass
* the class of the plan body. It must have the Behavior as super
- * class and implement the {@link PlanBodyInterface} interface.
+ * class and implement the {@link PlanBody} interface.
*/
public SimplePlan(Class<? extends Goal> goalClass,
MessageTemplate messageTemplate,
- Class<? extends PlanBodyInterface> planBodyClass) {
+ Class<? extends PlanBody> planBodyClass) {
super(planBodyClass.getSimpleName(), goalClass, messageTemplate);
this.planBodyClass = planBodyClass;
}
@@ -86,14 +86,14 @@ public class SimplePlan extends AbstractPlan {
/**
* Creates a new Simple Plan. It is a plan whose body is the specified class
* and its id is the plan body class name. The class must also implement the
- * {@link PlanBodyInterface} interface, otherwise an exception is going to
- * be thrown during the instantiation process.
+ * {@link PlanBody} interface, otherwise an exception is going to be thrown
+ * during the instantiation process.
*
* @param planBodyClass
* the class of the plan body. It must have the Behavior as super
- * class and implement the {@link PlanBodyInterface} interface.
+ * class and implement the {@link PlanBody} interface.
*/
- public SimplePlan(Class<? extends PlanBodyInterface> planBodyClass) {
+ public SimplePlan(Class<? extends PlanBody> planBodyClass) {
super(planBodyClass.getSimpleName());
this.planBodyClass = planBodyClass;
}
@@ -101,18 +101,18 @@ public class SimplePlan extends AbstractPlan {
/**
* Creates a new Simple Plan. It is a plan whose body is the specified class
* and its id is the plan body class name. The class must also implement the
- * {@link PlanBodyInterface} interface, otherwise an exception is going to
- * be thrown during the instantiation process. The message templates is
- * initialized with the provided template.
+ * {@link PlanBody} interface, otherwise an exception is going to be thrown
+ * during the instantiation process. The message templates is initialized
+ * with the provided template.
*
* @param messageTemplate
* the template of messages that this plan can process.
* @param planBodyClass
* the class of the plan body. It must have the Behavior as super
- * class and implement the {@link PlanBodyInterface} interface.
+ * class and implement the {@link PlanBody} interface.
*/
public SimplePlan(MessageTemplate messageTemplate,
- Class<? extends PlanBodyInterface> planBodyClass) {
+ Class<? extends PlanBody> planBodyClass) {
super(planBodyClass.getSimpleName(), messageTemplate);
this.planBodyClass = planBodyClass;
}
@@ -120,10 +120,10 @@ public class SimplePlan extends AbstractPlan {
/**
* Creates a new Simple Plan. It is a plan that has the provided id and
* whose body is the specified class. The class must also implement the
- * {@link PlanBodyInterface} interface, otherwise an exception is going to
- * be thrown during the instantiation process. It sets that this plan can
- * achieve the specified goal class, but more goals can be specified by
- * overriding the initGoals() method.
+ * {@link PlanBody} interface, otherwise an exception is going to be thrown
+ * during the instantiation process. It sets that this plan can achieve the
+ * specified goal class, but more goals can be specified by overriding the
+ * initGoals() method.
*
* @param id
* the id of this plan.
@@ -131,10 +131,10 @@ public class SimplePlan extends AbstractPlan {
* the goal that this plan can achieve.
* @param planBodyClass
* the class of the plan body. It must have the Behavior as super
- * class and implement the {@link PlanBodyInterface} interface.
+ * class and implement the {@link PlanBody} interface.
*/
public SimplePlan(String id, Class<? extends Goal> goalClass,
- Class<? extends PlanBodyInterface> planBodyClass) {
+ Class<? extends PlanBody> planBodyClass) {
super(id, goalClass);
this.planBodyClass = planBodyClass;
}
@@ -142,11 +142,11 @@ public class SimplePlan extends AbstractPlan {
/**
* Creates a new Simple Plan. It is a plan that has the provided id and
* whose body is the specified class. The class must also implement the
- * {@link PlanBodyInterface} interface, otherwise an exception is going to
- * be thrown during the instantiation process. It sets that this plan can
- * achieve the specified goal class, but more goals can be specified by
- * overriding the initGoals() method. The message templates is initialized
- * with the provided template.
+ * {@link PlanBody} interface, otherwise an exception is going to be thrown
+ * during the instantiation process. It sets that this plan can achieve the
+ * specified goal class, but more goals can be specified by overriding the
+ * initGoals() method. The message templates is initialized with the
+ * provided template.
*
* @param id
* the id of this plan.
@@ -156,11 +156,11 @@ public class SimplePlan extends AbstractPlan {
* the goal that this plan can achieve.
* @param planBodyClass
* the class of the plan body. It must have the Behavior as super
- * class and implement the {@link PlanBodyInterface} interface.
+ * class and implement the {@link PlanBody} interface.
*/
public SimplePlan(String id, Class<? extends Goal> goalClass,
MessageTemplate messageTemplate,
- Class<? extends PlanBodyInterface> planBodyClass) {
+ Class<? extends PlanBody> planBodyClass) {
super(id, goalClass, messageTemplate);
this.planBodyClass = planBodyClass;
}
@@ -168,17 +168,16 @@ public class SimplePlan extends AbstractPlan {
/**
* Creates a new Simple Plan. It is a plan that has the provided id and
* whose body is the specified class. The class must also implement the
- * {@link PlanBodyInterface} interface, otherwise an exception is going to
- * be thrown during the instantiation process.
+ * {@link PlanBody} interface, otherwise an exception is going to be thrown
+ * during the instantiation process.
*
* @param id
* the id of this plan.
* @param planBodyClass
* the class of the plan body. It must have the Behavior as super
- * class and implement the {@link PlanBodyInterface} interface.
+ * class and implement the {@link PlanBody} interface.
*/
- public SimplePlan(String id,
- Class<? extends PlanBodyInterface> planBodyClass) {
+ public SimplePlan(String id, Class<? extends PlanBody> planBodyClass) {
super(id);
this.planBodyClass = planBodyClass;
}
@@ -186,9 +185,9 @@ public class SimplePlan extends AbstractPlan {
/**
* Creates a new Simple Plan. It is a plan that has the provided id and
* whose body is the specified class. The class must also implement the
- * {@link PlanBodyInterface} interface, otherwise an exception is going to
- * be thrown during the instantiation process. The message templates is
- * initialized with the provided template.
+ * {@link PlanBody} interface, otherwise an exception is going to be thrown
+ * during the instantiation process. The message templates is initialized
+ * with the provided template.
*
* @param id
* the id of this plan.
@@ -196,10 +195,10 @@ public class SimplePlan extends AbstractPlan {
* the template of messages that this plan can process.
* @param planBodyClass
* the class of the plan body. It must have the Behavior as super
- * class and implement the {@link PlanBodyInterface} interface.
+ * class and implement the {@link PlanBody} interface.
*/
public SimplePlan(String id, MessageTemplate messageTemplate,
- Class<? extends PlanBodyInterface> planBodyClass) {
+ Class<? extends PlanBody> planBodyClass) {
super(id, messageTemplate);
this.planBodyClass = planBodyClass;
}
@@ -211,7 +210,7 @@ public class SimplePlan extends AbstractPlan {
* @see bdi4jade.plan.Plan#createPlanBody()
*/
@Override
- public PlanBodyInterface createPlanBody() throws PlanInstantiationException {
+ public PlanBody createPlanBody() throws PlanInstantiationException {
try {
return this.planBodyClass.newInstance();
} catch (Exception e) {
@@ -222,7 +221,7 @@ public class SimplePlan extends AbstractPlan {
/**
* @return the planBodyClass
*/
- public Class<? extends PlanBodyInterface> getPlanBodyClass() {
+ public Class<? extends PlanBody> getPlanBodyClass() {
return planBodyClass;
}
diff --git a/bdi-jade/src/bdi4jade/util/plan/ParallelGoalPlanBody.java b/bdi-jade/src/bdi4jade/util/plan/ParallelGoalPlanBody.java
index 3120b1a..4a3329a 100644
--- a/bdi-jade/src/bdi4jade/util/plan/ParallelGoalPlanBody.java
+++ b/bdi-jade/src/bdi4jade/util/plan/ParallelGoalPlanBody.java
@@ -31,16 +31,17 @@ import org.apache.commons.logging.LogFactory;
import bdi4jade.event.GoalFinishedEvent;
import bdi4jade.goal.Goal;
import bdi4jade.goal.GoalStatus;
+import bdi4jade.plan.AbstractPlanBody;
import bdi4jade.plan.OutputPlanBody;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
import bdi4jade.util.goal.ParallelGoal;
/**
* @author ingrid
*
*/
-public class ParallelGoalPlanBody extends PlanBody implements OutputPlanBody {
+public class ParallelGoalPlanBody extends AbstractPlanBody implements
+ OutputPlanBody {
private static final long serialVersionUID = -5919677537834351951L;
diff --git a/bdi-jade/src/bdi4jade/util/plan/SequentialGoalPlanBody.java b/bdi-jade/src/bdi4jade/util/plan/SequentialGoalPlanBody.java
index e2f1bda..61fb1f6 100644
--- a/bdi-jade/src/bdi4jade/util/plan/SequentialGoalPlanBody.java
+++ b/bdi-jade/src/bdi4jade/util/plan/SequentialGoalPlanBody.java
@@ -32,9 +32,9 @@ import org.apache.commons.logging.LogFactory;
import bdi4jade.event.GoalFinishedEvent;
import bdi4jade.goal.Goal;
import bdi4jade.goal.GoalStatus;
+import bdi4jade.plan.AbstractPlanBody;
import bdi4jade.plan.OutputPlanBody;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
import bdi4jade.util.goal.SequentialGoal;
/**
@@ -42,7 +42,8 @@ import bdi4jade.util.goal.SequentialGoal;
*
* @author ingrid
*/
-public class SequentialGoalPlanBody extends PlanBody implements OutputPlanBody {
+public class SequentialGoalPlanBody extends AbstractPlanBody implements
+ OutputPlanBody {
private static final long serialVersionUID = -5919677537834351951L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/AchieveOnPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/AchieveOnPlanBody.java
index 874c309..ddbd4c6 100644
--- a/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/AchieveOnPlanBody.java
+++ b/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/AchieveOnPlanBody.java
@@ -28,14 +28,14 @@ import bdi4jade.examples.blocksworld.domain.On;
import bdi4jade.examples.blocksworld.domain.Thing;
import bdi4jade.examples.blocksworld.goal.PerformMove;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
import bdi4jade.util.goal.BeliefSetValueGoal;
/**
* @author ingrid
*
*/
-public class AchieveOnPlanBody extends PlanBody {
+public class AchieveOnPlanBody extends AbstractPlanBody {
private static final long serialVersionUID = -5919677537834351951L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/ClearPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/ClearPlanBody.java
index 032391f..333a9e1 100644
--- a/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/ClearPlanBody.java
+++ b/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/ClearPlanBody.java
@@ -28,14 +28,14 @@ import bdi4jade.examples.blocksworld.domain.Clear;
import bdi4jade.examples.blocksworld.domain.On;
import bdi4jade.examples.blocksworld.domain.Thing;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
import bdi4jade.util.goal.BeliefSetValueGoal;
/**
* @author ingrid
*
*/
-public class ClearPlanBody extends PlanBody {
+public class ClearPlanBody extends AbstractPlanBody {
private static final long serialVersionUID = -5919677537834351951L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/PerformMovePlanBody.java b/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/PerformMovePlanBody.java
index 1bd5978..9bc2237 100644
--- a/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/PerformMovePlanBody.java
+++ b/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/PerformMovePlanBody.java
@@ -29,13 +29,13 @@ import bdi4jade.examples.blocksworld.domain.On;
import bdi4jade.examples.blocksworld.domain.Thing;
import bdi4jade.examples.blocksworld.goal.PerformMove;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
/**
* @author ingrid
*
*/
-public class PerformMovePlanBody extends PlanBody {
+public class PerformMovePlanBody extends AbstractPlanBody {
private static final long serialVersionUID = -5919677537834351951L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/TopLevelPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/TopLevelPlanBody.java
index d7bb4b9..15130f5 100644
--- a/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/TopLevelPlanBody.java
+++ b/bdi-jade-test/src/bdi4jade/examples/blocksworld/plan/TopLevelPlanBody.java
@@ -29,14 +29,14 @@ import bdi4jade.examples.blocksworld.BlocksWorldCapability;
import bdi4jade.examples.blocksworld.domain.On;
import bdi4jade.examples.blocksworld.goal.AchieveBlocksStacked;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
import bdi4jade.util.goal.BeliefSetValueGoal;
/**
* @author ingrid
*
*/
-public class TopLevelPlanBody extends PlanBody {
+public class TopLevelPlanBody extends AbstractPlanBody {
private static final long serialVersionUID = -5919677537834351951L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/compositegoal/MyPlan.java b/bdi-jade-test/src/bdi4jade/examples/compositegoal/MyPlan.java
index 8b3d970..f66d277 100644
--- a/bdi-jade-test/src/bdi4jade/examples/compositegoal/MyPlan.java
+++ b/bdi-jade-test/src/bdi4jade/examples/compositegoal/MyPlan.java
@@ -28,13 +28,13 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
/**
* @author ingrid
*
*/
-public class MyPlan extends PlanBody {
+public class MyPlan extends AbstractPlanBody {
private static final long serialVersionUID = -220345270457161508L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/helloworld/HelloWorldPlan.java b/bdi-jade-test/src/bdi4jade/examples/helloworld/HelloWorldPlan.java
index f469084..db0033b 100644
--- a/bdi-jade-test/src/bdi4jade/examples/helloworld/HelloWorldPlan.java
+++ b/bdi-jade-test/src/bdi4jade/examples/helloworld/HelloWorldPlan.java
@@ -23,13 +23,13 @@
package bdi4jade.examples.helloworld;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
/**
* @author ingridn
*
*/
-public class HelloWorldPlan extends PlanBody {
+public class HelloWorldPlan extends AbstractPlanBody {
private static final long serialVersionUID = -9039447524062487795L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/nestedcapabilities/NestedCapabilitiesAgent.java b/bdi-jade-test/src/bdi4jade/examples/nestedcapabilities/NestedCapabilitiesAgent.java
index 8975558..d801d9d 100644
--- a/bdi-jade-test/src/bdi4jade/examples/nestedcapabilities/NestedCapabilitiesAgent.java
+++ b/bdi-jade-test/src/bdi4jade/examples/nestedcapabilities/NestedCapabilitiesAgent.java
@@ -26,7 +26,7 @@ import bdi4jade.belief.TransientBelief;
import bdi4jade.core.BDIAgent;
import bdi4jade.core.Capability;
import bdi4jade.goal.Goal;
-import bdi4jade.plan.PlanBodyInterface;
+import bdi4jade.plan.PlanBody;
import bdi4jade.plan.SimplePlan;
class ChildGoal implements Goal {
@@ -53,7 +53,7 @@ public class NestedCapabilitiesAgent extends BDIAgent {
}
private void addPlan(Capability capability, Class<? extends Goal> goal,
- Class<? extends PlanBodyInterface> planBody) {
+ Class<? extends PlanBody> planBody) {
capability.getPlanLibrary().addPlan(new SimplePlan(goal, planBody));
}
diff --git a/bdi-jade-test/src/bdi4jade/examples/nestedcapabilities/SuccessPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/nestedcapabilities/SuccessPlanBody.java
index 421b7c3..513667e 100644
--- a/bdi-jade-test/src/bdi4jade/examples/nestedcapabilities/SuccessPlanBody.java
+++ b/bdi-jade-test/src/bdi4jade/examples/nestedcapabilities/SuccessPlanBody.java
@@ -26,9 +26,9 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
-public class SuccessPlanBody extends PlanBody {
+public class SuccessPlanBody extends AbstractPlanBody {
private static final long serialVersionUID = -9039447524062487795L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/nestedcapabilities/TestPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/nestedcapabilities/TestPlanBody.java
index 37d1103..3f690cf 100644
--- a/bdi-jade-test/src/bdi4jade/examples/nestedcapabilities/TestPlanBody.java
+++ b/bdi-jade-test/src/bdi4jade/examples/nestedcapabilities/TestPlanBody.java
@@ -29,9 +29,9 @@ import bdi4jade.event.GoalFinishedEvent;
import bdi4jade.examples.nestedcapabilities.NestedCapabilitiesAgent.Belief;
import bdi4jade.goal.GoalStatus;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
-public class TestPlanBody extends PlanBody {
+public class TestPlanBody extends AbstractPlanBody {
enum TestStep {
BELIEF, CHILD_GOAL, COMPLETED, MY_GOAL, PARENT_GOAL, PARENT_PROTECTED_GOAL, SIBLING_GOAL, SIBLING_PROTECTED_GOAL;
diff --git a/bdi-jade-test/src/bdi4jade/examples/ping/PingPlan.java b/bdi-jade-test/src/bdi4jade/examples/ping/PingPlan.java
index 95173dd..c5c663a 100644
--- a/bdi-jade-test/src/bdi4jade/examples/ping/PingPlan.java
+++ b/bdi-jade-test/src/bdi4jade/examples/ping/PingPlan.java
@@ -30,13 +30,13 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
/**
* @author ingrid
*
*/
-public class PingPlan extends PlanBody {
+public class PingPlan extends AbstractPlanBody {
private static final long serialVersionUID = -6288758975856575305L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/ping/PongPlan.java b/bdi-jade-test/src/bdi4jade/examples/ping/PongPlan.java
index ecfc020..ed2b343 100644
--- a/bdi-jade-test/src/bdi4jade/examples/ping/PongPlan.java
+++ b/bdi-jade-test/src/bdi4jade/examples/ping/PongPlan.java
@@ -29,13 +29,13 @@ import org.apache.commons.logging.LogFactory;
import bdi4jade.message.MessageGoal;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
/**
* @author ingrid
*
*/
-public class PongPlan extends PlanBody {
+public class PongPlan extends AbstractPlanBody {
private static final long serialVersionUID = -3352874506241004611L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/planfailed/MyPlan.java b/bdi-jade-test/src/bdi4jade/examples/planfailed/MyPlan.java
index 91814e0..6faf431 100644
--- a/bdi-jade-test/src/bdi4jade/examples/planfailed/MyPlan.java
+++ b/bdi-jade-test/src/bdi4jade/examples/planfailed/MyPlan.java
@@ -28,13 +28,13 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
/**
* @author ingrid
*
*/
-public class MyPlan extends PlanBody {
+public class MyPlan extends AbstractPlanBody {
private static final long serialVersionUID = -220345270457161508L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/planselection/Softgoals.java b/bdi-jade-test/src/bdi4jade/examples/planselection/Softgoals.java
index 5843d67..0809000 100644
--- a/bdi-jade-test/src/bdi4jade/examples/planselection/Softgoals.java
+++ b/bdi-jade-test/src/bdi4jade/examples/planselection/Softgoals.java
@@ -22,8 +22,8 @@
package bdi4jade.examples.planselection;
-import bdi4jade.extension.softgoal.core.NamedSoftgoal;
-import bdi4jade.extension.softgoal.core.Softgoal;
+import bdi4jade.goal.NamedSoftgoal;
+import bdi4jade.goal.Softgoal;
/**
* @author ingrid
diff --git a/bdi-jade-test/src/bdi4jade/examples/planselection/TransportationAgent.java b/bdi-jade-test/src/bdi4jade/examples/planselection/TransportationAgent.java
index 3015927..af47bff 100644
--- a/bdi-jade-test/src/bdi4jade/examples/planselection/TransportationAgent.java
+++ b/bdi-jade-test/src/bdi4jade/examples/planselection/TransportationAgent.java
@@ -28,16 +28,16 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import bdi4jade.belief.TransientBelief;
-import bdi4jade.extension.softgoal.core.SoftGoalBDIAgent;
-import bdi4jade.extension.softgoal.core.Softgoal;
-import bdi4jade.extension.softgoal.core.SoftgoalPreferences;
+import bdi4jade.extension.planselection.utilitybased.UtilityBasedBDIAgent;
+import bdi4jade.extension.planselection.utilitybased.SoftgoalPreferences;
+import bdi4jade.goal.Softgoal;
import bdi4jade.plan.Plan;
/**
* @author ingrid
*
*/
-public class TransportationAgent extends SoftGoalBDIAgent {
+public class TransportationAgent extends UtilityBasedBDIAgent {
static final long serialVersionUID = 2712019445290687786L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/planselection/TransportationPlan.java b/bdi-jade-test/src/bdi4jade/examples/planselection/TransportationPlan.java
index 0460527..231b6e4 100644
--- a/bdi-jade-test/src/bdi4jade/examples/planselection/TransportationPlan.java
+++ b/bdi-jade-test/src/bdi4jade/examples/planselection/TransportationPlan.java
@@ -23,12 +23,12 @@
package bdi4jade.examples.planselection;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import bdi4jade.extension.softgoal.core.Softgoal;
-import bdi4jade.extension.softgoal.plan.AnnotatedPlan.DefaultMetadata;
-import bdi4jade.extension.softgoal.plan.PlanContribution;
+import bdi4jade.extension.planselection.utilitybased.PlanContribution;
+import bdi4jade.goal.Softgoal;
import bdi4jade.plan.SimplePlan;
/**
@@ -60,7 +60,7 @@ public class TransportationPlan extends SimplePlan {
this.maxTime = maxTime;
this.minTime = minTime;
- Map<Softgoal, List<PlanContribution>> contributions = (Map<Softgoal, List<PlanContribution>>) getMetadata(DefaultMetadata.CONTRIBUTIONS);
+ Map<Softgoal, List<PlanContribution>> contributions = new HashMap<Softgoal, List<PlanContribution>>();
List<PlanContribution> sgContributions = new ArrayList<PlanContribution>();
sgContributions.add(new PlanContribution(Softgoals.SAFETY,
@@ -101,6 +101,8 @@ public class TransportationPlan extends SimplePlan {
sgContributions.add(new PlanContribution(Softgoals.PERFORMANCE,
(1 - crashProbability) * 0.5, 1 - (maxTime / MAX_TIME_TAKEN)));
contributions.put(Softgoals.PERFORMANCE, sgContributions);
+
+ putMetadata(PlanContribution.METADATA_NAME, contributions);
}
/**
diff --git a/bdi-jade-test/src/bdi4jade/examples/planselection/TransportationPlanBody.java b/bdi-jade-test/src/bdi4jade/examples/planselection/TransportationPlanBody.java
index 069fc22..bf3e18a 100644
--- a/bdi-jade-test/src/bdi4jade/examples/planselection/TransportationPlanBody.java
+++ b/bdi-jade-test/src/bdi4jade/examples/planselection/TransportationPlanBody.java
@@ -28,15 +28,15 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import bdi4jade.belief.TransientBelief;
-import bdi4jade.extension.softgoal.core.SoftgoalPreferences;
+import bdi4jade.extension.planselection.utilitybased.SoftgoalPreferences;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
/**
* @author ingrid
*
*/
-public class TransportationPlanBody extends PlanBody {
+public class TransportationPlanBody extends AbstractPlanBody {
class Scenario {
diff --git a/bdi-jade-test/src/bdi4jade/examples/subgoal/ChildPlan.java b/bdi-jade-test/src/bdi4jade/examples/subgoal/ChildPlan.java
index e159e97..e310fe3 100644
--- a/bdi-jade-test/src/bdi4jade/examples/subgoal/ChildPlan.java
+++ b/bdi-jade-test/src/bdi4jade/examples/subgoal/ChildPlan.java
@@ -26,13 +26,13 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import bdi4jade.plan.DisposablePlanBody;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
/**
* @author ingrid
*
*/
-public class ChildPlan extends PlanBody implements DisposablePlanBody {
+public class ChildPlan extends AbstractPlanBody implements DisposablePlanBody {
private static final long serialVersionUID = -5432560989511973914L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/subgoal/MyPlan.java b/bdi-jade-test/src/bdi4jade/examples/subgoal/MyPlan.java
index 7da6fd8..99d21e0 100644
--- a/bdi-jade-test/src/bdi4jade/examples/subgoal/MyPlan.java
+++ b/bdi-jade-test/src/bdi4jade/examples/subgoal/MyPlan.java
@@ -26,13 +26,13 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
/**
* @author ingrid
*
*/
-public class MyPlan extends PlanBody {
+public class MyPlan extends AbstractPlanBody {
private static final long serialVersionUID = -5432560989511973914L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/subgoal/ParentPlan.java b/bdi-jade-test/src/bdi4jade/examples/subgoal/ParentPlan.java
index 63f792b..63e21f2 100644
--- a/bdi-jade-test/src/bdi4jade/examples/subgoal/ParentPlan.java
+++ b/bdi-jade-test/src/bdi4jade/examples/subgoal/ParentPlan.java
@@ -26,13 +26,13 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
/**
* @author ingrid
*
*/
-public class ParentPlan extends PlanBody {
+public class ParentPlan extends AbstractPlanBody {
private static final long serialVersionUID = -5432560989511973914L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/template/MyAgent.java b/bdi-jade-test/src/bdi4jade/examples/template/MyAgent.java
index caadeca..1f85724 100644
--- a/bdi-jade-test/src/bdi4jade/examples/template/MyAgent.java
+++ b/bdi-jade-test/src/bdi4jade/examples/template/MyAgent.java
@@ -25,15 +25,15 @@ package bdi4jade.examples.template;
import bdi4jade.examples.template.goal.MyGoal;
import bdi4jade.examples.template.plan.MyPlan1;
import bdi4jade.examples.template.plan.MyPlan2;
-import bdi4jade.extension.softgoal.core.SoftGoalBDIAgent;
-import bdi4jade.extension.softgoal.core.Softgoal;
-import bdi4jade.extension.softgoal.core.SoftgoalPreferences;
+import bdi4jade.extension.planselection.utilitybased.UtilityBasedBDIAgent;
+import bdi4jade.extension.planselection.utilitybased.SoftgoalPreferences;
+import bdi4jade.goal.Softgoal;
/**
* @author ingrid
*
*/
-public class MyAgent extends SoftGoalBDIAgent {
+public class MyAgent extends UtilityBasedBDIAgent {
static final long serialVersionUID = 2712019445290687786L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/template/MyAgentSoftgoals.java b/bdi-jade-test/src/bdi4jade/examples/template/MyAgentSoftgoals.java
index 481d64d..c434e33 100644
--- a/bdi-jade-test/src/bdi4jade/examples/template/MyAgentSoftgoals.java
+++ b/bdi-jade-test/src/bdi4jade/examples/template/MyAgentSoftgoals.java
@@ -22,8 +22,8 @@
package bdi4jade.examples.template;
-import bdi4jade.extension.softgoal.core.NamedSoftgoal;
-import bdi4jade.extension.softgoal.core.Softgoal;
+import bdi4jade.goal.NamedSoftgoal;
+import bdi4jade.goal.Softgoal;
/**
* @author ingrid
diff --git a/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan1.java b/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan1.java
index a7dc650..df77724 100644
--- a/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan1.java
+++ b/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan1.java
@@ -23,14 +23,14 @@
package bdi4jade.examples.template.plan;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import bdi4jade.examples.template.MyAgentSoftgoals;
import bdi4jade.examples.template.goal.MyGoal;
-import bdi4jade.extension.softgoal.core.Softgoal;
-import bdi4jade.extension.softgoal.plan.AnnotatedPlan.DefaultMetadata;
-import bdi4jade.extension.softgoal.plan.PlanContribution;
+import bdi4jade.extension.planselection.utilitybased.PlanContribution;
+import bdi4jade.goal.Softgoal;
import bdi4jade.plan.SimplePlan;
/**
@@ -42,7 +42,7 @@ public class MyPlan1 extends SimplePlan {
public MyPlan1() {
super(MyGoal.class, MyPlan1Body.class);
- Map<Softgoal, List<PlanContribution>> contributions = (Map<Softgoal, List<PlanContribution>>) getMetadata(DefaultMetadata.CONTRIBUTIONS);
+ Map<Softgoal, List<PlanContribution>> contributions = new HashMap<Softgoal, List<PlanContribution>>();
List<PlanContribution> sgContributions = null;
sgContributions = new ArrayList<PlanContribution>();
@@ -58,6 +58,8 @@ public class MyPlan1 extends SimplePlan {
sgContributions.add(new PlanContribution(MyAgentSoftgoals.Softgoal2,
0.8, 1.0));
contributions.put(MyAgentSoftgoals.Softgoal2, sgContributions);
+
+ putMetadata(PlanContribution.METADATA_NAME, contributions);
}
}
\ No newline at end of file
diff --git a/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan1Body.java b/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan1Body.java
index ccb887c..a5721aa 100644
--- a/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan1Body.java
+++ b/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan1Body.java
@@ -23,13 +23,13 @@
package bdi4jade.examples.template.plan;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
/**
* @author ingrid
*
*/
-public class MyPlan1Body extends PlanBody {
+public class MyPlan1Body extends AbstractPlanBody {
private static final long serialVersionUID = -3947024373151941681L;
diff --git a/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan2.java b/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan2.java
index 2583274..ae9f7d4 100644
--- a/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan2.java
+++ b/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan2.java
@@ -23,14 +23,14 @@
package bdi4jade.examples.template.plan;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import bdi4jade.examples.template.MyAgentSoftgoals;
import bdi4jade.examples.template.goal.MyGoal;
-import bdi4jade.extension.softgoal.core.Softgoal;
-import bdi4jade.extension.softgoal.plan.AnnotatedPlan.DefaultMetadata;
-import bdi4jade.extension.softgoal.plan.PlanContribution;
+import bdi4jade.extension.planselection.utilitybased.PlanContribution;
+import bdi4jade.goal.Softgoal;
import bdi4jade.plan.SimplePlan;
/**
@@ -42,7 +42,7 @@ public class MyPlan2 extends SimplePlan {
public MyPlan2() {
super(MyGoal.class, MyPlan2Body.class);
- Map<Softgoal, List<PlanContribution>> contributions = (Map<Softgoal, List<PlanContribution>>) getMetadata(DefaultMetadata.CONTRIBUTIONS);
+ Map<Softgoal, List<PlanContribution>> contributions = new HashMap<Softgoal, List<PlanContribution>>();
List<PlanContribution> sgContributions = null;
sgContributions = new ArrayList<PlanContribution>();
@@ -58,6 +58,8 @@ public class MyPlan2 extends SimplePlan {
sgContributions.add(new PlanContribution(MyAgentSoftgoals.Softgoal2,
0.5, 1.0));
contributions.put(MyAgentSoftgoals.Softgoal2, sgContributions);
+
+ putMetadata(PlanContribution.METADATA_NAME, contributions);
}
}
\ No newline at end of file
diff --git a/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan2Body.java b/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan2Body.java
index 8041ea0..a0891df 100644
--- a/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan2Body.java
+++ b/bdi-jade-test/src/bdi4jade/examples/template/plan/MyPlan2Body.java
@@ -23,13 +23,13 @@
package bdi4jade.examples.template.plan;
import bdi4jade.plan.Plan.EndState;
-import bdi4jade.plan.PlanBody;
+import bdi4jade.plan.AbstractPlanBody;
/**
* @author ingrid
*
*/
-public class MyPlan2Body extends PlanBody {
+public class MyPlan2Body extends AbstractPlanBody {
private static final long serialVersionUID = -3947024373151941681L;