|
From: <jom...@us...> - 2008-05-07 21:24:48
|
Revision: 1296
http://jason.svn.sourceforge.net/jason/?rev=1296&view=rev
Author: jomifred
Date: 2008-05-07 14:24:45 -0700 (Wed, 07 May 2008)
Log Message:
-----------
update jason team for new version of IA of jason-moise
Modified Paths:
--------------
trunk/applications/jason-moise/lib/moise.jar
trunk/applications/jason-moise/src/jmoise/OrgAgent.java
trunk/applications/jason-team/src/asl/exploration.asl
trunk/applications/jason-team/src/asl/gaucho.asl
trunk/applications/jason-team/src/asl/goto.asl
trunk/applications/jason-team/src/asl/herding.asl
trunk/applications/jason-team/src/java/arch/LocalWorldModel.java
trunk/applications/jason-team/src/java/jia/direction.java
trunk/applications/jason-team/src/java/jia/herd_position.java
trunk/applications/jason-team/src/java/test/TestBasicHerding.java
trunk/src/jason/asSemantics/Agent.java
trunk/src/jason/asSemantics/Unifier.java
trunk/src/jason/asSyntax/Structure.java
Modified: trunk/applications/jason-moise/lib/moise.jar
===================================================================
(Binary files differ)
Modified: trunk/applications/jason-moise/src/jmoise/OrgAgent.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2008-05-07 15:59:20 UTC (rev 1295)
+++ trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2008-05-07 21:24:45 UTC (rev 1296)
@@ -92,6 +92,7 @@
public void checkMail() {
super.checkMail(); // get the messages from arch to circumstance
+
Circumstance C = getTS().getC();
Iterator<Message> i = C.getMailBox().iterator();
boolean updateGoalBels = false;
@@ -104,72 +105,52 @@
currentOE = (OE) m.getPropCont();
i.remove();
} else if (m.getSender().equals(getOrgManagerName())) {
+
// the content is a normal predicate
final String content = m.getPropCont().toString();
- final boolean isTell = m.getIlForce().equals("tell");
- final boolean isUntell = m.getIlForce().equals("untell");
- if (isTell && content.startsWith("scheme(")) {
- i.remove();
- addAsBel(content);
- //} else if (content.startsWith("update_goals")) {
- // // I need to generate AS Triggers like !<orggoal>
- // i.remove();
- // updateGoalBels = true;
- // updateGoalEvt = true;
- } else if (content.startsWith("goal_state")) {
- // the state of a scheme i belong to has changed
- i.remove();
- updateGoalBels(Pred.parsePred(content));
- updateGoalEvt = true;
- } else if (content.startsWith("scheme_group")) {
- i.remove();
- if (isTell) {
- // this message is generated when my group becomes
- // responsible for a scheme
- Literal l = addAsBel(content);
- generateObligationPermissionEvents(l);
- } else if (isUntell) {
- Literal l = delAsBel(content);
- removeObligationPermissionBeliefs(l, "obligation");
- removeObligationPermissionBeliefs(l, "permission");
- }
- } else if (isTell && content.startsWith("commitment")) {
- i.remove();
- addAsBel(content);
- // I need to generate AS Triggers like !<orggoal> since some scheme becomes well formed
- updateGoalEvt = true;
+
+ // test if it is the result of some org action
+ if (m.getInReplyTo() != null) {
+ // find the intention
+ Intention pi = C.getPendingIntentions().remove("om/"+m.getInReplyTo());
+ if (pi != null) {
+ i.remove();
+ resumeIntention(pi, content, C);
+ }
+ } else {
+ // add all tells directly in the memory
+ if (m.getIlForce().equals("tell")) {
+ i.remove();
+ if (content.startsWith("goal_state")) {
+ // the state of a scheme i belong to has changed
+ updateGoalBels( Pred.parsePred(content) );
+ updateGoalEvt = true;
+ } else {
+ Literal cl = addAsBel(content);
+
+ if (content.startsWith("scheme_group")) {
+ // this message is generated when my group becomes
+ // responsible for a scheme
+ generateObligationPermissionEvents(cl);
+ } else if (content.startsWith("commitment")) {
+ // I need to generate AS Triggers like !<orggoal> since some scheme becomes well formed
+ updateGoalEvt = true;
+ }
+ }
- } else if (m.getIlForce().equals("untell") && content.startsWith("scheme")) {
- 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());
- }
- }
- }
+ } else if ( m.getIlForce().equals("untell") ) {
+ i.remove();
+ Literal cl = delAsBel(content);
+
+ if (content.startsWith("scheme")) {
+ String schId = cl.getTerm(1).toString();
+ removeAchieveGoalsOfSch(schId);
+ removeBeliefs(schId);
+ } else if (content.startsWith("scheme_group")) {
+ removeObligationPermissionBeliefs(cl, "obligation");
+ removeObligationPermissionBeliefs(cl, "permission");
+ }
+ }
}
}
} catch (Exception e) {
@@ -184,7 +165,6 @@
} catch (Exception e) {
logger.log(Level.SEVERE, "Error!", e);
}
-
}
private Literal addAsBel(String b) throws RevisionFailedException {
@@ -199,6 +179,29 @@
getTS().getAg().delBel(l);
return l;
}
+
+ private void resumeIntention(Intention pi, String content, Circumstance C) {
+ 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());
+ }
+ }
+
+ }
private void generateObligationPermissionEvents(Pred m) throws RevisionFailedException {
// computes this agent obligations in the scheme
@@ -344,24 +347,25 @@
/** removes all bels related to a Scheme */
void removeBeliefs(String schId) throws RevisionFailedException {
Agent ag = getTS().getAg();
- ag.abolish(buildLiteralToCleanBB(schId, obligationLiteral, false), null);
- ag.abolish(buildLiteralToCleanBB(schId, permissionLiteral, false), null);
- ag.abolish(buildLiteralToCleanBB(schId, schemeGroupLiteral, false), null);
- ag.abolish(buildLiteralToCleanBB(schId, goalStateLiteral, false), null);
- ag.abolish(buildLiteralToCleanBB(schId, schPlayersLiteral, false), null);
- ag.abolish(buildLiteralToCleanBB(schId, commitmentLiteral, true), null);
+ Atom aSchId = new Atom(schId);
+ ag.abolish(buildLiteralToCleanBB(aSchId, obligationLiteral, false), null);
+ ag.abolish(buildLiteralToCleanBB(aSchId, permissionLiteral, false), null);
+ ag.abolish(buildLiteralToCleanBB(aSchId, schemeGroupLiteral, false), null);
+ ag.abolish(buildLiteralToCleanBB(aSchId, goalStateLiteral, false), null);
+ ag.abolish(buildLiteralToCleanBB(aSchId, schPlayersLiteral, false), null);
+ ag.abolish(buildLiteralToCleanBB(aSchId, commitmentLiteral, true), null);
}
- private Literal buildLiteralToCleanBB(String schId, PredicateIndicator pred, boolean schInEnd) {
+ private Literal buildLiteralToCleanBB(Atom aSchId, PredicateIndicator pred, boolean schInEnd) {
Literal l = new Literal(pred.getFunctor());
if (!schInEnd) {
- l.addTerm(new Atom(schId));
+ l.addTerm(aSchId);
}
for (int i=1;i<pred.getArity();i++) {
l.addTerm(new UnnamedVar());
}
if (schInEnd) {
- l.addTerm(new Atom(schId));
+ l.addTerm(aSchId);
}
return l;
}
Modified: trunk/applications/jason-team/src/asl/exploration.asl
===================================================================
--- trunk/applications/jason-team/src/asl/exploration.asl 2008-05-07 15:59:20 UTC (rev 1295)
+++ trunk/applications/jason-team/src/asl/exploration.asl 2008-05-07 21:24:45 UTC (rev 1296)
@@ -42,17 +42,17 @@
+!create_exploration_gr
<- .my_name(Me);
- // create the team
+ // create the team, if necessary
.if( Me == gaucho1 & not group(team,_) ) {
- jmoise.create_group(team)
+ jmoise.create_group(team)
};
-
- // wait the team creation
- ?group(team,TeamGroup);
-
- .if( not group(exploration_grp,_)[owner(Me)]) {
- jmoise.create_group(exploration_grp,TeamGroup);
- .wait("+group(exploration_grp,G)[owner(Me)]")
+
+ .if( not group(exploration_grp,_)[owner(Me)] ) {
+ ?group(team,TeamGroup); // get the team Id
+ jmoise.create_group(exploration_grp,TeamGroup,G);
+ .print("ooo Group ",G," created")
+ } {
+ ?group(exploration_grp,G)[owner(Me)]
};
.print("ooo Recruiting scouters for my explorer group ",G);
@@ -123,7 +123,7 @@
/* -- plans for the goals of role explorer -- */
-{ begin maintenance_goal("+pos(_,_,_)") }
+{ begin maintenance_goal("+at_target") }
+!goto_near_unvisited[scheme(Sch),mission(Mission)]
<- .print("ooo I should find the nearest unvisited location and go there!");
@@ -132,11 +132,11 @@
?group_area(_,GroupId, Area); // get the area of this group
?pos(MeX, MeY, _); // get my location
jia.near_least_visited(MeX, MeY, Area, TargetX, TargetY);
- -+target(TargetX, TargetY);
- .wait("+at_target",10000,_).
+ -+target(TargetX, TargetY).
/* added by the pattern
- .wait("+pos(_,_,_)"); // wait next cycle
+ .wait("+at_target").
+ //.wait("+pos(_,_,_)"); // wait next cycle
!!goto_near_unvisited[scheme(Sch),mission(Mission)]
*/
Modified: trunk/applications/jason-team/src/asl/gaucho.asl
===================================================================
--- trunk/applications/jason-team/src/asl/gaucho.asl 2008-05-07 15:59:20 UTC (rev 1295)
+++ trunk/applications/jason-team/src/asl/gaucho.asl 2008-05-07 21:24:45 UTC (rev 1296)
@@ -42,7 +42,7 @@
+?pos(X, Y, S) <- .wait("+pos(X,Y,S)").
+?group_area(Id,G,A) <- .wait("+group_area(Id,G,A)").
+?gsize(W,H) <- .wait("+gsize(W,H)").
-+?group(T,G) <- .wait("+group(T,G)").
++?group(team,G) <- .wait("+group(team,G)", 500, _); ?group(team,G).
+?ally_pos(Name,X,Y) : .my_name(Name) <- ?pos(X,Y,_).
+end_of_simulation(_Result)
@@ -77,8 +77,7 @@
+!remove_org
: .my_name(gaucho1)
<- .if( group(team,Old) ) {
- jmoise.remove_group(Old);
- .wait("-group(team,_)")
+ jmoise.remove_group(Old)
};
.for( scheme(_,SchId) ) {
@@ -109,8 +108,7 @@
// give up all missions
.while( commitment(Me,M,Sch) ) {
- jmoise.remove_mission(M,Sch);
- .wait("-commitment(Me,M,Sch)")
+ jmoise.remove_mission(M,Sch)
};
// if I play herder in another group, ...
@@ -122,12 +120,10 @@
// if I play any other role, give it up
.while( play(Me,R,OG) & OG \== GT) {
- jmoise.remove_role(R,OG);
- .wait("-play(Me,R,OG)")
+ jmoise.remove_role(R,OG)
};
- jmoise.adopt_role(NewRole,GT);
- .wait("+play(Me,NewRole,GT)").
+ jmoise.adopt_role(NewRole,GT).
//+!change_role(NewRole,GT)[source(S)]
// <- .print("ooo I cannot adopt the role ",NewRole," in group ",GT,", as asked by ",S).
Modified: trunk/applications/jason-team/src/asl/goto.asl
===================================================================
--- trunk/applications/jason-team/src/asl/goto.asl 2008-05-07 15:59:20 UTC (rev 1295)
+++ trunk/applications/jason-team/src/asl/goto.asl 2008-05-07 21:24:45 UTC (rev 1296)
@@ -24,18 +24,7 @@
-at_target;
!!move.
-//-target(_,_) // if I receive a message untell for my target, remove all target from BB
-// <- .abolish(target(_,_)).
-
-// I still do not know my location
-/*
+!move
- : not pos(_,_,_)
- <- .print("waiting my location....");
- .wait("+pos(_,_,_)");
- !move.
-*/
-+!move
: not target(_,_)
<- .print("waiting my target....");
.wait("+target(_,_)");
Modified: trunk/applications/jason-team/src/asl/herding.asl
===================================================================
--- trunk/applications/jason-team/src/asl/herding.asl 2008-05-07 15:59:20 UTC (rev 1295)
+++ trunk/applications/jason-team/src/asl/herding.asl 2008-05-07 21:24:45 UTC (rev 1296)
@@ -8,7 +8,7 @@
+cow(_,_,_)
: .my_name(Me) &
play(Me,explorer,_) &
- not .desire(create_herding_gr) // to avoid crating several groups
+ not .desire(create_herding_gr) // to avoid creating several groups
<- !create_herding_gr.
+!create_herding_gr
@@ -17,8 +17,7 @@
// create the new group
?group(team,TeamId);
- jmoise.create_group(herding_grp, TeamId);
- .wait("+group(herding_grp, HG)[owner(Me)]", 4000);
+ jmoise.create_group(herding_grp, TeamId, HG);
.print("ooo Group ",HG," created.");
// store the list of scouter in my group
@@ -26,7 +25,6 @@
.findall(Scouter,play(Scouter,scouter,EG),LScouters);
!change_role(herder,HG);
- //?play(Me,herder,FinalHerdingGroup);
// ask scouters to change role
.print("ooo Asking ",LScouters," to adopt the herdboy role in ",HG);
@@ -42,8 +40,8 @@
.broadcast(tell, group_leader(G,Me)).
// If I stop playing herder, destroy the herding groups I've created
--play(Ag,herder,_)
- : .my_name(Ag)
+-play(Me,herder,_)
+ : .my_name(Me)
<- .wait(4000);
.for( group(herding_grp,G)[owner(Me)] ) {
-group_leader(G,Me);
Modified: trunk/applications/jason-team/src/java/arch/LocalWorldModel.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-05-07 15:59:20 UTC (rev 1295)
+++ trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-05-07 21:24:45 UTC (rev 1296)
@@ -6,6 +6,7 @@
import jason.environment.grid.Location;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -145,26 +146,31 @@
m[c][l] += value;
}
- public Location nearFree(Location l) throws Exception {
+ // occupied means the places that can not be considered as nearFree
+ public Location nearFree(Location l, List<Location> occupied) throws Exception {
int w = 0;
+ Location newl;
+ if (occupied == null) occupied = Collections.emptyList();
List<Location> options = new ArrayList<Location>();
while (true) {
options.clear();
for (int y=l.y-w+1; y<l.y+w; y++) {
//System.out.println(" "+(l.x+w)+" "+y);
//System.out.println(" "+(l.x-w)+" "+y);
- if (isFree(l.x-w,y))
- options.add(new Location(l.x-w,y));
- if (isFree(l.x+w,y))
- options.add(new Location(l.x+w,y));
+ newl = new Location(l.x-w,y);
+ if (isFree(newl) && !occupied.contains(newl))
+ options.add(newl);
+ newl = new Location(l.x+w,y);
+ if (isFree(newl) && !occupied.contains(newl))
+ options.add(newl);
}
for (int x=l.x-w; x<=l.x+w;x++) {
- //System.out.println(" "+x+" "+(l.y-w));
- //System.out.println(" "+x+" "+(l.y+w));
- if (isFree(x,l.y-w))
- options.add(new Location(x,l.y-w));
- if (isFree(x,l.y+w))
- options.add(new Location(x,l.y+w));
+ newl = new Location(x,l.y-w);
+ if (isFree(newl) && !occupied.contains(newl))
+ options.add(newl);
+ newl = new Location(x,l.y+w);
+ if (isFree(newl) && !occupied.contains(newl))
+ options.add(newl);
}
//System.out.println(w + " " + options);
if (!options.isEmpty())
Modified: trunk/applications/jason-team/src/java/jia/direction.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/direction.java 2008-05-07 15:59:20 UTC (rev 1295)
+++ trunk/applications/jason-team/src/java/jia/direction.java 2008-05-07 21:24:45 UTC (rev 1296)
@@ -73,7 +73,7 @@
// if search is null, it is impossible in the scenario to goto n, set it as obstacle
ts.getLogger().info("[direction] No possible path to "+to+" setting as obstacle.");
model.add(WorldModel.OBSTACLE, to);
- to = model.nearFree(to);
+ to = model.nearFree(to, null);
s = new Search(model, from, to, ts.getUserAgArch());
}
Modified: trunk/applications/jason-team/src/java/jia/herd_position.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/herd_position.java 2008-05-07 15:59:20 UTC (rev 1295)
+++ trunk/applications/jason-team/src/java/jia/herd_position.java 2008-05-07 21:24:45 UTC (rev 1296)
@@ -130,7 +130,7 @@
}
}
if (r != null)
- r = model.nearFree(r);
+ r = model.nearFree(r, null);
return r;
}
@@ -182,8 +182,8 @@
//System.out.println(" = "+dist+" result "+l);
if (l != null) {
l = pathToNearCow(l, clusterLocs);
- if ( ! model.inGrid(l) || model.hasObject(WorldModel.OBSTACLE, l))
- l = model.nearFree(l);
+ if ( !model.inGrid(l) || model.hasObject(WorldModel.OBSTACLE, l) || r.contains(l))
+ l = model.nearFree(l, r);
r.add( l );
}
Modified: trunk/applications/jason-team/src/java/test/TestBasicHerding.java
===================================================================
--- trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-05-07 15:59:20 UTC (rev 1295)
+++ trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-05-07 21:24:45 UTC (rev 1296)
@@ -198,7 +198,7 @@
// add an agent in 4,38
model.add(WorldModel.AGENT, 4,38);
byIA = hp.getAgTarget(clusterLocs, Formation.six,cowboy.getLocation(model));
- assertEquals(null, byIA);
+ //assertEquals(null, byIA);
// add an agent in 5,37
//model.add(WorldModel.AGENT, 5,37);
@@ -222,7 +222,7 @@
assertEquals(new Location(11,49), byIA);
List<Location> form = hp.formationPlaces(clusterLocs, Formation.four);
- assertEquals("[6,48, 11,49, 6,48, 11,49]", form.toString());
+ assertEquals("[6,48, 11,49, 6,49, 12,48]", form.toString());
}
@Test
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2008-05-07 15:59:20 UTC (rev 1295)
+++ trunk/src/jason/asSemantics/Agent.java 2008-05-07 21:24:45 UTC (rev 1296)
@@ -648,14 +648,14 @@
*/
public void abolish(Literal bel, Unifier un) throws RevisionFailedException {
List<Literal> toDel = new ArrayList<Literal>();
-
+ if (un == null) un = new Unifier();
Iterator<Literal> il = getBB().getCandidateBeliefs(bel, un);
if (il != null) {
while (il.hasNext()) {
Literal inBB = il.next();
if (!inBB.isRule()) {
// need to clone unifier since it is changed in previous iteration
- Unifier unC = (un == null ? new Unifier() : un.copy());
+ Unifier unC = un.copy();
if (unC.unifiesNoUndo(bel, inBB)) {
toDel.add(inBB);
}
Modified: trunk/src/jason/asSemantics/Unifier.java
===================================================================
--- trunk/src/jason/asSemantics/Unifier.java 2008-05-07 15:59:20 UTC (rev 1295)
+++ trunk/src/jason/asSemantics/Unifier.java 2008-05-07 21:24:45 UTC (rev 1296)
@@ -335,8 +335,13 @@
function.put( (VarTerm)k.clone(), (Term)u.function.get(k).clone());
}
+ public Object clone() {
+ return copy();
+ }
+
+ /** same as clone but with typed return */
@SuppressWarnings("unchecked")
- public Object clone() {
+ public Unifier copy() {
try {
Unifier newUn = new Unifier();
newUn.function = (HashMap)function.clone();
@@ -348,11 +353,6 @@
}
}
- /** same as clone but with typed return */
- public Unifier copy() {
- return (Unifier)clone();
- }
-
public boolean equals(Object o) {
if (o == null) return false;
if (o == this) return true;
Modified: trunk/src/jason/asSyntax/Structure.java
===================================================================
--- trunk/src/jason/asSyntax/Structure.java 2008-05-07 15:59:20 UTC (rev 1295)
+++ trunk/src/jason/asSyntax/Structure.java 2008-05-07 21:24:45 UTC (rev 1296)
@@ -226,6 +226,8 @@
public void delTerm(int index) {
terms.remove(index);
+ predicateIndicatorCache = null;
+ resetHashCodeCache();
}
public void addTerms(Term ... ts ) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|