|
From: <jom...@us...> - 2015-03-06 22:09:19
|
Revision: 1823
http://sourceforge.net/p/jason/svn/1823
Author: jomifred
Date: 2015-03-06 22:09:17 +0000 (Fri, 06 Mar 2015)
Log Message:
-----------
improvements in meta events related to dropped intentions
Modified Paths:
--------------
trunk/src/jason/asSemantics/Circumstance.java
trunk/src/jason/stdlib/drop_desire.java
Modified: trunk/src/jason/asSemantics/Circumstance.java
===================================================================
--- trunk/src/jason/asSemantics/Circumstance.java 2015-03-02 11:44:12 UTC (rev 1822)
+++ trunk/src/jason/asSemantics/Circumstance.java 2015-03-06 22:09:17 UTC (rev 1823)
@@ -149,20 +149,45 @@
}
public boolean removeEvent(Event ev) {
+ boolean removed = false;
if (ev.equals(AE)) {
AE = null;
- return true;
+ removed = true;
+ } else {
+ removed = E.remove(ev);
}
- return E.remove(ev);
+ if (removed && ev.getIntention() != null && listeners != null)
+ for (CircumstanceListener el : listeners)
+ el.intentionDropped(ev.getIntention());
+ return removed;
}
+ // remove events based on a match with a trigger
+ public void removeEvents(Trigger te, Unifier un) {
+ Iterator<Event> ie = E.iterator();
+ while (ie.hasNext()) {
+ Event ev = ie.next();
+ Trigger t = ev.getTrigger();
+ if (ev.getIntention() != Intention.EmptyInt) { // since the unifier of the intention will not be used, apply it to the event before comparing to the event to be dropped
+ t = t.capply(ev.getIntention().peek().getUnif());
+ }
+ if (un.clone().unifiesNoUndo(te, t)) {
+ ie.remove();
+ if (ev.getIntention() != null && listeners != null)
+ for (CircumstanceListener el : listeners)
+ el.intentionDropped(ev.getIntention());
+ }
+ }
+ }
+
public void clearEvents() {
// notify listeners
if (listeners != null)
for (CircumstanceListener el : listeners) {
for (Event ev: E)
- el.intentionDropped(ev.getIntention());
- if (AE != null)
+ if (ev.getIntention() != null)
+ el.intentionDropped(ev.getIntention());
+ if (AE != null && AE.getIntention() != null)
el.intentionDropped(AE.getIntention());
}
@@ -199,6 +224,10 @@
public Event removeAtomicEvent() {
Event e = AE;
AE = null;
+ if (e != null && e.getIntention() != null && listeners != null)
+ for (CircumstanceListener el : listeners)
+ el.intentionDropped(e.getIntention());
+
return e;
/*if (!hasAtomicEvent)
return null;
@@ -458,9 +487,32 @@
}
public Event removePendingEvent(String pendingId) {
- return PE.remove(pendingId);
+ Event e = PE.remove(pendingId);
+ if (e != null && listeners != null && e.getIntention() != null)
+ for (CircumstanceListener el : listeners)
+ el.intentionDropped(e.getIntention());
+ return e;
}
+ public void removePendingEvents(Trigger te, Unifier un) {
+ Iterator<Event> ie = PE.values().iterator();
+ while (ie.hasNext()) {
+ Event ev = ie.next();
+ Trigger t = ev.getTrigger();
+ if (ev.getIntention() != Intention.EmptyInt) { // since the unifier of the intention will not be used, apply it to the event before comparing to the event to be dropped
+ t = t.capply(ev.getIntention().peek().getUnif());
+ }
+ if (un.clone().unifiesNoUndo(te, t)) {
+ ie.remove();
+
+ if (listeners != null && ev.getIntention() != null)
+ for (CircumstanceListener el : listeners)
+ el.intentionDropped(ev.getIntention());
+ }
+ }
+
+ }
+
/** actions */
public ActionExec getAction() {
Modified: trunk/src/jason/stdlib/drop_desire.java
===================================================================
--- trunk/src/jason/stdlib/drop_desire.java 2015-03-02 11:44:12 UTC (rev 1822)
+++ trunk/src/jason/stdlib/drop_desire.java 2015-03-06 22:09:17 UTC (rev 1823)
@@ -24,8 +24,6 @@
package jason.stdlib;
import jason.asSemantics.Circumstance;
-import jason.asSemantics.Event;
-import jason.asSemantics.Intention;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Literal;
@@ -34,9 +32,7 @@
import jason.asSyntax.Trigger.TEOperator;
import jason.asSyntax.Trigger.TEType;
-import java.util.Iterator;
-
/**
<p>Internal action: <b><code>.drop_desire(<i>D</i>)</code></b>.
@@ -85,12 +81,15 @@
Trigger te = new Trigger(TEOperator.add, TEType.achieve, l);
// search in E
- dropEvt(te, un, C.getEventsPlusAtomic());
+ C.removeEvents(te, un);
+ //dropEvt(te, un, C.getEventsPlusAtomic());
- // search in PE (only the event need to be checked, the related intention is handeled by dropInt)
- dropEvt(te, un, C.getPendingEvents().values().iterator());
+ // search in PE (only the event need to be checked, the related intention is handled by dropInt)
+ C.removePendingEvents(te, un);
+ //dropEvt(te, un, C.getPendingEvents().values().iterator());
}
+ /* moved to circumstance
private static void dropEvt(Trigger te, Unifier un, Iterator<Event> ie) {
while (ie.hasNext()) {
Event ei = ie.next();
@@ -102,5 +101,5 @@
ie.remove();
}
}
- }
+ }*/
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|