|
From: <jom...@us...> - 2008-05-29 11:49:20
|
Revision: 1316
http://jason.svn.sourceforge.net/jason/?rev=1316&view=rev
Author: jomifred
Date: 2008-05-29 04:49:16 -0700 (Thu, 29 May 2008)
Log Message:
-----------
jason team: fix restart
Modified Paths:
--------------
trunk/applications/jason-team/src/asl/exploration.asl
trunk/applications/jason-team/src/asl/herding.asl
trunk/applications/jason-team/src/java/jia/cluster.java
Modified: trunk/applications/jason-team/src/asl/exploration.asl
===================================================================
--- trunk/applications/jason-team/src/asl/exploration.asl 2008-05-29 07:05:19 UTC (rev 1315)
+++ trunk/applications/jason-team/src/asl/exploration.asl 2008-05-29 11:49:16 UTC (rev 1316)
@@ -171,7 +171,7 @@
<- .send(L,askAll,play(_, herdboy, _), LBoys);
.send(L,askOne,current_cluster(_),current_cluster(LCluster));
//.print("xxx boys of ",L," are ",LBoys," his cluster size is ", .length(LCluster));
- if (.length(LBoys) < 2 & .length(LCluster) > 10) {
+ if (.length(LBoys) < 2 & .length(LCluster) > (.length(LBoys)+1)*5) {
!!create_herding_gr
}{
!check_small_herd_grp(Leaders)
Modified: trunk/applications/jason-team/src/asl/herding.asl
===================================================================
--- trunk/applications/jason-team/src/asl/herding.asl 2008-05-29 07:05:19 UTC (rev 1315)
+++ trunk/applications/jason-team/src/asl/herding.asl 2008-05-29 11:49:16 UTC (rev 1316)
@@ -65,7 +65,7 @@
+!check_merge
: .my_name(Me) &
play(Me, herder, Gi) &
- .count(play(_,_,Gi), N) & N < 3 & // only merge small group
+ //.count(play(_,_,Gi), N) & N < 3 & // only merge small group
current_cluster(MyC)
<- // for all other groups
for( group_leader(Gj, L) & Me < L & L \== Me & not play(L,herdboy,Gi)) { //
Modified: trunk/applications/jason-team/src/java/jia/cluster.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/cluster.java 2008-05-29 07:05:19 UTC (rev 1315)
+++ trunk/applications/jason-team/src/java/jia/cluster.java 2008-05-29 11:49:16 UTC (rev 1316)
@@ -13,6 +13,7 @@
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;
@@ -20,7 +21,6 @@
import arch.CowboyArch;
import arch.LocalWorldModel;
import busca.Nodo;
-import env.WorldModel;
/**
* Computes a cluster of cows for the agent
@@ -39,7 +39,7 @@
if (model == null)
return false;
- List<Location> locs = getCluster(model, WorldModel.cowPerceptionRatio, arch);
+ List<Location> locs = getCluster(model, 3, arch); //WorldModel.cowPerceptionRatio
if (args.length == 1) {
return un.unifies(args[0], new ObjectTermImpl(locs));
@@ -60,7 +60,7 @@
return false;
}
- public static List<Location> getCluster(LocalWorldModel model, int maxDist, CowboyArch arch) throws Exception {
+ public static List<Location> getClusterTest1(LocalWorldModel model, int maxDist, CowboyArch arch) throws Exception {
/*
Vs = set of all seen cows
Cs = { the cow near to the corral }
@@ -96,8 +96,53 @@
cows.remove(near);
}
- /* OLD strategy
- Vec mean = Vec.mean( cows );
+ boolean add = true;
+ while (add) {
+ add = false;
+ Iterator<Vec> i = cows.iterator();
+ while (i.hasNext()) {
+ Vec v = i.next();
+
+ Iterator<Vec> j = cs.iterator();
+ while (j.hasNext() && cs.size() < MAXCLUSTERSIZE) {
+ Vec c = j.next();
+ if (c.sub(v).magnitude() < maxDist) {
+ cs.add(v);
+ i.remove();
+ add = true;
+ break;
+ }
+ }
+ }
+
+ // do not get too big clusters
+ if (cs.size() > MAXCLUSTERSIZE)
+ break;
+ }
+ List<Location> clusterLocs = new ArrayList<Location>();
+ for (Vec v: cs) {
+ // place all cows in ref to 0,0
+ clusterLocs.add(v.getLocation(model));
+ }
+ return clusterLocs;
+ }
+
+ 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 }
+
+ add = true
+ while (add)
+ add = false
+ for all v in Vs
+ if (some cow in Cs sees v)
+ move v from Vs to Cs
+ add = true
+ */
+ Collection<Vec> cows = model.getCows();
+ List<Vec> cs = new ArrayList<Vec>();
+ Vec mean = Vec.mean( cows );
List<Vec> vs = new ArrayList<Vec>();
// place all cows in ref to mean
for (Vec v: cows)
@@ -108,13 +153,12 @@
if (!vs.isEmpty())
cs.add(vs.remove(0));
- */
boolean add = true;
while (add) {
add = false;
- Iterator<Vec> i = cows.iterator(); //vs.iterator();
+ Iterator<Vec> i = vs.iterator();
while (i.hasNext()) {
Vec v = i.next();
@@ -137,12 +181,11 @@
List<Location> clusterLocs = new ArrayList<Location>();
for (Vec v: cs) {
// place all cows in ref to 0,0
- clusterLocs.add(v.getLocation(model));
- //clusterLocs.add(v.add(mean).getLocation(model));
+ clusterLocs.add(v.add(mean).getLocation(model));
}
return clusterLocs;
}
-
+
public static List<Vec> location2vec(LocalWorldModel model, List<Location> clusterLocs) {
List<Vec> cows = new ArrayList<Vec>();
for (Location l: clusterLocs)
@@ -150,4 +193,3 @@
return cows;
}
}
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|