|
From: <jom...@us...> - 2008-04-26 14:12:33
|
Revision: 1264
http://jason.svn.sourceforge.net/jason/?rev=1264&view=rev
Author: jomifred
Date: 2008-04-26 07:12:31 -0700 (Sat, 26 Apr 2008)
Log Message:
-----------
jason team: add org. goals (with no code) in the code of the agents
Modified Paths:
--------------
trunk/applications/jason-moise/lib/moise.jar
trunk/applications/jason-moise/src/asl/moise-common.asl
trunk/applications/jason-moise/src/jmoise/OrgManager.java
trunk/applications/jason-team/src/asl/exploration.asl
trunk/applications/jason-team/src/asl/gaucho.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/herd_position.java
trunk/applications/jason-team/src/java/test/TestBasicHerding.java
trunk/applications/jason-team/src/team-os.xml
trunk/src/jason/asSyntax/VarTerm.java
trunk/src/jason/environment/grid/Location.java
trunk/src/test/VarTermTest.java
Added Paths:
-----------
trunk/applications/jason-team/src/java/jia/near_least_visited.java
Modified: trunk/applications/jason-moise/lib/moise.jar
===================================================================
(Binary files differ)
Modified: trunk/applications/jason-moise/src/asl/moise-common.asl
===================================================================
--- trunk/applications/jason-moise/src/asl/moise-common.asl 2008-04-26 11:54:31 UTC (rev 1263)
+++ trunk/applications/jason-moise/src/asl/moise-common.asl 2008-04-26 14:12:31 UTC (rev 1264)
@@ -51,6 +51,6 @@
// if some scheme is finished, drop all intentions related to it.
-scheme(_Spec,Id)
- <- .drop_desire(X[scheme(Id)]).
+ <- .drop_desire(_[scheme(Id)]).
+error(M)[source(orgManager)] <- .print("Error in organisational action: ",M); -error(M)[source(orgManager)].
Modified: trunk/applications/jason-moise/src/jmoise/OrgManager.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/OrgManager.java 2008-04-26 11:54:31 UTC (rev 1263)
+++ trunk/applications/jason-moise/src/jmoise/OrgManager.java 2008-04-26 14:12:31 UTC (rev 1264)
@@ -103,6 +103,7 @@
addCommand(new SetGoalState());
addCommand(new SetGoalArg());
addCommand(new RemoveScheme());
+ addCommand(new AbortScheme());
addCommand(new AddAgent());
}
@@ -428,13 +429,24 @@
sendReply(sender, mId, "error(\"you are not the owner of the scheme " + schId + ", so you can not change it\")");
}
- currentOE.finishScheme(sch);
-
+ act(currentOE, sch);
// send untell to agents
updateMembersOE(currentOE.getAgents(), "scheme(" + sch.getSpec().getId() + "," + sch.getId() + ")[owner(" + sch.getOwner() + ")]", false, false);
}
+ protected void act(OE currentOE, SchemeInstance sch) throws MoiseException {
+ currentOE.finishScheme(sch);
+ }
}
+ class AbortScheme extends RemoveScheme {
+ public String getId() {
+ return "abort_scheme";
+ }
+ protected void act(OE currentOE, SchemeInstance sch) throws MoiseException {
+ currentOE.abortScheme(sch);
+ }
+ }
+
class SetGoalState implements OrgManagerCommand {
public String getId() {
return "set_goal_state";
Modified: trunk/applications/jason-team/src/asl/exploration.asl
===================================================================
--- trunk/applications/jason-team/src/asl/exploration.asl 2008-04-26 11:54:31 UTC (rev 1263)
+++ trunk/applications/jason-team/src/asl/exploration.asl 2008-04-26 14:12:31 UTC (rev 1264)
@@ -1,5 +1,13 @@
/* -- plans for exploration phase -- */
+
+/* -- initial beliefs -- */
+
+// missions I can commit to
+desired_mission(exploring, mexplorer).
+desired_mission(exploring, mscouter).
+
+
/* -- initial goals -- */
//!test.
@@ -34,8 +42,9 @@
X = math.round(((W*H)/3)/H);
+group_area(0, G1, area(0, 0, X, H-1));
+group_area(1, G2, area(X+1, 0, W-1, H/2));
- +group_area(2, G3, area(X+1, (H/2)+1, W-1, H-1)).
+ +group_area(2, G3, area(X+1, (H/2)+1, W-1, H-1)).
+
+group_area(ID,G,A)[source(self)]
<- .broadcast(tell, group_area(ID,G,A)).
@@ -81,8 +90,55 @@
<- .print("ooo find_scouter failure, try another agent.");
!find_scouter(LSOdd,GId).
+// If if start playing explorer in a group that has no scheme, create the scheme
++play(Ag,explorer,G)
+ : .my_name(Ag) &
+ not scheme_group(_,G)
+ <- jmoise.create_scheme(exploring, [G]).
+
-/* plans for agents the others */
+/* plans for the others */
-+!play_role(Role,Group)
- <- jmoise.adopt_role(Role,Group).
++!play_role(Role,Group)[source(Ag)]
+ <- .print("ooo Adopting role ",Role,", asked by ",Ag);
+ jmoise.adopt_role(Role,Group).
+
+
+/* -- plans for the goals of role explorer -- */
+
+// TODO: make a pattern for organisational maintainance goal
+
++!goto_near_unvisited[scheme(Sch)]
+ <- .print("ooo I should find the near unvisited location and go there!");
+ .my_name(Me);
+ ?play(Me,explorer,GroupId); // get the group where I play explorer
+ ?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("+pos(_,_,_)"); // wait next cycle
+ !!goto_near_unvisited[scheme(Sch)].
+
+-!goto_near_unvisited[scheme(Sch)]
+ <- .current_intention(I);
+ .print("ooo Failure to goto_near_unvisited ",I);
+ .wait("+pos(_,_,_)"); // wait next cycle
+ !!goto_near_unvisited[scheme(Sch)].
+
+
+/* -- plans for the goals of role scouter -- */
+
++!follow_leader[scheme(Sch)]
+ <- .print("ooo I should follow the leader!");
+ // TODO:
+ .wait("+pos(_,_,_)"); // wait next cycle
+ !!follow_leader[scheme(Sch)].
+
+/* -- plans for the goals of all roles -- */
+
++!share_cows[scheme(Sch)]
+ <- .print("ooo I should share cows!");
+ // TODO:
+ .wait("+pos(_,_,_)"); // wait next cycle
+ !!share_cows[scheme(Sch)].
+
Modified: trunk/applications/jason-team/src/asl/gaucho.asl
===================================================================
--- trunk/applications/jason-team/src/asl/gaucho.asl 2008-04-26 11:54:31 UTC (rev 1263)
+++ trunk/applications/jason-team/src/asl/gaucho.asl 2008-04-26 14:12:31 UTC (rev 1264)
@@ -32,9 +32,6 @@
/* -- plans -- */
-+pos(_,_,_) <- do(skip).
-
-
+?pos(X, Y, S) <- .wait("+pos(X,Y,S)").
+?group_area(Id,G,A) <- .wait("+group_area(Id,G,A)").
Modified: trunk/applications/jason-team/src/asl/herding.asl
===================================================================
--- trunk/applications/jason-team/src/asl/herding.asl 2008-04-26 11:54:31 UTC (rev 1263)
+++ trunk/applications/jason-team/src/asl/herding.asl 2008-04-26 14:12:31 UTC (rev 1264)
@@ -1 +1,35 @@
/* -- plans for herding phase -- */
+
+/* -- initial beliefs -- */
+
+// missions I can commit to
+desired_mission(exploring, mherder).
+desired_mission(exploring, mherdboy).
+
+
+/* -- plans for the goals of role herder -- */
+
++!recruit[scheme(Sch)]
+ <- .print("ooo I should revise the size of the cluster and recruit!");
+ // TODO
+ .wait("+pos(_,_,_)"); // wait next cycle
+ !!recruit[scheme(Sch)].
+
+
++!define_formation[scheme(Sch)]
+ <- .print("ooo I should define the formation of my group!");
+ jia.herd_position(2,L); // formation in two (TODO: get the number of players in the group or scheme)
+ .print("ooo formation is ",L);
+ // TODO: allocate and share the formation
+ .wait("+pos(_,_,_)"); // wait next cycle
+ !!define_formation[scheme(Sch)].
+
+
+/* -- plans for the goals of all roles (herder and herdboy) -- */
+
++!be_in_formation[scheme(Sch)]
+ <- .print("ooo I should be in formation!");
+ // TODO
+ .wait("+pos(_,_,_)"); // wait next cycle
+ !!be_in_formation[scheme(Sch)].
+
Modified: trunk/applications/jason-team/src/java/arch/LocalWorldModel.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-04-26 11:54:31 UTC (rev 1263)
+++ trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-04-26 14:12:31 UTC (rev 1264)
@@ -185,10 +185,7 @@
}
/** returns the near location of x,y that was least visited */
- public Location getNearLeastVisited(int agx, int agy) {
- //int distanceToBorder = (agx < getWidth()/2 ? agx : getWidth() - agx) - 1;
- Location agloc = new Location(agx,agy);
-
+ public Location getNearLeastVisited(Location agloc, Location tr, Location bl) {
/*
logger.info("------");
for (int i = 0; i < getWidth(); i++) {
@@ -203,8 +200,8 @@
//int visitedTarget = 0;
while (true) {
- int x = agx;
- int y = agy;
+ int x = agloc.x;
+ int y = agloc.y;
int w = 1;
int dx = 0;
int dy = 0;
@@ -217,13 +214,13 @@
dx++;
break;
} else {
- stage = 2;//(x % 2 == 0) ? 2 : 3;
+ stage = 2;
}
case 2: if (dy < w) {
dy++;
break;
} else {
- stage = 3;//(x % 2 == 0) ? 3 : 1;
+ stage = 3;
}
case 3: if (dx > 0) {
dx--;
@@ -243,7 +240,7 @@
}
Location l = new Location(x+dx,y+dy);
- if (isFree(l) && !l.equals(agloc)) {
+ if (isFree(l) && !l.equals(agloc) && l.isInArea(tr, bl)) {
if (visited[l.x][l.y] < minVisited) { // a place better then minVisited! go there
return l;
} if (visited[l.x][l.y] == minVisited) { // a place in the minVisited level
Modified: trunk/applications/jason-team/src/java/jia/herd_position.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-26 11:54:31 UTC (rev 1263)
+++ trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-26 14:12:31 UTC (rev 1264)
@@ -3,7 +3,11 @@
import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.NumberTerm;
import jason.asSyntax.NumberTermImpl;
+import jason.asSyntax.Structure;
import jason.asSyntax.Term;
import jason.environment.grid.Location;
@@ -18,6 +22,11 @@
/**
* Gives a good location to herd cows
+ *
+ * the first argument is the formation id (one, two, ... 1, 2, ....)
+ *
+ * if it is called with 3 args, returns the a free location in the formation
+ * otherwise return a list of location for the formation
*
* @author jomi
*/
@@ -26,32 +35,62 @@
public static final double maxStdDev = 3;
public enum Formation {
- one { int[] getDistances() { return new int[] { 0 }; } },
- six { int[] getDistances() { return new int[] { 2, -2, 6, -6, 10, -10 }; } };
+ one { int[] getDistances() { return new int[] { 0 }; } },
+ two { int[] getDistances() { return new int[] { 2, -2 }; } },
+ three { int[] getDistances() { return new int[] { 0, 4, -4 }; } },
+ four { int[] getDistances() { return new int[] { 2, -2, 6, -6 }; } },
+ five { int[] getDistances() { return new int[] { 0, 4, -4, 8, -8 }; } },
+ six { int[] getDistances() { return new int[] { 2, -2, 6, -6, 10, -10 }; } };
abstract int[] getDistances();
};
@Override
- public Object execute(TransitionSystem ts, Unifier un, Term[] terms) throws Exception {
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
CowboyArch arch = (CowboyArch)ts.getUserAgArch();
LocalWorldModel model = arch.getModel();
if (model == null)
return false;
-
Location agLoc = model.getAgPos(arch.getMyId());
+ // identify the formation id
+ Formation formation = Formation.six;
+ if (args[0].isNumeric()) {
+ int index = (int)((NumberTerm)args[0]).solve();
+ formation = Formation.values()[ index-1 ];
+ } else {
+ formation = Formation.valueOf(args[0].toString());
+ }
+
// update GUI
if (arch.hasGUI())
- setFormationLoc(model, Formation.valueOf(terms[0].toString()));
+ setFormationLoc(model, formation);
- Location agTarget = getAgTarget(model, Formation.valueOf(terms[0].toString()), agLoc);
- if (agTarget != null) {
- agTarget = nearFreeForAg(model, agLoc, agTarget);
- return un.unifies(terms[1], new NumberTermImpl(agTarget.x)) &&
- un.unifies(terms[2], new NumberTermImpl(agTarget.y));
+ // if the return is a location for one agent
+ if (args.length == 3) {
+ Location agTarget = getAgTarget(model, formation, agLoc);
+ if (agTarget != null) {
+ return un.unifies(args[1], new NumberTermImpl(agTarget.x)) &&
+ un.unifies(args[2], new NumberTermImpl(agTarget.y));
+ } else {
+ ts.getLogger().info("No target! I am at "+agLoc+" places are "+formationPlaces(model, formation));
+ }
} else {
- ts.getLogger().info("No target! I am at "+agLoc+" places are "+formationPlaces(model, Formation.valueOf(terms[0].toString())));
+ // return all the locations for the formation
+ List<Location> locs = formationPlaces(model, formation);
+ if (locs != null) {
+ ListTerm r = new ListTermImpl();
+ ListTerm tail = r;
+ for (Location l: locs) {
+ Structure p = new Structure("pos",2);
+ p.addTerm(new NumberTermImpl(l.x));
+ p.addTerm(new NumberTermImpl(l.y));
+ tail = tail.append(p);
+ }
+ return un.unifies(args[1], r);
+ } else {
+ ts.getLogger().info("No formation possible! I am at "+agLoc+" places are "+formationPlaces(model, formation));
+ }
}
} catch (Throwable e) {
ts.getLogger().log(Level.SEVERE, "herd_position error: "+e, e);
@@ -66,11 +105,13 @@
for (Location l : locs) {
r = l;
if (ag.equals(l) || // I am there
- model.countObjInArea(WorldModel.AGENT, l, 1) == 0) { // no one else is there
+ !model.hasObject(WorldModel.AGENT, l)) { // no one else is there
break;
}
}
}
+ if (r != null)
+ r = model.nearFree(r);
return r;
}
@@ -125,7 +166,7 @@
for (int agTargetSize = initAgTS; agTargetSize <= Math.abs(dist); agTargetSize++) {
l = agTarget.newMagnitude(agTargetSize).add(mean).add(agsTarget).getLocation(model);
//System.out.println("pos angle "+agTargetSize);
- uselast = !model.inGrid(l) || model.hasObject(WorldModel.OBSTACLE, l) && lastloc != null;
+ uselast = (!model.inGrid(l) || model.hasObject(WorldModel.OBSTACLE, l)) && lastloc != null;
if (uselast) {
r.add(pathToNearCow(model, lastloc));
break;
@@ -160,8 +201,8 @@
return t;
}
+ /*
public Location nearFreeForAg(LocalWorldModel model, Location ag, Location t) throws Exception {
- /*
// run A* to get the path from ag to t
if (! model.inGrid(t))
t = model.nearFree(t);
@@ -179,8 +220,8 @@
if (i++ > 3) // do not go to far from target
break;
}
- */
return model.nearFree(t);
}
+ */
}
Added: trunk/applications/jason-team/src/java/jia/near_least_visited.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/near_least_visited.java (rev 0)
+++ trunk/applications/jason-team/src/java/jia/near_least_visited.java 2008-04-26 14:12:31 UTC (rev 1264)
@@ -0,0 +1,59 @@
+package jia;
+
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.NumberTerm;
+import jason.asSyntax.NumberTermImpl;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+import jason.environment.grid.Location;
+
+import java.util.logging.Level;
+
+import arch.CowboyArch;
+import arch.LocalWorldModel;
+
+/**
+ * Gets the near least visited location for a location (args 0 and 1) inside an area (arg 2).
+ *
+ * Example: jia.near_least_visited(10,10,area(0,0,20,30),X,Y).
+ *
+ * Its is based on the agent's model of the world.
+ *
+ * @author jomi
+ */
+public class near_least_visited extends DefaultInternalAction {
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ try {
+ LocalWorldModel model = ((CowboyArch)ts.getUserAgArch()).getModel();
+ if (model == null) {
+ ts.getLogger().log(Level.SEVERE, "no model to get near_least_visited!");
+ } else {
+ int agx = (int)((NumberTerm)args[0]).solve();
+ int agy = (int)((NumberTerm)args[1]).solve();
+ Location ag = new Location(agx, agy);
+
+ Structure sarea = (Structure)args[2];
+ int ax1 = (int)((NumberTerm)sarea.getTerm(0)).solve();
+ int ay1 = (int)((NumberTerm)sarea.getTerm(1)).solve();
+ int ax2 = (int)((NumberTerm)sarea.getTerm(2)).solve();
+ int ay2 = (int)((NumberTerm)sarea.getTerm(3)).solve();
+
+ Location tr = new Location(ax1, ay1);
+ Location bl = new Location(ax2, ay2);
+
+ Location n = model.getNearLeastVisited(ag, tr, bl);
+ un.unifies(args[3], new NumberTermImpl(n.x));
+ un.unifies(args[4], new NumberTermImpl(n.y));
+ //ts.getLogger().info("at "+agx+","+agy+" to "+n.x+","+n.y);
+ return true;
+ }
+ } catch (Throwable e) {
+ ts.getLogger().log(Level.SEVERE, "near_least_visited error: "+e, e);
+ }
+ return false;
+ }
+}
Modified: trunk/applications/jason-team/src/java/test/TestBasicHerding.java
===================================================================
--- trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-04-26 11:54:31 UTC (rev 1263)
+++ trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-04-26 14:12:31 UTC (rev 1264)
@@ -170,7 +170,6 @@
scenario2();
model.add(WorldModel.ENEMY, 11,48);
Location byIA = new herd_position().getAgTarget(model, Formation.one, cowboy.getLocation(model));
- byIA = new herd_position().nearFreeForAg(model, new Location(11,46), byIA);
assertEquals(new Location(11,49), byIA);
}
Modified: trunk/applications/jason-team/src/team-os.xml
===================================================================
--- trunk/applications/jason-team/src/team-os.xml 2008-04-26 11:54:31 UTC (rev 1263)
+++ trunk/applications/jason-team/src/team-os.xml 2008-04-26 14:12:31 UTC (rev 1264)
@@ -107,8 +107,8 @@
</functional-specification>
<deontic-specification>
- <deontic-relation type="obligation" role="explorer" mission="mscouter" />
- <deontic-relation type="obligation" role="scouter" mission="mexplorer" />
+ <deontic-relation type="obligation" role="explorer" mission="mexplorer" />
+ <deontic-relation type="obligation" role="scouter" mission="mscouter" />
<deontic-relation type="obligation" role="herder" mission="mherder" />
<deontic-relation type="obligation" role="herdboy" mission="mherdboy" />
</deontic-specification>
Modified: trunk/src/jason/asSyntax/VarTerm.java
===================================================================
--- trunk/src/jason/asSyntax/VarTerm.java 2008-04-26 11:54:31 UTC (rev 1263)
+++ trunk/src/jason/asSyntax/VarTerm.java 2008-04-26 14:12:31 UTC (rev 1264)
@@ -368,9 +368,12 @@
@Override
public void countVars(Map<VarTerm, Integer> c) {
- if (isVar()) {
- int n = c.containsKey(this) ? c.get(this) : 0;
- c.put(this, n+1);
+ if (value == null) {
+ int n = c.containsKey(this) ? c.get(this) : 0;
+ c.put(this, n+1);
+ super.countVars(c);
+ } else {
+ value.countVars(c);
}
}
Modified: trunk/src/jason/environment/grid/Location.java
===================================================================
--- trunk/src/jason/environment/grid/Location.java 2008-04-26 11:54:31 UTC (rev 1263)
+++ trunk/src/jason/environment/grid/Location.java 2008-04-26 14:12:31 UTC (rev 1264)
@@ -23,7 +23,10 @@
return Math.max( Math.abs(this.x - l.x) , Math.abs(this.y - l.y));
}
- public boolean isNeigbour(Location l) {
+ public boolean isInArea(Location tr, Location bl) {
+ return x >= tr.x && x <= bl.x && y >= tr.y && y <= bl.y;
+ }
+ public boolean isNeigbour(Location l) {
return
distance(l) == 1 ||
equals(l) ||
Modified: trunk/src/test/VarTermTest.java
===================================================================
--- trunk/src/test/VarTermTest.java 2008-04-26 11:54:31 UTC (rev 1263)
+++ trunk/src/test/VarTermTest.java 2008-04-26 14:12:31 UTC (rev 1264)
@@ -23,7 +23,9 @@
import jason.infra.centralised.CentralisedAgArch;
import java.io.StringReader;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import junit.framework.TestCase;
@@ -443,6 +445,13 @@
assertFalse(v.isGround());
}
+ public void testUnamedVarAnnots() {
+ Term t = DefaultTerm.parse("_[scheme(Id)]");
+ Map<VarTerm,Integer> c = new HashMap<VarTerm, Integer>();
+ t.countVars(c);
+ assertEquals(1,c.get(new VarTerm("Id")).intValue());
+ }
+
public void testUnifClone() {
VarTerm x1 = new VarTerm("X");
VarTerm x2 = new VarTerm("X");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|