bdi4jade

Setting output in belief goals

9/14/2014 1:19:46 AM

Details

diff --git a/bdi-jade/src/bdi4jade/goal/BeliefGoal.java b/bdi-jade/src/bdi4jade/goal/BeliefGoal.java
index 0446cb0..64fdfdc 100644
--- a/bdi-jade/src/bdi4jade/goal/BeliefGoal.java
+++ b/bdi-jade/src/bdi4jade/goal/BeliefGoal.java
@@ -22,6 +22,7 @@
 
 package bdi4jade.goal;
 
+import bdi4jade.belief.Belief;
 import bdi4jade.belief.BeliefBase;
 
 /**
@@ -40,6 +41,13 @@ public interface BeliefGoal<K> extends Goal {
 	public K getBeliefName();
 
 	/**
+	 * Returns the belief which is the output of this goal achievement.
+	 * 
+	 * @return the belief.
+	 */
+	public Belief<K, ?> getOutputBelief();
+
+	/**
 	 * Checks whether this goal is achieved by checking the provided belief
 	 * base.
 	 * 
@@ -49,4 +57,11 @@ public interface BeliefGoal<K> extends Goal {
 	 */
 	public boolean isAchieved(BeliefBase beliefBase);
 
+	/**
+	 * Sets the belief which is the output of this goal achievement.
+	 * 
+	 * @return the belief.
+	 */
+	public void setOutputBelief(Belief<K, ?> belief);
+
 }
diff --git a/bdi-jade/src/bdi4jade/goal/BeliefNotNullValueGoal.java b/bdi-jade/src/bdi4jade/goal/BeliefNotNullValueGoal.java
index 7957eb1..0f81b9a 100644
--- a/bdi-jade/src/bdi4jade/goal/BeliefNotNullValueGoal.java
+++ b/bdi-jade/src/bdi4jade/goal/BeliefNotNullValueGoal.java
@@ -22,8 +22,6 @@
 
 package bdi4jade.goal;
 
-import bdi4jade.annotation.Parameter;
-import bdi4jade.annotation.Parameter.Direction;
 import bdi4jade.belief.Belief;
 import bdi4jade.belief.BeliefBase;
 
@@ -39,12 +37,10 @@ import bdi4jade.belief.BeliefBase;
  * 
  * @author Ingrid Nunes
  */
-public class BeliefNotNullValueGoal<K, V> implements BeliefGoal<K> {
+public class BeliefNotNullValueGoal<K, V> extends AbstractBeliefGoal<K> {
 
 	private static final long serialVersionUID = 2493877854717226283L;
 
-	private K beliefName;
-
 	/**
 	 * Default constructor.
 	 */
@@ -53,13 +49,13 @@ public class BeliefNotNullValueGoal<K, V> implements BeliefGoal<K> {
 	}
 
 	/**
-	 * Creates a new BeliefValueGoal with the provided belief.
+	 * Creates a new BeliefNotNullValueGoal with the provided belief.
 	 * 
 	 * @param beliefName
 	 *            the belief name.
 	 */
 	public BeliefNotNullValueGoal(K beliefName) {
-		this.beliefName = beliefName;
+		super(beliefName);
 	}
 
 	/**
@@ -69,22 +65,12 @@ public class BeliefNotNullValueGoal<K, V> implements BeliefGoal<K> {
 	public boolean equals(Object obj) {
 		if (obj instanceof BeliefNotNullValueGoal) {
 			BeliefNotNullValueGoal<?, ?> bg = (BeliefNotNullValueGoal<?, ?>) obj;
-			return (!beliefName.equals(bg.beliefName));
+			return beliefName.equals(bg.beliefName);
 		}
 		return false;
 	}
 
 	/**
-	 * Returns the name of the belief associated with this goal.
-	 * 
-	 * @return the belief name.
-	 */
-	@Parameter(direction = Direction.IN)
-	public K getBeliefName() {
-		return beliefName;
-	}
-
-	/**
 	 * @see java.lang.Object#hashCode()
 	 */
 	@Override
@@ -115,16 +101,6 @@ public class BeliefNotNullValueGoal<K, V> implements BeliefGoal<K> {
 	}
 
 	/**
-	 * Sets the name of the belief associated with this goal.
-	 * 
-	 * @param beliefName
-	 *            the belief name.
-	 */
-	public void setBeliefName(K beliefName) {
-		this.beliefName = beliefName;
-	}
-
-	/**
 	 * Returns a string representation of this goal, in the form
 	 * "BeliefValueGoal: BELIEF NAME should be BELIEF VALUE".
 	 * 
diff --git a/bdi-jade/src/bdi4jade/goal/BeliefNotPresentGoal.java b/bdi-jade/src/bdi4jade/goal/BeliefNotPresentGoal.java
index 43295a7..d3ae503 100644
--- a/bdi-jade/src/bdi4jade/goal/BeliefNotPresentGoal.java
+++ b/bdi-jade/src/bdi4jade/goal/BeliefNotPresentGoal.java
@@ -22,8 +22,6 @@
 
 package bdi4jade.goal;
 
-import bdi4jade.annotation.Parameter;
-import bdi4jade.annotation.Parameter.Direction;
 import bdi4jade.belief.BeliefBase;
 
 /**
@@ -33,12 +31,10 @@ import bdi4jade.belief.BeliefBase;
  * 
  * @author Ingrid Nunes
  */
-public class BeliefNotPresentGoal<K> implements BeliefGoal<K> {
+public class BeliefNotPresentGoal<K> extends AbstractBeliefGoal<K> {
 
 	private static final long serialVersionUID = 2493877854717226283L;
 
-	private K beliefName;
-
 	/**
 	 * Default constructor.
 	 */
@@ -47,13 +43,13 @@ public class BeliefNotPresentGoal<K> implements BeliefGoal<K> {
 	}
 
 	/**
-	 * Creates a new BeliefGoal with the provided belief name.
+	 * Creates a new BeliefNotPresentGoal with the provided belief name.
 	 * 
 	 * @param beliefName
 	 *            the belief name.
 	 */
 	public BeliefNotPresentGoal(K beliefName) {
-		this.beliefName = beliefName;
+		super(beliefName);
 	}
 
 	/**
@@ -69,16 +65,6 @@ public class BeliefNotPresentGoal<K> implements BeliefGoal<K> {
 	}
 
 	/**
-	 * Returns the name of the belief associated with this goal.
-	 * 
-	 * @return the belief name.
-	 */
-	@Parameter(direction = Direction.IN)
-	public K getBeliefName() {
-		return beliefName;
-	}
-
-	/**
 	 * @see java.lang.Object#hashCode()
 	 */
 	@Override
@@ -103,16 +89,6 @@ public class BeliefNotPresentGoal<K> implements BeliefGoal<K> {
 	}
 
 	/**
-	 * Sets the name of the belief associated with this goal.
-	 * 
-	 * @param beliefName
-	 *            the belief name.
-	 */
-	public void setBeliefName(K beliefName) {
-		this.beliefName = beliefName;
-	}
-
-	/**
 	 * Returns a string representation of this goal, in the form
 	 * "BeliefGoal: belief name".
 	 * 
diff --git a/bdi-jade/src/bdi4jade/goal/BeliefPresentGoal.java b/bdi-jade/src/bdi4jade/goal/BeliefPresentGoal.java
index e5c9eb6..4140ed3 100644
--- a/bdi-jade/src/bdi4jade/goal/BeliefPresentGoal.java
+++ b/bdi-jade/src/bdi4jade/goal/BeliefPresentGoal.java
@@ -22,8 +22,6 @@
 
 package bdi4jade.goal;
 
-import bdi4jade.annotation.Parameter;
-import bdi4jade.annotation.Parameter.Direction;
 import bdi4jade.belief.BeliefBase;
 
 /**
@@ -32,12 +30,10 @@ import bdi4jade.belief.BeliefBase;
  * 
  * @author Ingrid Nunes
  */
-public class BeliefPresentGoal<K> implements BeliefGoal<K> {
+public class BeliefPresentGoal<K> extends AbstractBeliefGoal<K> {
 
 	private static final long serialVersionUID = 2493877854717226283L;
 
-	private K beliefName;
-
 	/**
 	 * Default constructor.
 	 */
@@ -46,13 +42,13 @@ public class BeliefPresentGoal<K> implements BeliefGoal<K> {
 	}
 
 	/**
-	 * Creates a new BeliefGoal with the provided belief name.
+	 * Creates a new BeliefPresentGoal with the provided belief name.
 	 * 
 	 * @param beliefName
 	 *            the belief name.
 	 */
 	public BeliefPresentGoal(K beliefName) {
-		this.beliefName = beliefName;
+		super(beliefName);
 	}
 
 	/**
@@ -68,16 +64,6 @@ public class BeliefPresentGoal<K> implements BeliefGoal<K> {
 	}
 
 	/**
-	 * Returns the name of the belief associated with this goal.
-	 * 
-	 * @return the belief name.
-	 */
-	@Parameter(direction = Direction.IN)
-	public K getBeliefName() {
-		return beliefName;
-	}
-
-	/**
 	 * @see java.lang.Object#hashCode()
 	 */
 	@Override
@@ -102,16 +88,6 @@ public class BeliefPresentGoal<K> implements BeliefGoal<K> {
 	}
 
 	/**
-	 * Sets the name of the belief associated with this goal.
-	 * 
-	 * @param beliefName
-	 *            the belief name.
-	 */
-	public void setBeliefName(K beliefName) {
-		this.beliefName = beliefName;
-	}
-
-	/**
 	 * Returns a string representation of this goal, in the form
 	 * "BeliefGoal: belief name".
 	 * 
diff --git a/bdi-jade/src/bdi4jade/goal/BeliefSetHasValueGoal.java b/bdi-jade/src/bdi4jade/goal/BeliefSetHasValueGoal.java
index b533372..51f7dbf 100644
--- a/bdi-jade/src/bdi4jade/goal/BeliefSetHasValueGoal.java
+++ b/bdi-jade/src/bdi4jade/goal/BeliefSetHasValueGoal.java
@@ -39,11 +39,10 @@ import bdi4jade.belief.BeliefSet;
  * 
  * @author Ingrid Nunes
  */
-public class BeliefSetHasValueGoal<K, V> implements BeliefGoal<K> {
+public class BeliefSetHasValueGoal<K, V> extends AbstractBeliefGoal<K> {
 
 	private static final long serialVersionUID = 2493877854717226283L;
 
-	private K beliefName;
 	private V value;
 
 	/**
@@ -64,7 +63,7 @@ public class BeliefSetHasValueGoal<K, V> implements BeliefGoal<K> {
 	 *            the value that is target of this goal.
 	 */
 	public BeliefSetHasValueGoal(K beliefSetName, V value) {
-		this.beliefName = beliefSetName;
+		super(beliefSetName);
 		this.value = value;
 	}
 
@@ -89,16 +88,6 @@ public class BeliefSetHasValueGoal<K, V> implements BeliefGoal<K> {
 	}
 
 	/**
-	 * Returns the name of the belief associated with this goal.
-	 * 
-	 * @return the belief name.
-	 */
-	@Parameter(direction = Direction.IN)
-	public K getBeliefName() {
-		return beliefName;
-	}
-
-	/**
 	 * The belief value associated with this goal.
 	 * 
 	 * @return the belief value.
@@ -142,16 +131,6 @@ public class BeliefSetHasValueGoal<K, V> implements BeliefGoal<K> {
 	}
 
 	/**
-	 * Sets the name of the belief associated with this goal.
-	 * 
-	 * @param beliefName
-	 *            the belief name.
-	 */
-	public void setBeliefName(K beliefName) {
-		this.beliefName = beliefName;
-	}
-
-	/**
 	 * Sets the value of this goal.
 	 * 
 	 * @param value
diff --git a/bdi-jade/src/bdi4jade/goal/BeliefValueGoal.java b/bdi-jade/src/bdi4jade/goal/BeliefValueGoal.java
index 832b33e..a422cd4 100644
--- a/bdi-jade/src/bdi4jade/goal/BeliefValueGoal.java
+++ b/bdi-jade/src/bdi4jade/goal/BeliefValueGoal.java
@@ -39,11 +39,10 @@ import bdi4jade.belief.BeliefBase;
  * 
  * @author Ingrid Nunes
  */
-public class BeliefValueGoal<K, V> implements BeliefGoal<K> {
+public class BeliefValueGoal<K, V> extends AbstractBeliefGoal<K> {
 
 	private static final long serialVersionUID = 2493877854717226283L;
 
-	private K beliefName;
 	private V value;
 
 	/**
@@ -75,7 +74,7 @@ public class BeliefValueGoal<K, V> implements BeliefGoal<K> {
 	 *            the value that is target of this goal.
 	 */
 	public BeliefValueGoal(K beliefName, V value) {
-		this.beliefName = beliefName;
+		super(beliefName);
 		this.value = value;
 	}
 
@@ -100,16 +99,6 @@ public class BeliefValueGoal<K, V> implements BeliefGoal<K> {
 	}
 
 	/**
-	 * Returns the name of the belief associated with this goal.
-	 * 
-	 * @return the belief name.
-	 */
-	@Parameter(direction = Direction.IN)
-	public K getBeliefName() {
-		return beliefName;
-	}
-
-	/**
 	 * The belief value associated with this goal.
 	 * 
 	 * @return the belief value.
@@ -157,16 +146,6 @@ public class BeliefValueGoal<K, V> implements BeliefGoal<K> {
 	}
 
 	/**
-	 * Sets the name of the belief associated with this goal.
-	 * 
-	 * @param beliefName
-	 *            the belief name.
-	 */
-	public void setBeliefName(K beliefName) {
-		this.beliefName = beliefName;
-	}
-
-	/**
 	 * Sets the value of this goal.
 	 * 
 	 * @param value
diff --git a/bdi-jade/src/bdi4jade/plan/planbody/BeliefGoalPlanBody.java b/bdi-jade/src/bdi4jade/plan/planbody/BeliefGoalPlanBody.java
index 869e259..cf12315 100644
--- a/bdi-jade/src/bdi4jade/plan/planbody/BeliefGoalPlanBody.java
+++ b/bdi-jade/src/bdi4jade/plan/planbody/BeliefGoalPlanBody.java
@@ -22,6 +22,9 @@
 
 package bdi4jade.plan.planbody;
 
+import bdi4jade.annotation.Parameter;
+import bdi4jade.annotation.Parameter.Direction;
+import bdi4jade.belief.Belief;
 import bdi4jade.goal.BeliefGoal;
 import bdi4jade.plan.Plan.EndState;
 
@@ -57,6 +60,12 @@ public abstract class BeliefGoalPlanBody extends AbstractPlanBody {
 	 */
 	protected abstract void execute();
 
+	@Parameter(direction = Direction.OUT)
+	public Belief<?, ?> getOutputBelief() {
+		return getBeliefBase().getBelief(
+				((BeliefGoal<?>) getGoal()).getBeliefName());
+	}
+
 	/**
 	 * This method is a placeholder for subclasses. It is invoked by the
 	 * {@link #onStart()} method, after it performs some pre-processing.