|
From: <jom...@us...> - 2015-03-31 12:44:45
|
Revision: 1826
http://sourceforge.net/p/jason/svn/1826
Author: jomifred
Date: 2015-03-31 12:44:42 +0000 (Tue, 31 Mar 2015)
Log Message:
-----------
improve meta events with finish state (achieved, unachieved or dropped)
Modified Paths:
--------------
trunk/demos/meta-events/robot.asl
trunk/src/jason/asSemantics/GoalListener.java
trunk/src/jason/asSemantics/GoalListenerForMetaEvents.java
trunk/src/jason/asSemantics/TransitionSystem.java
trunk/src/jason/stdlib/fail_goal.java
trunk/src/jason/stdlib/resume.java
trunk/src/jason/stdlib/succeed_goal.java
trunk/src/jason/stdlib/suspend.java
Modified: trunk/demos/meta-events/robot.asl
===================================================================
--- trunk/demos/meta-events/robot.asl 2015-03-27 17:34:55 UTC (rev 1825)
+++ trunk/demos/meta-events/robot.asl 2015-03-31 12:44:42 UTC (rev 1826)
@@ -4,7 +4,7 @@
/* Plans for goals */
-+!move <- move; !!move.
++!move <- move; !move.
/* Plans for perception */
Modified: trunk/src/jason/asSemantics/GoalListener.java
===================================================================
--- trunk/src/jason/asSemantics/GoalListener.java 2015-03-27 17:34:55 UTC (rev 1825)
+++ trunk/src/jason/asSemantics/GoalListener.java 2015-03-31 12:44:42 UTC (rev 1826)
@@ -6,12 +6,13 @@
public interface GoalListener {
public enum GoalStates { started, suspended, resumed, finished, failed } ;
+ public enum FinishStates { achieved, unachieved, dropped } ;
/** method called when a new goal is produced by operator ! */
public void goalStarted(Event goal);
- /** method called when a goal is successfully finished */
- public void goalFinished(Trigger goal);
+ /** method called when a goal is (un)successfully finished */
+ public void goalFinished(Trigger goal, FinishStates result);
/** method called when a goal is failed */
public void goalFailed(Trigger goal);
Modified: trunk/src/jason/asSemantics/GoalListenerForMetaEvents.java
===================================================================
--- trunk/src/jason/asSemantics/GoalListenerForMetaEvents.java 2015-03-27 17:34:55 UTC (rev 1825)
+++ trunk/src/jason/asSemantics/GoalListenerForMetaEvents.java 2015-03-31 12:44:42 UTC (rev 1826)
@@ -24,8 +24,8 @@
generateGoalStateEvent(goal.getLiteral(), goal.getType(), GoalStates.failed, null);
}
- public void goalFinished(Trigger goal) {
- generateGoalStateEvent(goal.getLiteral(), goal.getType(), GoalStates.finished, null);
+ public void goalFinished(Trigger goal, FinishStates result) {
+ generateGoalStateEvent(goal.getLiteral(), goal.getType(), GoalStates.finished, result.toString());
}
public void goalResumed(Trigger goal) {
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2015-03-27 17:34:55 UTC (rev 1825)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2015-03-31 12:44:42 UTC (rev 1826)
@@ -27,6 +27,7 @@
import jason.NoValueException;
import jason.RevisionFailedException;
import jason.architecture.AgArch;
+import jason.asSemantics.GoalListener.FinishStates;
import jason.asSyntax.ASSyntax;
import jason.asSyntax.Atom;
import jason.asSyntax.BinaryStructure;
@@ -158,7 +159,7 @@
public void intentionDropped(Intention i) {
for (IntendedMeans im: i) //.getIMs())
if (im.getTrigger().isAddition() && im.getTrigger().isGoal())
- gl.goalFinished(im.getTrigger());
+ gl.goalFinished(im.getTrigger(), FinishStates.dropped);
}
public void intentionSuspended(Intention i, String reason) {
@@ -916,13 +917,14 @@
IntendedMeans topIM = i.pop();
Trigger topTrigger = topIM.getTrigger();
Literal topLiteral = topTrigger.getLiteral();
- if (logger.isLoggable(Level.FINE)) logger.fine("Returning from IM "+topIM.getPlan().getLabel()+", te="+topIM.getPlan().getTrigger()+" unif="+topIM.unif);
+ if (logger.isLoggable(Level.FINE))
+ logger.fine("Returning from IM "+topIM.getPlan().getLabel()+", te="+topTrigger+" unif="+topIM.unif);
- // produce ^!g[state(finished)] event
- if (topTrigger.getOperator() == TEOperator.add && topTrigger.isGoal()) {
- if (hasGoalListener())
- for (GoalListener gl: goalListeners)
- gl.goalFinished(topTrigger);
+ // produce ^!g[state(finished)[reason(achieved)]] event
+ if (!topTrigger.isMetaEvent() && topTrigger.isGoal() && hasGoalListener()) {
+ for (GoalListener gl: goalListeners) {
+ gl.goalFinished(topTrigger, FinishStates.achieved);
+ }
}
// if has finished a failure handling IM ...
@@ -1099,8 +1101,11 @@
if (im.isGoalAdd()) {
// notify listener
if (hasGoalListener())
- for (GoalListener gl: goalListeners)
+ for (GoalListener gl: goalListeners) {
gl.goalFailed(im.getTrigger());
+ if (!failEventIsRelevant)
+ gl.goalFinished(im.getTrigger(), FinishStates.unachieved);
+ }
if (failEventIsRelevant) {
confP.C.addEvent(failEvent);
Modified: trunk/src/jason/stdlib/fail_goal.java
===================================================================
--- trunk/src/jason/stdlib/fail_goal.java 2015-03-27 17:34:55 UTC (rev 1825)
+++ trunk/src/jason/stdlib/fail_goal.java 2015-03-31 12:44:42 UTC (rev 1826)
@@ -29,6 +29,7 @@
import jason.asSemantics.Intention;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
+import jason.asSemantics.GoalListener.FinishStates;
import jason.asSyntax.Literal;
import jason.asSyntax.Term;
import jason.asSyntax.Trigger;
@@ -47,6 +48,8 @@
is a goal if there is a triggering event <code>+!G</code> in any plan within
any intention; also note that intentions can be suspended hence appearing
in sets E, PA, or PI of the agent's circumstance as well.
+ <br/>
+ The meta-event <code>^!G[state(failed)]</code> is produced.
<p>Example:<ul>
@@ -109,6 +112,9 @@
return 2;
} else { // i is finished or without failure plan
ts.getLogger().fine("'.fail_goal("+g+")' is removing the intention without event:\n" + i);
+ if (ts.hasGoalListener())
+ for (GoalListener gl: ts.getGoalListeners())
+ gl.goalFinished(g, FinishStates.unachieved);
return 3;
}
}
Modified: trunk/src/jason/stdlib/resume.java
===================================================================
--- trunk/src/jason/stdlib/resume.java 2015-03-27 17:34:55 UTC (rev 1825)
+++ trunk/src/jason/stdlib/resume.java 2015-03-31 12:44:42 UTC (rev 1826)
@@ -44,6 +44,8 @@
<b><code>.resume(<i>G</i>)</code></b>.
<p>Description: resume goals <i>G</i> that were suspended by <code>.suspend</code>.
+ <br/>
+ The meta-event <code>^!G[state(resumed)]</code> is produced.
<p>Example:<ul>
Modified: trunk/src/jason/stdlib/succeed_goal.java
===================================================================
--- trunk/src/jason/stdlib/succeed_goal.java 2015-03-27 17:34:55 UTC (rev 1825)
+++ trunk/src/jason/stdlib/succeed_goal.java 2015-03-31 12:44:42 UTC (rev 1826)
@@ -32,6 +32,7 @@
import jason.asSemantics.Intention;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
+import jason.asSemantics.GoalListener.FinishStates;
import jason.asSyntax.Literal;
import jason.asSyntax.Term;
import jason.asSyntax.Trigger;
@@ -49,6 +50,8 @@
is a goal if there is a triggering event <code>+!G</code> in any plan within any
intention; also note that intentions can be suspended hence appearing
in E, PA, or PI as well.
+ <br/>
+ The meta-event <code>^!G[state(finished)]</code> is produced.
<p>Example:<ul>
@@ -196,7 +199,7 @@
if (i != null && i.dropGoal(g, un)) {
if (ts.hasGoalListener())
for (GoalListener gl: ts.getGoalListeners())
- gl.goalFinished(g);
+ gl.goalFinished(g, FinishStates.achieved);
// continue the intention
if (!i.isFinished()) { // could be finished after i.dropGoal() !!
@@ -218,7 +221,7 @@
if (i != null) {
if (ts.hasGoalListener())
for (GoalListener gl: ts.getGoalListeners())
- gl.goalFinished(e.getTrigger());
+ gl.goalFinished(e.getTrigger(), FinishStates.achieved);
i.peek().removeCurrentStep();
ts.applyClrInt(i);
C.addIntention(i);
Modified: trunk/src/jason/stdlib/suspend.java
===================================================================
--- trunk/src/jason/stdlib/suspend.java 2015-03-27 17:34:55 UTC (rev 1825)
+++ trunk/src/jason/stdlib/suspend.java 2015-03-31 12:44:42 UTC (rev 1826)
@@ -47,7 +47,9 @@
running until the internal action <code>.resume</code> change the state of those intentions.
A literal <i>G</i>
is a goal if there is a triggering event <code>+!G</code> in any plan within
- any intention in I, E, PI, or PA.
+ any intention in I, E, PI, or PA.
+ <br/>
+ The meta-event <code>^!G[state(suspended)]</code> is produced.
<p>Examples:<ul>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|