|
From: <jom...@us...> - 2008-05-06 22:06:59
|
Revision: 1292
http://jason.svn.sourceforge.net/jason/?rev=1292&view=rev
Author: jomifred
Date: 2008-05-06 15:06:56 -0700 (Tue, 06 May 2008)
Log Message:
-----------
jason team: merge of herding team (does not work correctly yet)
Modified Paths:
--------------
trunk/applications/jason-team/AC-Local-JasonTeam.mas2j
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/ACProxy.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/environment/grid/GridWorldView.java
Modified: trunk/applications/jason-team/AC-Local-JasonTeam.mas2j
===================================================================
--- trunk/applications/jason-team/AC-Local-JasonTeam.mas2j 2008-05-05 18:33:43 UTC (rev 1291)
+++ trunk/applications/jason-team/AC-Local-JasonTeam.mas2j 2008-05-06 22:06:56 UTC (rev 1292)
@@ -18,32 +18,44 @@
host="localhost", port=12300, username=participant1, password="1"]
agentArchClass arch.ACArchitecture
agentClass agent.SelectEvent
- beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","ally_pos(key,_,_)","corral(_,_,_,_)", "target(_,_)");
+ beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","ally_pos(key,_,_)","corral(_,_,_,_)",
+ "target(_,_)", "group_leader(key,_)", "cow(key,_,_)",
+ "group_area(key, _, _)");
gaucho2 gaucho.asl
[verbose=1,host="localhost", port=12300, username=participant2, password="2"]
agentArchClass arch.ACArchitecture
agentClass agent.SelectEvent
- beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","ally_pos(key,_,_)","corral(_,_,_,_)", "target(_,_)");
+ beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","ally_pos(key,_,_)","corral(_,_,_,_)",
+ "target(_,_)", "group_leader(key,_)", "cow(key,_,_)",
+ "group_area(key, _, _)");
gaucho3 gaucho.asl
[verbose=1,host="localhost", port=12300, username=participant3, password="3"]
agentArchClass arch.ACArchitecture
agentClass agent.SelectEvent
- beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","ally_pos(key,_,_)","corral(_,_,_,_)", "target(_,_)");
+ beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","ally_pos(key,_,_)","corral(_,_,_,_)",
+ "target(_,_)", "group_leader(key,_)", "cow(key,_,_)",
+ "group_area(key, _, _)");
gaucho4 gaucho.asl
[verbose=1,host="localhost", port=12300, username=participant4, password="4"]
agentArchClass arch.ACArchitecture
agentClass agent.SelectEvent
- beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","ally_pos(key,_,_)","corral(_,_,_,_)", "target(_,_)");
+ beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","ally_pos(key,_,_)","corral(_,_,_,_)",
+ "target(_,_)", "group_leader(key,_)", "cow(key,_,_)",
+ "group_area(key, _, _)");
gaucho5 gaucho.asl
[verbose=1,host="localhost", port=12300, username=participant5, password="5"]
agentArchClass arch.ACArchitecture
agentClass agent.SelectEvent
- beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","ally_pos(key,_,_)","corral(_,_,_,_)", "target(_,_)");
+ beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","ally_pos(key,_,_)","corral(_,_,_,_)",
+ "target(_,_)", "group_leader(key,_)", "cow(key,_,_)",
+ "group_area(key, _, _)");
gaucho6 gaucho.asl
[verbose=1,host="localhost", port=12300, username=participant6, password="6"]
agentArchClass arch.ACArchitecture
agentClass agent.SelectEvent
- beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","ally_pos(key,_,_)","corral(_,_,_,_)", "target(_,_)");
+ beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","ally_pos(key,_,_)","corral(_,_,_,_)",
+ "target(_,_)", "group_leader(key,_)", "cow(key,_,_)",
+ "group_area(key, _, _)");
directives: maintenance_goal = agent.OrgMaintenanceGoal;
Modified: trunk/applications/jason-team/src/asl/exploration.asl
===================================================================
--- trunk/applications/jason-team/src/asl/exploration.asl 2008-05-05 18:33:43 UTC (rev 1291)
+++ trunk/applications/jason-team/src/asl/exploration.asl 2008-05-06 22:06:56 UTC (rev 1292)
@@ -5,7 +5,7 @@
/* -- initial goals -- */
-!create_team_group.
+//!create_team_group.
/*
-- plans for new match
@@ -15,48 +15,49 @@
/* plans for the team's groups creation */
+/*
+!create_team_group
: .my_name(gaucho1)
<- .print("oooo creating new team group ------------------------------------------------- ");
!remove_org;
jmoise.create_group(team).
+!create_team_group.
+*/
-+group(team,GId) // agent 1 is responsible for the creation of exploration groups
+/*+group(team,GId) // agent 1 is responsible for the creation of exploration groups
: .my_name(gaucho1)
<- jmoise.create_group(exploration_grp,GId);
jmoise.create_group(exploration_grp,GId);
- jmoise.create_group(exploration_grp,GId).
-+group(exploration_grp,_) // compute the area of the groups
- : .my_name(gaucho1) &
- group(team,TeamId) &
- .findall(GId, group(exploration_grp,GId)[super_gr(TeamId)], LG) &
- LG = [G1,G2,G3] // there are three groups
- <- ?gsize(W,H);
- 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)).
+ jmoise.create_group(exploration_grp,GId). */
+
-
-+group_area(ID,G,A)[source(self)]
- <- .broadcast(tell, group_area(ID,G,A)).
-
-
/* plans for agents with odd id */
+gsize(_,_) // new match has started
: .my_name(Me) &
agent_id(Me,AgId) &
AgId mod 2 == 1 // I have an odd Id
- <- //.if( .my_name(gaucho1) ) {
- // !create_team_group
- //};
+ <- !create_exploration_gr.
- .print("ooo Recruiting scouters for my explorer group....");
++!create_exploration_gr
+ <- .my_name(Me);
+
+ // create the team
+ .if( Me == gaucho1 & not 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)]")
+ };
+
+ .print("ooo Recruiting scouters for my explorer group ",G);
- // wait my pos
- ?pos(MyX,MyY,_);
+ ?pos(MyX,MyY,_); // wait my pos
// wait others pos
.while( .count(ally_pos(_,_,_), N) & N < 5 ) {
@@ -71,8 +72,8 @@
.sort(LOdd, LSOdd);
// test if I received the area of my group
- ?group_area(AgId div 2,G,A);
- .print("ooo Scouters candidates =", LSOdd," in area ",group_area(AgId div 2,G,A));
+ ?group_area(AreaId,G,A);
+ .print("ooo Scouters candidates =", LSOdd," in area ",group_area(AreaId,G,A));
// adopt role explorer in the group
jmoise.adopt_role(explorer,G);
@@ -94,7 +95,31 @@
not scheme_group(_,G)
<- jmoise.create_scheme(explore_sch, [G]).
+// If I stop playing explorer, destroy the explore groups I've created
+-play(Ag,explorer,_)
+ : .my_name(Ag)
+ <- .wait(4000);
+ .for( group(exploration_grp,G)[owner(Me)] ) {
+ jmoise.remove_group(G);
+ .wait(4000)
+ }.
+
++group(exploration_grp,_) // compute the area of the groups
+ : .my_name(gaucho1) &
+ group(team,TeamId) &
+ .findall(GId, group(exploration_grp,GId)[super_gr(TeamId)], LG) &
+ LG = [G1,G2,G3] // there are three groups
+ <- ?gsize(W,H);
+ 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(ID,G,A)[source(self)]
+ <- .broadcast(tell, group_area(ID,G,A)).
+
+
/* -- plans for the goals of role explorer -- */
{ begin maintenance_goal("+pos(_,_,_)") }
Modified: trunk/applications/jason-team/src/asl/gaucho.asl
===================================================================
--- trunk/applications/jason-team/src/asl/gaucho.asl 2008-05-05 18:33:43 UTC (rev 1291)
+++ trunk/applications/jason-team/src/asl/gaucho.asl 2008-05-06 22:06:56 UTC (rev 1292)
@@ -42,20 +42,20 @@
+?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)").
+?ally_pos(Name,X,Y) : .my_name(Name) <- ?pos(X,Y,_).
+end_of_simulation(_Result)
- <- .abolish(group_area(_,_,_));
+ <- -end_of_simulation(_);
+ .drop_all_desires;
!remove_org.
-+!restart.
-
-/* <- .print("*** restart ***").
++!restart
+ <- //.print("*** restart ***");
//.drop_all_desires;
- //.abolish(target(_,_)).
+ .abolish(cow(_,_,_)).
// TODO: what to do?
//!decide_target.
-*/
/* -- plans for the goals of all roles -- */
@@ -77,7 +77,8 @@
+!remove_org
: .my_name(gaucho1)
<- .if( group(team,Old) ) {
- jmoise.remove_group(Old)
+ jmoise.remove_group(Old);
+ .wait("-group(team,_)")
};
.for( scheme(_,SchId)) {
@@ -98,6 +99,43 @@
?play(Me,R,Gid);
.findall(P, play(P,_,Gid), G).
+
++!change_role(R,G)
+ : .my_name(Me) & play(Me, R,G).
+
++!change_role(NewRole,GT)[source(S)]
+ : not .desire(change_role(_,_)) // to not trigger two change of role
+ <- .my_name(Me);
+ .print("ooo Adopting the role ",NewRole," in group ",GT,", as asked by ",S);
+
+ // give up all missions
+ .while( commitment(Me,M,Sch) ) {
+ jmoise.remove_mission(M,Sch);
+ .wait("-commitment(Me,M,Sch)")
+ };
+
+ // if I play herder in another group, ...
+ .if( play(Me,herder,G) & G \== GT) {
+ // ask all herdboys to also change the group
+ ?my_group_players(HerdBoys, herder);
+ .send(HerdBoys, achieve, change_role(herdboy,GT))
+ };
+
+ // 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.adopt_role(NewRole,GT);
+ .wait("+play(Me,NewRole,GT)").
+
++!change_role(NewRole,GT)[source(S)]
+ <- .print("ooo I cannot adopt the role ",NewRole," in group ",GT,", as asked by ",S).
+
+
++!play_role(Role,Group)
+ : .my_name(Me) & play(Me,R,G).
+!play_role(Role,Group)[source(Ag)]
<- .print("ooo Adopting role ",Role," in group ",Group,", asked by ",Ag);
jmoise.adopt_role(Role, Group).
Modified: trunk/applications/jason-team/src/asl/herding.asl
===================================================================
--- trunk/applications/jason-team/src/asl/herding.asl 2008-05-05 18:33:43 UTC (rev 1291)
+++ trunk/applications/jason-team/src/asl/herding.asl 2008-05-06 22:06:56 UTC (rev 1292)
@@ -5,7 +5,6 @@
/* -- plans for herding groups creation -- */
// if see cow and is not herding, create the herding group and change roles
-@lcs[atomic]
+cow(_,_,_)
: .my_name(Me) &
play(Me,explorer,_) &
@@ -20,44 +19,38 @@
?group(team,TeamId);
jmoise.create_group(herding_grp, TeamId);
.wait("+group(herding_grp, HG)[owner(Me)]", 4000);
+ .print("ooo Group ",HG," created.");
// store the list of scouter in my group
?play(Me,explorer,EG);
.findall(Scouter,play(Scouter,scouter,EG),LScouters);
!change_role(herder,HG);
+ .wait("+play(Me,herder,FinalHerdingGroup)");
// ask scouters to change role
- .print("ooo Asking ",LScouters," to adopt the herdboy role");
- .send(LScouters,achieve,change_role(herdboy,HG)).
-
-
-+!change_role(herder,HG)
- <- .my_name(Me);
- .if (commitment(Me,explore,Sch)) {
- jmoise.remove_mission(explore,Sch)
- };
- .if (play(Me,explorer,EG)) {
- jmoise.remove_role(explorer,EG)
- };
- jmoise.adopt_role(herder,HG).
+ .print("ooo Asking ",LScouters," to adopt the herdboy role in ",FinalHerdingGroup);
+ .send(LScouters,achieve,change_role(herdboy,FinalHerdingGroup)).
-+!change_role(herdboy,HG)
- <- .my_name(Me);
- .if (commitment(Me,scout,Sch)) {
- jmoise.remove_mission(scout,Sch)
- };
- .if (play(Me,scouter,EG)) {
- jmoise.remove_role(scouter,EG)
- };
- jmoise.adopt_role(herdboy,HG).
-
// If if start playing explorer in a group that has no scheme, create the scheme
-+play(Ag,herder,G)
- : .my_name(Ag) &
++play(Me,herder,G)
+ : .my_name(Me) &
not scheme_group(_,G)
- <- jmoise.create_scheme(herd_sch, [G]).
+ <- jmoise.create_scheme(herd_sch, [G]);
+ +group_leader(G,Me);
+ .broadcast(tell, group_leader(G,Me)).
+
+// If I stop playing herder, destroy the herding groups I've created
+-play(Ag,herder,_)
+ : .my_name(Ag)
+ <- .wait(4000);
+ .for( group(herding_grp,G)[owner(Me)] ) {
+ -group_leader(G,Me);
+ .broadcast(untell, group_leader(G,Me));
+ jmoise.remove_group(G);
+ .wait(4000)
+ }.
/* -- plans for the goals of role herder -- */
@@ -65,11 +58,29 @@
{ begin maintenance_goal("+pos(_,_,_)") }
+!recruit[scheme(Sch),mission(Mission)]
- <- .print("ooo I should revise the size of the cluster and recruit!").
+ <- .print("ooo I should revise the size of the cluster and recruit!");
+ !check_merge.
{ end }
-
++!check_merge
+ : .my_name(Me) &
+ play(Me, herder, Gi) &
+ current_cluster(MyC)
+ <- // for all other groups
+ .for( group_leader(Gj, L) & L \== Me & Me < L) {
+ .print("ooo Checking merging with ",Gj);
+ // ask their cluster
+ .send(L, askOne, current_cluster(_), current_cluster(TC));
+ .intersection(MyC,TC,I);
+
+ .if (.length(I) > 0) {
+ .print("ooo Merging my herding group ",Gi," with ",Gj, " lead by ",L);
+ .send(L, achieve, change_role(herdboy,Gi))
+ }
+ }.
++!check_merge.
+
{ begin maintenance_goal("+pos(_,_,_)") }
+!define_formation[scheme(Sch),mission(Mission)]
@@ -116,6 +127,7 @@
!closest(T,Aux2,S,pos(XP,YP),LD).
*/
+
/* -- plans for the goals of all roles (herder and herdboy) -- */
Modified: trunk/applications/jason-team/src/java/arch/ACProxy.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/ACProxy.java 2008-05-05 18:33:43 UTC (rev 1291)
+++ trunk/applications/jason-team/src/java/arch/ACProxy.java 2008-05-06 22:06:56 UTC (rev 1292)
@@ -203,12 +203,12 @@
}
}
+ //if (logger.isLoggable(Level.FINE))
+ logger.info("Request action for "+lpos+" / rid: "+rid+" / percepts: "+percepts);
//arq.sendCowsToTeam();
arq.startNextStep(step, percepts);
- //if (logger.isLoggable(Level.FINE))
- logger.info("Request action for "+lpos+" / rid: "+rid+" / percepts: "+percepts);
} catch (Exception e) {
logger.log(Level.SEVERE, "error processing request",e);
}
Modified: trunk/applications/jason-team/src/java/jia/herd_position.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/herd_position.java 2008-05-05 18:33:43 UTC (rev 1291)
+++ trunk/applications/jason-team/src/java/jia/herd_position.java 2008-05-06 22:06:56 UTC (rev 1292)
@@ -146,7 +146,7 @@
}
}
- private List<Location> formationPlaces(List<Location> clusterLocs, Formation formation) throws Exception {
+ public List<Location> formationPlaces(List<Location> clusterLocs, Formation formation) throws Exception {
lastCluster = clusterLocs;
List<Vec> cows = cluster.location2vec(model, clusterLocs);
@@ -180,8 +180,12 @@
Location l = findFirstFreeLocTowardsTarget(agTarget, mean.add(agsTarget), initAgTS, dist, model);
//System.out.println(" = "+dist+" result "+l);
- if (l != null)
- r.add(pathToNearCow(l, clusterLocs));
+ if (l != null) {
+ l = pathToNearCow(l, clusterLocs);
+ if ( ! model.inGrid(l) || model.hasObject(WorldModel.OBSTACLE, l))
+ l = model.nearFree(l);
+ r.add( l );
+ }
/*
Location lastloc = null;
@@ -210,7 +214,7 @@
public static Location findFirstFreeLocTowardsTarget(Vec target, Vec ref, int initialSize, int maxSize, LocalWorldModel model) {
Location lastloc = null;
maxSize = Math.abs(maxSize);
- Location l = ref.getLocation(model);;
+ Location l = ref.getLocation(model);
for (int s = initialSize; s <= maxSize; s++) {
l = target.newMagnitude(s).add(ref).getLocation(model);
//System.out.println("pos angle "+s+" = "+l);
Modified: trunk/applications/jason-team/src/java/test/TestBasicHerding.java
===================================================================
--- trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-05-05 18:33:43 UTC (rev 1291)
+++ trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-05-06 22:06:56 UTC (rev 1292)
@@ -220,6 +220,9 @@
Location byIA = hp.getAgTarget(clusterLocs, Formation.one, cowboy.getLocation(model));
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());
}
@Test
Modified: trunk/applications/jason-team/src/team-os.xml
===================================================================
--- trunk/applications/jason-team/src/team-os.xml 2008-05-05 18:33:43 UTC (rev 1291)
+++ trunk/applications/jason-team/src/team-os.xml 2008-05-06 22:06:56 UTC (rev 1292)
@@ -95,10 +95,10 @@
<scheme id="herd_sch" >
<goal id="herd_cows" >
<plan operator="parallel">
- <goal id="recruit" ds="recruit more herdboys depending on the size of the cows cluster" type="maintenance"/>
- <goal id="define_formation" ds="compute the ideal location of each member of the group and share this information with them" type="maintenance"/>
- <goal id="be_in_formation" ds="go to the place allocated to the agent in the formation" type="maintenance"/>
- <goal id="share_seen_cows" ds="share seen cows with other agents in the scheme" type="maintenance"/>
+ <goal id="recruit" ds="recruit more herdboys depending on the size of the cows cluster" type="maintenance"/>
+ <goal id="define_formation" ds="compute the ideal location of each member of the group and share this information with them" type="maintenance"/>
+ <goal id="be_in_formation" ds="go to the place allocated to the agent in the formation" type="maintenance"/>
+ <goal id="share_seen_cows" ds="share seen cows with other agents in the scheme" type="maintenance"/>
</plan>
</goal>
Modified: trunk/src/jason/environment/grid/GridWorldView.java
===================================================================
--- trunk/src/jason/environment/grid/GridWorldView.java 2008-05-05 18:33:43 UTC (rev 1291)
+++ trunk/src/jason/environment/grid/GridWorldView.java 2008-05-06 22:06:56 UTC (rev 1292)
@@ -56,8 +56,10 @@
/** updates only one position of the grid */
public void update(int x, int y) {
- drawEmpty(drawArea.getGraphics(), x, y);
- draw(drawArea.getGraphics(), x, y);
+ Graphics g = drawArea.getGraphics();
+ if (g == null) return;
+ drawEmpty(g, x, y);
+ draw(g, x, y);
}
public void drawObstacle(Graphics g, int x, int y) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|