|
From: <jom...@us...> - 2008-05-29 07:05:22
|
Revision: 1315
http://jason.svn.sourceforge.net/jason/?rev=1315&view=rev
Author: jomifred
Date: 2008-05-29 00:05:19 -0700 (Thu, 29 May 2008)
Log Message:
-----------
jason team: fix minor issues in cluster alg.
Modified Paths:
--------------
trunk/applications/jason-team/gauchos.xml
trunk/applications/jason-team/readme.txt
trunk/applications/jason-team/src/asl/herding.asl
trunk/applications/jason-team/src/java/jia/cluster.java
trunk/applications/jason-team/src/java/test/TestBasicHerding.java
Modified: trunk/applications/jason-team/gauchos.xml
===================================================================
--- trunk/applications/jason-team/gauchos.xml 2008-05-28 20:05:55 UTC (rev 1314)
+++ trunk/applications/jason-team/gauchos.xml 2008-05-29 07:05:19 UTC (rev 1315)
@@ -115,7 +115,7 @@
<target name="clean" >
<delete failonerror="no" includeEmptyDirs="true" verbose="true">
- <fileset dir="${basedir}" includes="**/*.class"/>
+ <fileset dir="${basedir}/bin" includes="**/*.class"/>
</delete>
</target>
Modified: trunk/applications/jason-team/readme.txt
===================================================================
--- trunk/applications/jason-team/readme.txt 2008-05-28 20:05:55 UTC (rev 1314)
+++ trunk/applications/jason-team/readme.txt 2008-05-29 07:05:19 UTC (rev 1315)
@@ -5,7 +5,7 @@
*
* By
* Jomi F. Hubner (EMSE, France)
- * Rafael H. Bordini (Durhma, UK)
+ * Rafael H. Bordini (Durham, UK)
* Gauthier Picard (EMSE, France)
*/
Modified: trunk/applications/jason-team/src/asl/herding.asl
===================================================================
--- trunk/applications/jason-team/src/asl/herding.asl 2008-05-28 20:05:55 UTC (rev 1314)
+++ trunk/applications/jason-team/src/asl/herding.asl 2008-05-29 07:05:19 UTC (rev 1315)
@@ -82,7 +82,7 @@
//jia.path_length(TCX,TCY,CorralX,CorralY,TCD);
//.print("ooo check merging: my distance to corral = ",MCD," other group distance = ",TCD);
//if (MCD <= TCD) {
- .print("ooo Merging my herding group ",Gi," with ",Gj, " lead by ",L);
+ .print("ooo merging my herding group ",Gi," with ",Gj, " lead by ",L);
.send(L, achieve, change_role(herdboy,Gi))
//}
}
@@ -92,11 +92,36 @@
{ begin maintenance_goal("+pos(_,_,_)") }
-+!release_boys[scheme(Sch),mission(Mission),group(Gr)]
+/*+!release_boys[scheme(Sch),mission(Mission),group(Gr)]
: .count(play(_,herdboy,Gr),N) & N > 4
<- .print("xxx release gaucho5 from my herding group");
.send(gaucho5,achieve,create_exploration_gr);
.send(gaucho6,achieve,restart).
+ */
++!release_boys[scheme(Sch),mission(Mission),group(Gr)]
+ : .count(play(_,herdboy,Gr),N) &
+ (N > 3 | (N > 1 & current_cluster(CAsList) & .length(CAsList) < 5))
+
+ <- .print("xxx release an agent of my herding group");
+
+ // try an odd agent first
+ if (play(gaucho5,herdboy,Gr)) { // & agent_id(AgName,Id) & Id mod 2 == 1) {
+ .send(gaucho5,achieve,restart)
+ }{
+ if (play(gaucho6,herdboy,Gr)) { // & agent_id(AgName,Id) & Id mod 2 == 0) {
+ .send(gaucho6,achieve,restart)
+ }{
+ if (play(gaucho3,herdboy,Gr)) {
+ .send(gaucho3,achieve,restart)
+ }{
+ if (play(gaucho4,herdboy,Gr)) {
+ .send(gaucho4,achieve,restart)
+ }
+ }
+ }
+ };
+ .wait("+pos(_,_,_)"); // wait an extra step before try to release agents again
+ .wait("+pos(_,_,_)").
+!release_boys[scheme(Sch),mission(Mission),group(Gr)].
{ end }
Modified: trunk/applications/jason-team/src/java/jia/cluster.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/cluster.java 2008-05-28 20:05:55 UTC (rev 1314)
+++ trunk/applications/jason-team/src/java/jia/cluster.java 2008-05-29 07:05:19 UTC (rev 1315)
@@ -13,13 +13,13 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import arch.CowboyArch;
import arch.LocalWorldModel;
+import busca.Nodo;
import env.WorldModel;
/**
@@ -29,7 +29,7 @@
*/
public class cluster extends DefaultInternalAction {
- private static final int MAXCLUSTERSIZE = 15;
+ public static final int MAXCLUSTERSIZE = 15;
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
@@ -38,9 +38,8 @@
LocalWorldModel model = arch.getModel();
if (model == null)
return false;
- //Location agLoc = model.getAgPos(arch.getMyId());
- List<Location> locs = getCluster(model, 3); //WorldModel.cowPerceptionRatio);
+ List<Location> locs = getCluster(model, WorldModel.cowPerceptionRatio, arch);
if (args.length == 1) {
return un.unifies(args[0], new ObjectTermImpl(locs));
@@ -61,10 +60,10 @@
return false;
}
- public static List<Location> getCluster(LocalWorldModel model, int maxDist) {
+ public static List<Location> getCluster(LocalWorldModel model, int maxDist, CowboyArch arch) throws Exception {
/*
- Vs = set of all seen cows (sorted by distance to the centre of cluster)
- Cs = { the cow near to the center of Vs }
+ Vs = set of all seen cows
+ Cs = { the cow near to the corral }
add = true
while (add)
@@ -75,6 +74,29 @@
add = true
*/
Collection<Vec> cows = model.getCows();
+
+ // find cow near corral
+ Vec near = null;
+ int nearDist = 0;
+ for (Vec v: cows) {
+ // use A* to get the distance from this cow to corral
+ Nodo solution = new Search(model, v.getLocation(model), model.getCorralCenter(), arch).search();
+ if (solution != null) {
+ int d = solution.getProfundidade();
+ if (near == null || d < nearDist) {
+ near = v;
+ nearDist = d;
+ }
+ }
+ }
+
+ List<Vec> cs = new ArrayList<Vec>();
+ if (near != null) {
+ cs.add(near);
+ cows.remove(near);
+ }
+
+ /* OLD strategy
Vec mean = Vec.mean( cows );
List<Vec> vs = new ArrayList<Vec>();
// place all cows in ref to mean
@@ -83,15 +105,16 @@
if (vs.size() > 4)
Collections.sort(vs); // sort only big clusters (for small clusters, to sort causes a kind of oscillation)
-
- List<Vec> cs = new ArrayList<Vec>();
- if (!vs.isEmpty())
- cs.add(vs.remove(0));
+
+ if (!vs.isEmpty())
+ cs.add(vs.remove(0));
+ */
+
boolean add = true;
while (add) {
add = false;
- Iterator<Vec> i = vs.iterator();
+ Iterator<Vec> i = cows.iterator(); //vs.iterator();
while (i.hasNext()) {
Vec v = i.next();
@@ -114,9 +137,9 @@
List<Location> clusterLocs = new ArrayList<Location>();
for (Vec v: cs) {
// place all cows in ref to 0,0
- clusterLocs.add(v.add(mean).getLocation(model));
+ clusterLocs.add(v.getLocation(model));
+ //clusterLocs.add(v.add(mean).getLocation(model));
}
-
return clusterLocs;
}
Modified: trunk/applications/jason-team/src/java/test/TestBasicHerding.java
===================================================================
--- trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-05-28 20:05:55 UTC (rev 1314)
+++ trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-05-29 07:05:19 UTC (rev 1315)
@@ -82,7 +82,7 @@
}
@Test
- public void bigCluster() {
+ public void bigCluster() throws Exception {
// big cluster
for (int x = 10; x < 30; x++) {
for (int y = 5; y < 20; y++) {
@@ -90,8 +90,8 @@
}
}
- List<Location> cowsl = cluster.getCluster(model, WorldModel.cowPerceptionRatio);
- assertEquals(model.getCows().size(), cowsl.size());
+ List<Location> cowsl = cluster.getCluster(model, WorldModel.cowPerceptionRatio, null);
+ assertEquals(cluster.MAXCLUSTERSIZE, cowsl.size());
}
private void addCowsToModel(Vec... cows) {
@@ -189,7 +189,7 @@
scenario1();
// find center/clusterise
- List<Location> clusterLocs = cluster.getCluster(model, WorldModel.cowPerceptionRatio);
+ List<Location> clusterLocs = cluster.getCluster(model, WorldModel.cowPerceptionRatio, null);
List<Vec> cowsl = cluster.location2vec(model, clusterLocs);
//Vec stddev = Vec.stddev(cowsl, Vec.mean(cowsl));
assertEquals(3, cowsl.size());
@@ -249,7 +249,7 @@
scenario2();
model.add(WorldModel.ENEMY, 11,48);
- List<Location> clusterLocs = cluster.getCluster(model, WorldModel.cowPerceptionRatio);
+ List<Location> clusterLocs = cluster.getCluster(model, WorldModel.cowPerceptionRatio, null);
List<Vec> cowsl = cluster.location2vec(model, clusterLocs);
assertEquals(9, cowsl.size());
@@ -270,7 +270,7 @@
public void formationSc3() throws Exception {
scenario3();
- List<Location> clusterLocs = cluster.getCluster(model, WorldModel.cowPerceptionRatio);
+ List<Location> clusterLocs = cluster.getCluster(model, WorldModel.cowPerceptionRatio, null);
assertEquals(6, clusterLocs.size());
herd_position hp = new herd_position();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|