bdi4jade
Changes
bdi-jade/src/bdi4jade/belief/BeliefBase.java 21(+21 -0)
bdi-jade/src/bdi4jade/core/BDIAgent.java 13(+13 -0)
Details
bdi-jade/src/bdi4jade/belief/BeliefBase.java 21(+21 -0)
diff --git a/bdi-jade/src/bdi4jade/belief/BeliefBase.java b/bdi-jade/src/bdi4jade/belief/BeliefBase.java
index fd9e7a7..d5ec621 100644
--- a/bdi-jade/src/bdi4jade/belief/BeliefBase.java
+++ b/bdi-jade/src/bdi4jade/belief/BeliefBase.java
@@ -335,6 +335,27 @@ public class BeliefBase implements Serializable {
}
/**
+ * Checks whether a belief is part of the belief base with an specific
+ * value. If this belief base does not contain it, the method checks
+ * whole-capabilities' belief base recursively.
+ *
+ * @param name
+ * the belief to be checked
+ * @return true if the belief base contains the belief.
+ */
+ public boolean hasBelief(Object name, Object value) {
+ Belief<?, ?> belief = getBelief(name);
+ if (belief == null) {
+ return false;
+ }
+ if (belief.getValue() == null) {
+ return value == null;
+ } else {
+ return belief.getValue() == value;
+ }
+ }
+
+ /**
* Notifies the capability associated with this belief base that a belief
* was modified. It also recursively notifies belief listeners of part
* capabilities.
diff --git a/bdi-jade/src/bdi4jade/belief/TransientPropositionalBelief.java b/bdi-jade/src/bdi4jade/belief/TransientPropositionalBelief.java
index ee8113d..90e7bd1 100644
--- a/bdi-jade/src/bdi4jade/belief/TransientPropositionalBelief.java
+++ b/bdi-jade/src/bdi4jade/belief/TransientPropositionalBelief.java
@@ -33,4 +33,35 @@ public class TransientPropositionalBelief<K> extends
private static final long serialVersionUID = -2315938302480821432L;
+ /**
+ * The default constructor. It should be only used if persistence frameworks
+ * are used.
+ */
+ protected TransientPropositionalBelief() {
+
+ }
+
+ /**
+ * Creates a new transient propositional belief, whose value is true.
+ *
+ * @param name
+ * the belief name.
+ */
+ public TransientPropositionalBelief(K name) {
+ super(name, Boolean.TRUE);
+ }
+
+ /**
+ * Initializes a transient propositional belief with its name and a initial
+ * value.
+ *
+ * @param name
+ * the belief name.
+ * @param value
+ * the initial belief value.
+ */
+ public TransientPropositionalBelief(K name, Boolean value) {
+ super(name, value);
+ }
+
}
diff --git a/bdi-jade/src/bdi4jade/core/AbstractBDIAgent.java b/bdi-jade/src/bdi4jade/core/AbstractBDIAgent.java
index b319071..84c8305 100644
--- a/bdi-jade/src/bdi4jade/core/AbstractBDIAgent.java
+++ b/bdi-jade/src/bdi4jade/core/AbstractBDIAgent.java
@@ -361,11 +361,13 @@ public abstract class AbstractBDIAgent extends Agent implements BDIAgent {
} else {
dispatcher.addIntention(intention);
}
- this.bdiInterpreter.restart();
if (goalListener != null) {
intention.addGoalListener(goalListener);
}
fireGoalEvent(new GoalEvent(goal));
+
+ restart();
+
return intention;
}
}
@@ -464,12 +466,10 @@ public abstract class AbstractBDIAgent extends Agent implements BDIAgent {
}
/**
- * Returns all capabilities that are part of this agent. This included all
- * capabilities composed or associated with other capabilities.
- *
- * @return the capabilities.
+ * @see BDIAgent#getAllCapabilities()
*/
- protected Collection<Capability> getAllCapabilities() {
+ @Override
+ public Collection<Capability> getAllCapabilities() {
synchronized (aggregatedCapabilities) {
return capabilities;
}
@@ -673,6 +673,14 @@ public abstract class AbstractBDIAgent extends Agent implements BDIAgent {
}
/**
+ * @see BDIAgent#restart()
+ */
+ @Override
+ public void restart() {
+ this.bdiInterpreter.restart();
+ }
+
+ /**
* Sets the belief revision strategy of this agent.
*
* @param beliefRevisionStrategy
bdi-jade/src/bdi4jade/core/BDIAgent.java 13(+13 -0)
diff --git a/bdi-jade/src/bdi4jade/core/BDIAgent.java b/bdi-jade/src/bdi4jade/core/BDIAgent.java
index f1bdd9a..8d5c82f 100644
--- a/bdi-jade/src/bdi4jade/core/BDIAgent.java
+++ b/bdi-jade/src/bdi4jade/core/BDIAgent.java
@@ -148,6 +148,14 @@ public interface BDIAgent {
public AID getAID();
/**
+ * Returns all capabilities that are part of this agent. This included all
+ * capabilities composed or associated with other capabilities.
+ *
+ * @return the capabilities.
+ */
+ public Collection<Capability> getAllCapabilities();
+
+ /**
* 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.
*
@@ -194,4 +202,9 @@ public interface BDIAgent {
*/
public void removeGoalListener(GoalListener goalListener);
+ /**
+ * Restarts the agent in case its reasoning cycle is in the blocked state.
+ */
+ public void restart();
+
}
diff --git a/bdi-jade/src/bdi4jade/goal/BeliefSetValueGoal.java b/bdi-jade/src/bdi4jade/goal/BeliefSetValueGoal.java
index 91552f3..7ed7ea0 100644
--- a/bdi-jade/src/bdi4jade/goal/BeliefSetValueGoal.java
+++ b/bdi-jade/src/bdi4jade/goal/BeliefSetValueGoal.java
@@ -30,7 +30,9 @@ import bdi4jade.belief.BeliefSet;
* a certain value, that is, the agent has a belief set whose name is specified
* in this goal and it contains the specified value.
*
- * @param <T>
+ * @param <K>
+ * the type of the belief name.
+ * @param <V>
* the type of the values in the belief set.
*
* @author Ingrid Nunes
diff --git a/bdi-jade/src/bdi4jade/goal/BeliefValueGoal.java b/bdi-jade/src/bdi4jade/goal/BeliefValueGoal.java
index c93ccaa..89153c3 100644
--- a/bdi-jade/src/bdi4jade/goal/BeliefValueGoal.java
+++ b/bdi-jade/src/bdi4jade/goal/BeliefValueGoal.java
@@ -32,7 +32,9 @@ import bdi4jade.belief.BeliefBase;
* with an specific value, that is, the agent has a belief whose name and value
* are specified in this goal.
*
- * @param <T>
+ * @param <K>
+ * the type of the belief name.
+ * @param <V>
* the type of the belief value.
*
* @author Ingrid Nunes
diff --git a/bdi-jade/src/bdi4jade/reasoning/AbstractAgentReasoningStrategy.java b/bdi-jade/src/bdi4jade/reasoning/AbstractAgentReasoningStrategy.java
index f6f05ea..83d9aa6 100644
--- a/bdi-jade/src/bdi4jade/reasoning/AbstractAgentReasoningStrategy.java
+++ b/bdi-jade/src/bdi4jade/reasoning/AbstractAgentReasoningStrategy.java
@@ -42,7 +42,7 @@ public abstract class AbstractAgentReasoningStrategy implements
*/
@Override
public void setAgent(AbstractBDIAgent agent) {
- if (this.agent != null) {
+ if (agent != null && this.agent != null && !this.agent.equals(agent)) {
throw new IllegalArgumentException(
"This reasoning strategy is already associated with another agent.");
}
diff --git a/bdi-jade/src/bdi4jade/reasoning/AbstractReasoningStrategy.java b/bdi-jade/src/bdi4jade/reasoning/AbstractReasoningStrategy.java
index b109d9d..924cf9d 100644
--- a/bdi-jade/src/bdi4jade/reasoning/AbstractReasoningStrategy.java
+++ b/bdi-jade/src/bdi4jade/reasoning/AbstractReasoningStrategy.java
@@ -41,7 +41,8 @@ public abstract class AbstractReasoningStrategy implements ReasoningStrategy {
*/
@Override
public void setCapability(Capability capability) {
- if (this.capability != null) {
+ if (capability != null && this.capability != null
+ && !this.capability.equals(capability)) {
throw new IllegalArgumentException(
"This reasoning strategy is already associated with another capability.");
}
diff --git a/bdi-jade/src/bdi4jade/reasoning/DefaultAgentBeliefRevisionStrategy.java b/bdi-jade/src/bdi4jade/reasoning/DefaultAgentBeliefRevisionStrategy.java
index 80ecdc2..f358930 100644
--- a/bdi-jade/src/bdi4jade/reasoning/DefaultAgentBeliefRevisionStrategy.java
+++ b/bdi-jade/src/bdi4jade/reasoning/DefaultAgentBeliefRevisionStrategy.java
@@ -35,14 +35,15 @@ public class DefaultAgentBeliefRevisionStrategy extends
AbstractAgentReasoningStrategy implements AgentBeliefRevisionStrategy {
/**
- * This default implementation requests each of its capabilities to review
- * their individual set of beliefs.
+ * This default implementation requests each of its capabilities (including
+ * associated and composed capabilities) to review their individual set of
+ * beliefs.
*
* @see AgentBeliefRevisionStrategy#reviewBeliefs()
*/
@Override
public void reviewBeliefs() {
- for (Capability capability : agent.getCapabilities()) {
+ for (Capability capability : agent.getAllCapabilities()) {
capability.getBeliefRevisionStrategy().reviewBeliefs();
}
}