|
From: <jom...@us...> - 2008-04-16 16:46:53
|
Revision: 1218
http://jason.svn.sourceforge.net/jason/?rev=1218&view=rev
Author: jomifred
Date: 2008-04-16 09:46:46 -0700 (Wed, 16 Apr 2008)
Log Message:
-----------
correctly handle failure events caused by no relevant plans
minor changes in the jason team
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/tests/TestAll.java
trunk/applications/jason-team/logging.properties
trunk/applications/jason-team/src/java/arch/ACArchitecture.java
trunk/applications/jason-team/src/java/arch/IdentifyCrashed.java
trunk/applications/jason-team/src/java/arch/WriteStatusThread.java
trunk/release-notes.txt
trunk/src/jason/asSemantics/TransitionSystem.java
Added Paths:
-----------
trunk/applications/as-unit-test/src/jason/tests/TestPlanFailure.java
Modified: trunk/applications/as-unit-test/src/jason/tests/TestAll.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2008-04-16 16:46:46 UTC (rev 1218)
@@ -8,8 +8,10 @@
@SuiteClasses({
BugVarsInInitBels.class,
TestAddLogExprInBB.class,
+ TestGoalSource.class,
TestKQML.class,
- TestVarInContext.class /*,
- TestPlanbodyAsTerm.class*/
+ /* TestPlanbodyAsTerm.class, */
+ TestPlanFailure.class,
+ TestVarInContext.class
})
public class TestAll { }
Added: trunk/applications/as-unit-test/src/jason/tests/TestPlanFailure.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestPlanFailure.java (rev 0)
+++ trunk/applications/as-unit-test/src/jason/tests/TestPlanFailure.java 2008-04-16 16:46:46 UTC (rev 1218)
@@ -0,0 +1,49 @@
+package jason.tests;
+
+import jason.asunit.TestAgent;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestPlanFailure {
+
+ TestAgent ag;
+
+ // initialisation of the agent test
+ @Before
+ public void setupAg() {
+ ag = new TestAgent();
+
+ // defines the agent's AgentSpeak code
+ ag.parseAScode(
+ "+!test : true <- !g1(X); endtest; end(X). "+
+
+ "+!g1(X) : true <- inig1; !g2(X); endg1. "+
+ "+!g2(X) : true <- inig2; !g3(X); endg2. "+
+ "+!g3(X) : true <- inig2; !g4(X); endg3. "+
+ "+!g4(X) : true <- inig4; !g5(X); endg4. "+
+ "+!g5(_) : true <- .fail. "+
+ "-!g3(failure) : true <- infailg3. "+
+
+ "+!norel <- !j; endnorel. "+
+ "-!j <- infailj. "
+ );
+ }
+
+ @Test
+ public void testFailurePlan() {
+ ag.addGoal("test");
+ ag.assertAct("inig4", 10);
+ ag.assertAct("infailg3", 5);
+ ag.assertAct("endg2", 5);
+ ag.assertAct("endtest", 5);
+ ag.assertAct("end(failure)", 5);
+ }
+
+ @Test
+ public void testNoRelPlan() {
+ ag.addGoal("norel");
+ ag.assertAct("infailj", 10);
+ ag.assertAct("endnorel", 5);
+ }
+}
Modified: trunk/applications/jason-team/logging.properties
===================================================================
--- trunk/applications/jason-team/logging.properties 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/applications/jason-team/logging.properties 2008-04-16 16:46:46 UTC (rev 1218)
@@ -4,10 +4,10 @@
#
# default Jason MAS Console
-handlers = jason.runtime.MASConsoleLogHandler, java.util.logging.FileHandler
+#handlers = jason.runtime.MASConsoleLogHandler, java.util.logging.FileHandler
# To use the ConsoleHandler, use the following line instead.
-#handlers= java.util.logging.ConsoleHandler, java.util.logging.FileHandler
+handlers= java.util.logging.ConsoleHandler, java.util.logging.FileHandler
# Default logging level. Other values are:
# SEVERE (only severe messages)
Modified: trunk/applications/jason-team/src/java/arch/ACArchitecture.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-04-16 16:46:46 UTC (rev 1218)
@@ -61,6 +61,7 @@
@Override
public List<Literal> perceive() {
+ agDidPerceive(); // for crash control
return new ArrayList<Literal>(percepts); // it must be a copy!
}
Modified: trunk/applications/jason-team/src/java/arch/IdentifyCrashed.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/IdentifyCrashed.java 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/applications/jason-team/src/java/arch/IdentifyCrashed.java 2008-04-16 16:46:46 UTC (rev 1218)
@@ -42,27 +42,23 @@
@Override
public List<Literal> perceive() {
- agThread = Thread.currentThread();
- doPercept();
+ agThread = Thread.currentThread();
+ agDidPerceive();
return super.perceive();
}
- private synchronized void doPercept() {
+ public synchronized void agDidPerceive() {
didPercept = true;
notifyAll();
}
- public boolean didPercept() {
- return didPercept;
+ private synchronized void waitPerceive() throws InterruptedException {
+ wait(maxCycleTime);
}
-
+
public boolean isCrashed() {
return !didPercept;
}
-
- private synchronized void waitPercept() throws InterruptedException {
- wait(maxCycleTime);
- }
@Override
public void stopAg() {
@@ -78,7 +74,7 @@
dead = true;
// gives some time to TS get the change in state
- waitPercept();
+ waitPerceive();
try {
if (isCrashed()) {
return fix2();
@@ -94,17 +90,23 @@
/** try to fix the agent: approach 2: interrupt the agent thread */
protected boolean fix2() throws Exception {
- getTS().getLogger().warning("fix2: I am still dead! Interrupting the agent thread...");
- // try to interrupt the agent thread.
- agThread.interrupt();
+ if (agThread != null) {
+ getTS().getLogger().warning("fix2: I am still dead! Interrupting the agent thread...");
+ // try to interrupt the agent thread.
+
+ agThread.interrupt();
- waitPercept();
- if (isCrashed()) {
- getTS().getLogger().warning("Interrupt doesn't work!!! The agent remains dead!");
- return fix3();
+ waitPerceive();
+ if (isCrashed()) {
+ getTS().getLogger().warning("Interrupt doesn't work!!! The agent remains dead!");
+ return fix3();
+ } else {
+ getTS().getLogger().warning("fix2: I am Ok now!");
+ return true;
+ }
} else {
- getTS().getLogger().warning("fix2: I am Ok now!");
- return true;
+ getTS().getLogger().warning("fix2: can not be used (thread == null).");
+ return fix3();
}
}
Modified: trunk/applications/jason-team/src/java/arch/WriteStatusThread.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/WriteStatusThread.java 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/applications/jason-team/src/java/arch/WriteStatusThread.java 2008-04-16 16:46:46 UTC (rev 1218)
@@ -109,6 +109,7 @@
if (act.equals(WorldModel.Move.southwest.toString())) return "sw";
if (act.equals(WorldModel.Move.north.toString())) return "n ";
if (act.equals(WorldModel.Move.south.toString())) return "s ";
+ if (act.equals(WorldModel.Move.skip.toString())) return "sk";
return act;
}
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/release-notes.txt 2008-04-16 16:46:46 UTC (rev 1218)
@@ -5,6 +5,7 @@
Bugs fixed:
. use nested source annotations in communication
. add "source(self)" in goals without source
+. correctly handle failure event caused by no relevant plans
-------------
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2008-04-16 16:46:46 UTC (rev 1218)
@@ -459,13 +459,13 @@
// Rule Achieve
case achieve:
- // free variables in an event cannot conflict with those in the plan
- body = (Literal)body.clone();
if (!body.hasSource()) {
// do not add source(self) in case the
// programmer set some annotation
body.addAnnot(BeliefBase.TSelf);
}
+ // free variables in an event cannot conflict with those in the plan
+ body = (Literal)body.clone();
body.makeVarsAnnon();
conf.C.addAchvGoal(body, conf.C.SI);
confP.step = State.StartRC;
@@ -473,12 +473,12 @@
// Rule Achieve as a New Focus (the !! operator)
case achieveNF:
- body = (Literal)body.clone();
if (!body.hasSource()) {
// do not add source(self) in case the
// programmer set some annotation
body.addAnnot(BeliefBase.TSelf);
}
+ body = (Literal)body.clone();
body.makeVarsAnnon();
conf.C.addAchvGoal(body, Intention.EmptyInt);
updateIntention();
@@ -635,8 +635,13 @@
// +!s: !b; !z
// should became
// +!s: !z
- im = i.pop(); // +!c above, old
- while (!im.unif.unifies(topIM.getTrigger().getLiteral(), im.getTrigger().getLiteral()) && i.size() > 0) {
+ im = i.peek();
+ if (im.isFinished() || !im.unif.unifies(topIM.getTrigger().getLiteral(), im.getCurrentStep().getBodyTerm()))
+ im = i.pop(); // +!c above
+
+ while (i.size() > 0 &&
+ !im.unif.unifies(topIM.getTrigger().getLiteral(), im.getTrigger().getLiteral()) &&
+ !im.unif.unifies(topIM.getTrigger().getLiteral(), im.getCurrentStep().getBodyTerm())) {
im = i.pop();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|