|
From: <jom...@us...> - 2008-05-07 16:55:32
|
Revision: 1295
http://jason.svn.sourceforge.net/jason/?rev=1295&view=rev
Author: jomifred
Date: 2008-05-07 08:59:20 -0700 (Wed, 07 May 2008)
Log Message:
-----------
make all jmoise actions "synchronous" (the intention is suspended until
the end of the execution of the action)
Modified Paths:
--------------
trunk/applications/jason-moise/example/writePaper/jaime.asl
trunk/applications/jason-moise/src/jmoise/MoiseBaseIA.java
trunk/applications/jason-moise/src/jmoise/OrgAgent.java
trunk/applications/jason-moise/src/jmoise/OrgManager.java
trunk/applications/jason-moise/src/jmoise/adopt_role.java
trunk/applications/jason-moise/src/jmoise/create_group.java
trunk/applications/jason-moise/src/jmoise/create_scheme.java
trunk/applications/jason-moise/src/jmoise/link.java
trunk/applications/jason-moise/src/jmoise/set_org_manager.java
trunk/src/jason/asSyntax/Structure.java
trunk/src/jason/stdlib/suspend.java
Modified: trunk/applications/jason-moise/example/writePaper/jaime.asl
===================================================================
--- trunk/applications/jason-moise/example/writePaper/jaime.asl 2008-05-07 10:12:25 UTC (rev 1294)
+++ trunk/applications/jason-moise/example/writePaper/jaime.asl 2008-05-07 15:59:20 UTC (rev 1295)
@@ -15,7 +15,8 @@
// create a group to write a paper
+!create_group : true
<- //.send(orgManager, achieve, create_group(wpgroup)).
- jmoise.create_group(wpgroup).
+ jmoise.create_group(wpgroup,G);
+ .print("Group ",G," created").
@@ -35,7 +36,8 @@
// when a scheme has finished, start another
-scheme(writePaperSch,_)
: group(wpgroup,GId)
- <- jmoise.create_scheme(writePaperSch, [GId]).
+ <- jmoise.create_scheme(writePaperSch, [GId], SchId);
+ .print("Scheme ",SchId," created").
// include common plans for MOISE+ agents
{ include("moise-common.asl") }
Modified: trunk/applications/jason-moise/src/jmoise/MoiseBaseIA.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/MoiseBaseIA.java 2008-05-07 10:12:25 UTC (rev 1294)
+++ trunk/applications/jason-moise/src/jmoise/MoiseBaseIA.java 2008-05-07 15:59:20 UTC (rev 1295)
@@ -2,6 +2,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.Intention;
import jason.asSemantics.Message;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
@@ -26,6 +27,10 @@
String acName = this.getClass().getSimpleName(); // remove the package name "jmoise"
Structure acTerm = new Structure(acName);
acTerm.addTerms(args);
+ // remove the last arg if unground (the return of the IA)
+ if (!acTerm.getTerm(args.length-1).isGround()) {
+ acTerm.delTerm(args.length-1);
+ }
if (logger.isLoggable(Level.FINE)) logger.fine("sending: "+acTerm);
// send acTerm as message to OrgManager
@@ -33,6 +38,12 @@
OrgAgent oag = (OrgAgent)ts.getUserAgArch();
Message m = new Message("achieve", null, oag.getOrgManagerName(), acTerm);
oag.sendMsg(m);
+
+ if (suspendIntention()) {
+ Intention i = ts.getC().getSelectedIntention();
+ i.setSuspended(true);
+ ts.getC().getPendingIntentions().put("om/"+m.getMsgId(), i);
+ }
return true;
} catch (JasonException e) {
throw e;
@@ -41,4 +52,10 @@
}
return false;
}
+
+ @Override
+ public boolean suspendIntention() {
+ return true;
+ }
+
}
Modified: trunk/applications/jason-moise/src/jmoise/OrgAgent.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2008-05-07 10:12:25 UTC (rev 1294)
+++ trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2008-05-07 15:59:20 UTC (rev 1295)
@@ -4,13 +4,17 @@
import jason.RevisionFailedException;
import jason.architecture.AgArch;
import jason.asSemantics.Agent;
+import jason.asSemantics.Circumstance;
import jason.asSemantics.Event;
import jason.asSemantics.Intention;
import jason.asSemantics.Message;
import jason.asSemantics.Unifier;
import jason.asSyntax.Atom;
import jason.asSyntax.DefaultTerm;
+import jason.asSyntax.InternalActionLiteral;
import jason.asSyntax.Literal;
+import jason.asSyntax.PlanBody;
+import jason.asSyntax.PlanBodyImpl;
import jason.asSyntax.Pred;
import jason.asSyntax.PredicateIndicator;
import jason.asSyntax.Structure;
@@ -18,6 +22,7 @@
import jason.asSyntax.Trigger;
import jason.asSyntax.UnnamedVar;
import jason.asSyntax.VarTerm;
+import jason.asSyntax.PlanBody.BodyType;
import jason.asSyntax.Trigger.TEOperator;
import jason.asSyntax.Trigger.TEType;
import jason.mas2j.ClassParameters;
@@ -87,8 +92,8 @@
public void checkMail() {
super.checkMail(); // get the messages from arch to circumstance
-
- Iterator<Message> i = getTS().getC().getMailBox().iterator();
+ Circumstance C = getTS().getC();
+ Iterator<Message> i = C.getMailBox().iterator();
boolean updateGoalBels = false;
boolean updateGoalEvt = false;
while (i.hasNext()) {
@@ -138,6 +143,33 @@
String schId = Pred.parsePred(content).getTerm(1).toString();
removeAchieveGoalsOfSch(schId);
removeBeliefs(schId);
+
+ // test if it is the result of some org action
+ } else if (m.getInReplyTo() != null) {
+ // find the intention
+ Intention pi = C.getPendingIntentions().remove("om/"+m.getInReplyTo());
+ if (pi != null) {
+ i.remove();
+ pi.setSuspended(false);
+ C.addIntention(pi); // add it back in I
+ Structure body = (Structure)pi.peek().removeCurrentStep(); // remove the internal action
+
+ if (content.startsWith("error")) {
+ // fail the IA
+ PlanBody pbody = pi.peek().getPlan().getBody();
+ pbody.add(0, new PlanBodyImpl(BodyType.internalAction, new InternalActionLiteral(".fail")));
+ getTS().getLogger().warning("Error in organisational action: "+content);
+ } else {
+ // try to unify the return value
+ //System.out.println("answer is "+content+" or "+DefaultTerm.parse(content)+" with body "+body);
+ // if the last arg of body is a free var
+ Term lastTerm = body.getTerm(body.getArity()-1);
+ if (!lastTerm.isGround()) {
+ pi.peek().getUnif().unifies(lastTerm, DefaultTerm.parse(content));
+ //System.out.println("un = "+pi.peek().getUnif());
+ }
+ }
+ }
}
}
} catch (Exception e) {
Modified: trunk/applications/jason-moise/src/jmoise/OrgManager.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/OrgManager.java 2008-05-07 10:12:25 UTC (rev 1294)
+++ trunk/applications/jason-moise/src/jmoise/OrgManager.java 2008-05-07 15:59:20 UTC (rev 1295)
@@ -205,6 +205,7 @@
updateMembersOE(sender, "play(" + rp.getPlayer().getId() + "," + rp.getRole().getId() + "," + grId + ")", false, true);
}
}
+ sendReply(sender, mId, "ok");
}
}
@@ -231,6 +232,7 @@
updateMembersOE(sender, "play(" + rp.getPlayer().getId() + "," + rp.getRole().getId() + "," + gr.getId() + ")", false, false);
}
}
+ sendReply(sender, mId, "ok");
}
}
@@ -259,6 +261,7 @@
updateMembersOE(sch.getOwner(), "sch_players(" + sch.getId() + ",NP)", false, false);
}
updateMembersOE(sch.getOwner(), "sch_players(" + sch.getId() + "," + sch.getPlayersQty() + ")", false, true);
+ sendReply(sender, mId, "ok");
}
}
@@ -305,6 +308,7 @@
// notify owner that it can finish the scheme
updateMembersOE(sch.getOwner(), "sch_players(" + sch.getId() + ",NP)", false, false);
updateMembersOE(sch.getOwner(), "sch_players(" + sch.getId() + "," + sch.getPlayersQty() + ")", false, true);
+ sendReply(sender, mId, "ok");
}
}
@@ -333,6 +337,7 @@
newGr.setOwner(sender);
updateMembersOE(currentOE.getAgents(), "group(" + specId + "," + newGr.getId() + ")[owner(" + sender + ")," + annot + "]", false, true);
+ sendReply(sender, mId, newGr.getId());
}
}
@@ -389,6 +394,7 @@
// sent a new copy of OE
updateMembersOE(currentOE.getAgents(), "group(" + gr.getGrSpec().getId() + "," + gr.getId() + ")", true, false);
+ sendReply(sender, mId, "ok");
}
}
@@ -429,6 +435,7 @@
updateMembersOE(gi.getPlayers(), "scheme_group(" + sch.getId() + "," + gi.getId() + ")", true, true);
}
}
+ sendReply(sender, mId, sch.getId());
}
}
@@ -457,6 +464,7 @@
sch.addResponsibleGroup(gr);
updateMembersOE(gr.getPlayers(), "scheme_group(" + schId + "," + grId + ")", true, true);
+ sendReply(sender, mId, "ok");
}
}
@@ -479,6 +487,7 @@
act(currentOE, sch);
// send untell to agents
updateMembersOE(currentOE.getAgents(), "scheme(" + sch.getSpec().getId() + "," + sch.getId() + ")[owner(" + sch.getOwner() + ")]", false, false);
+ sendReply(sender, mId, "ok");
}
protected void act(OE currentOE, SchemeInstance sch) throws MoiseException {
currentOE.finishScheme(sch);
@@ -526,6 +535,7 @@
gi.setImpossible(sender);
}
updateMembersOE(sch.getPlayers(), "goal_state(" + gi.getScheme().getId() + "," + gi.getSpec().getId() + ")", true, true);
+ sendReply(sender, mId, "ok");
}
}
@@ -565,6 +575,7 @@
gi.setArgumentValue(arg, value);
updateMembersOE(sch.getPlayers(), "goal_state(" + gi.getScheme().getId() + "," + gi.getSpec().getId() + ")", true, true);
+ sendReply(sender, mId, "ok");
}
}
Modified: trunk/applications/jason-moise/src/jmoise/adopt_role.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/adopt_role.java 2008-05-07 10:12:25 UTC (rev 1294)
+++ trunk/applications/jason-moise/src/jmoise/adopt_role.java 2008-05-07 15:59:20 UTC (rev 1295)
@@ -49,5 +49,5 @@
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
return super.execute(ts,un,args);
- }
+ }
}
Modified: trunk/applications/jason-moise/src/jmoise/create_group.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/create_group.java 2008-05-07 10:12:25 UTC (rev 1294)
+++ trunk/applications/jason-moise/src/jmoise/create_group.java 2008-05-07 15:59:20 UTC (rev 1295)
@@ -29,8 +29,12 @@
<ul>
<li> <code>jmoise.create_group(team)</code>:
creates a new root group based on specification of a team.</li>
+<li> <code>jmoise.create_group(team,G)</code>:
+ creates a new root group based on specification of a team and unifies in G the identification of the new group.</li>
<li> <code>jmoise.create_group(defence, team0)</code>:
creates a sub-group of group team0 based on specification defence.</li>
+<li> <code>jmoise.create_group(defence, team0, G)</code>:
+ creates a sub-group of group team0 based on specification defence and unifies in G the identification of the new group.</li>
</ul>
@see jmoise.remove_group
Modified: trunk/applications/jason-moise/src/jmoise/create_scheme.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/create_scheme.java 2008-05-07 10:12:25 UTC (rev 1294)
+++ trunk/applications/jason-moise/src/jmoise/create_scheme.java 2008-05-07 15:59:20 UTC (rev 1295)
@@ -22,9 +22,12 @@
<ul>
<li> <code>jmoise.create_scheme(wp)</code>:
creates new scheme based on specification wp.</li>
-<li> <code>jmoise.create_scheme(wp, [ g1, g2])</code>:
+<li> <code>jmoise.create_scheme(wp, [g1, g2])</code>:
creates new scheme based on specification wp and set g1 and g2 as responsible
groups.</li>
+<li> <code>jmoise.create_scheme(wp, [g1, g2], S)</code>:
+ creates new scheme based on specification wp and set g1 and g2 as responsible
+ groups. The identification of the new group will be unified with G.</li>
</ul>
@see jmoise.remove_scheme
Modified: trunk/applications/jason-moise/src/jmoise/link.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/link.java 2008-05-07 10:12:25 UTC (rev 1294)
+++ trunk/applications/jason-moise/src/jmoise/link.java 2008-05-07 15:59:20 UTC (rev 1295)
@@ -1,5 +1,6 @@
package jmoise;
+import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Atom;
@@ -37,7 +38,7 @@
@author Jomi
*/
-public class link extends MoiseBaseIA {
+public class link extends DefaultInternalAction {
private static Logger logger = Logger.getLogger(link.class.getName());
Modified: trunk/applications/jason-moise/src/jmoise/set_org_manager.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/set_org_manager.java 2008-05-07 10:12:25 UTC (rev 1294)
+++ trunk/applications/jason-moise/src/jmoise/set_org_manager.java 2008-05-07 15:59:20 UTC (rev 1295)
@@ -1,5 +1,6 @@
package jmoise;
+import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;
@@ -8,7 +9,7 @@
import java.util.logging.Logger;
/** Changes the name of the OrgManager agent, the default name is "orgManager" */
-public class set_org_manager extends MoiseBaseIA {
+public class set_org_manager extends DefaultInternalAction {
private static Logger logger = Logger.getLogger(set_org_manager.class.getName());
Modified: trunk/src/jason/asSyntax/Structure.java
===================================================================
--- trunk/src/jason/asSyntax/Structure.java 2008-05-07 10:12:25 UTC (rev 1294)
+++ trunk/src/jason/asSyntax/Structure.java 2008-05-07 15:59:20 UTC (rev 1295)
@@ -224,6 +224,10 @@
resetHashCodeCache();
}
+ public void delTerm(int index) {
+ terms.remove(index);
+ }
+
public void addTerms(Term ... ts ) {
for (Term t: ts) {
terms.add(t);
Modified: trunk/src/jason/stdlib/suspend.java
===================================================================
--- trunk/src/jason/stdlib/suspend.java 2008-05-07 10:12:25 UTC (rev 1294)
+++ trunk/src/jason/stdlib/suspend.java 2008-05-07 15:59:20 UTC (rev 1295)
@@ -85,9 +85,7 @@
Intention i = C.getSelectedIntention();
suspendIntention = true;
i.setSuspended(true);
- //i.peek().removeCurrentStep();
- C.getPendingIntentions().put(SELF_SUSPENDED_INT, i); //
-
+ C.getPendingIntentions().put(SELF_SUSPENDED_INT, i);
return true;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|