|
From: <jom...@us...> - 2008-04-28 20:54:44
|
Revision: 1277
http://jason.svn.sourceforge.net/jason/?rev=1277&view=rev
Author: jomifred
Date: 2008-04-28 13:54:41 -0700 (Mon, 28 Apr 2008)
Log Message:
-----------
jason team: improve share_cows alg
Modified Paths:
--------------
trunk/applications/jason-moise/lib/moise.jar
trunk/applications/jason-moise/src/jmoise/OrgManager.java
trunk/applications/jason-team/AC-Local-JasonTeam.mas2j
trunk/applications/jason-team/massim-server/conf/serverconfig.xml
trunk/applications/jason-team/src/asl/dummy.asl
trunk/applications/jason-team/src/asl/gaucho.asl
trunk/applications/jason-team/src/java/agent/SelectEvent.java
trunk/applications/jason-team/src/java/arch/ACArchitecture.java
trunk/applications/jason-team/src/java/arch/ACProxy.java
trunk/applications/jason-team/src/java/arch/CowboyArch.java
trunk/applications/jason-team/src/java/arch/LocalWorldModel.java
trunk/applications/jason-team/src/java/jia/Vec.java
trunk/applications/jason-team/src/java/jia/herd_position.java
trunk/applications/jason-team/src/java/test/TestBasicHerding.java
Modified: trunk/applications/jason-moise/lib/moise.jar
===================================================================
(Binary files differ)
Modified: trunk/applications/jason-moise/src/jmoise/OrgManager.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/OrgManager.java 2008-04-28 17:38:52 UTC (rev 1276)
+++ trunk/applications/jason-moise/src/jmoise/OrgManager.java 2008-04-28 20:54:41 UTC (rev 1277)
@@ -194,7 +194,7 @@
}
// notify others in the group about this new player
- updateMembersOE(gr.getAgents(), "play(" + sender + "," + roleId + "," + grId + ")", true, true);
+ updateMembersOE(gr.getAgentsInThisGroupAndSubGroups(), "play(" + sender + "," + roleId + "," + grId + ")", true, true);
// send players of this group to sender
for (RolePlayer rp : gr.getPlayers()) {
@@ -216,7 +216,7 @@
GroupInstance gr = currentOE.findGroup(grId);
// notify other players
- updateMembersOE(gr.getAgents(), "play(" + sender + "," + roleId + "," + grId + ")", false, false);
+ updateMembersOE(gr.getAgentsInThisGroupAndSubGroups(), "play(" + sender + "," + roleId + "," + grId + ")", false, false);
}
}
Modified: trunk/applications/jason-team/AC-Local-JasonTeam.mas2j
===================================================================
--- trunk/applications/jason-team/AC-Local-JasonTeam.mas2j 2008-04-28 17:38:52 UTC (rev 1276)
+++ trunk/applications/jason-team/AC-Local-JasonTeam.mas2j 2008-04-28 20:54:41 UTC (rev 1277)
@@ -1,3 +1,4 @@
+
/* Jason Team for the
* Multi-Agent Programming Contest 2008
* (http://cig.in.tu-clausthal.de/AgentContest)
Modified: trunk/applications/jason-team/massim-server/conf/serverconfig.xml
===================================================================
--- trunk/applications/jason-team/massim-server/conf/serverconfig.xml 2008-04-28 17:38:52 UTC (rev 1276)
+++ trunk/applications/jason-team/massim-server/conf/serverconfig.xml 2008-04-28 20:54:41 UTC (rev 1277)
@@ -266,52 +266,52 @@
<account actionclassmap="Grid"
defaultactionclass="massim.simulation.GridSimulationAgentAction"
- timeout="8000" auxtimeout="500" maxpacketlength="65536"
+ timeout="4000" auxtimeout="500" maxpacketlength="65536"
username="botagent1" password="1" team="bot" />
<account actionclassmap="Grid"
defaultactionclass="massim.simulation.GridSimulationAgentAction"
- timeout="8000" auxtimeout="500" maxpacketlength="65536"
+ timeout="4000" auxtimeout="500" maxpacketlength="65536"
username="botagent2" password="2" team="bot" />
<account actionclassmap="Grid"
defaultactionclass="massim.simulation.GridSimulationAgentAction"
- timeout="8000" auxtimeout="500" maxpacketlength="65536"
+ timeout="4000" auxtimeout="500" maxpacketlength="65536"
username="botagent3" password="3" team="bot" />
<account actionclassmap="Grid"
defaultactionclass="massim.simulation.GridSimulationAgentAction"
- timeout="8000" auxtimeout="500" maxpacketlength="65536"
+ timeout="4000" auxtimeout="500" maxpacketlength="65536"
username="botagent4" password="4" team="bot" />
<account actionclassmap="Grid"
defaultactionclass="massim.simulation.GridSimulationAgentAction"
- timeout="8000" auxtimeout="500" maxpacketlength="65536"
+ timeout="4000" auxtimeout="500" maxpacketlength="65536"
username="botagent5" password="5" team="bot" />
<account actionclassmap="Grid"
defaultactionclass="massim.simulation.GridSimulationAgentAction"
- timeout="8000" auxtimeout="500" maxpacketlength="65536"
+ timeout="4000" auxtimeout="500" maxpacketlength="65536"
username="botagent6" password="6" team="bot" />
<account actionclassmap="Grid"
defaultactionclass="massim.simulation.GridSimulationAgentAction"
- timeout="8000" auxtimeout="500" maxpacketlength="65536"
+ timeout="4000" auxtimeout="500" maxpacketlength="65536"
username="participant1" password="1" team="participant" />
<account actionclassmap="Grid"
defaultactionclass="massim.simulation.GridSimulationAgentAction"
- timeout="8000" auxtimeout="500" maxpacketlength="65536"
+ timeout="4000" auxtimeout="500" maxpacketlength="65536"
username="participant2" password="2" team="participant" />
<account actionclassmap="Grid"
defaultactionclass="massim.simulation.GridSimulationAgentAction"
- timeout="8000" auxtimeout="500" maxpacketlength="65536"
+ timeout="4000" auxtimeout="500" maxpacketlength="65536"
username="participant3" password="3" team="participant" />
<account actionclassmap="Grid"
defaultactionclass="massim.simulation.GridSimulationAgentAction"
- timeout="8000" auxtimeout="500" maxpacketlength="65536"
+ timeout="4000" auxtimeout="500" maxpacketlength="65536"
username="participant4" password="4" team="participant" />
<account actionclassmap="Grid"
defaultactionclass="massim.simulation.GridSimulationAgentAction"
- timeout="8000" auxtimeout="500" maxpacketlength="65536"
+ timeout="4000" auxtimeout="500" maxpacketlength="65536"
username="participant5" password="5" team="participant" />
<account actionclassmap="Grid"
defaultactionclass="massim.simulation.GridSimulationAgentAction"
- timeout="8000" auxtimeout="500" maxpacketlength="65536"
+ timeout="4000" auxtimeout="500" maxpacketlength="65536"
username="participant6" password="6" team="participant" />
</accounts>
Modified: trunk/applications/jason-team/src/asl/dummy.asl
===================================================================
--- trunk/applications/jason-team/src/asl/dummy.asl 2008-04-28 17:38:52 UTC (rev 1276)
+++ trunk/applications/jason-team/src/asl/dummy.asl 2008-04-28 20:54:41 UTC (rev 1277)
@@ -50,8 +50,12 @@
+pos(Step,_,_) // new cycle
: Step mod 6 == 0
<- !decide_target.
-
+
+// add all cows in BB (used by the arch)
++cell(X,Y,cow(_)) <- +cow(X,Y).
+-cell(X,Y,cow(_)) <- -cow(X,Y).
+
/* -- decide a new target -- */
+!decide_target
Modified: trunk/applications/jason-team/src/asl/gaucho.asl
===================================================================
--- trunk/applications/jason-team/src/asl/gaucho.asl 2008-04-28 17:38:52 UTC (rev 1276)
+++ trunk/applications/jason-team/src/asl/gaucho.asl 2008-04-28 20:54:41 UTC (rev 1277)
@@ -94,16 +94,16 @@
+!share_seen_cows.
// simple implementation of share_cows (see TODO above)
-+cell(X,Y,cow(_))
++cell(X,Y,cow(_))[source(percept)]
: .my_name(Me) & play(Me,_,Gr)
<- C = cow(X,Y);
+C;
- jmoise.broadcast(Gr, tell, C).
--cell(X,Y,cow(_))
+ jmoise.broadcast(Gr, tell, C).
+-cell(X,Y,cow(_))[source(percept)]
: .my_name(Me) & play(Me,_,Gr)
<- C = cow(X,Y);
-C;
- jmoise.broadcast(Gr, untell, C).
+ jmoise.broadcast(Gr, untell, C).
Modified: trunk/applications/jason-team/src/java/agent/SelectEvent.java
===================================================================
--- trunk/applications/jason-team/src/java/agent/SelectEvent.java 2008-04-28 17:38:52 UTC (rev 1276)
+++ trunk/applications/jason-team/src/java/agent/SelectEvent.java 2008-04-28 20:54:41 UTC (rev 1277)
@@ -10,14 +10,13 @@
import java.util.Queue;
/**
- * change the default select event function to prefer cell(_,_,gold) events.
+ * change the default select event function to prefer cell(_,_,cow(_)) events.
*
* @author Jomi
*/
public class SelectEvent extends Agent {
- private Trigger gold = Trigger.parseTrigger("+cell(_,_,gold)");
- private Trigger restart = Trigger.parseTrigger("+restart");
+ private Trigger cow = Trigger.parseTrigger("+cell(_,_,cow(_))");
private Unifier un = new Unifier();
public Event selectEvent(Queue<Event> events) {
@@ -25,14 +24,11 @@
while (ie.hasNext()) {
un.clear();
Event e = ie.next();
- if (un.unifies(gold, e.getTrigger()) || un.unifies(restart, e.getTrigger())) {
- //getTS().getLogger().info("custom select event "+e);
+ if (un.unifies(cow, e.getTrigger())) {
ie.remove();
return e;
}
}
return super.selectEvent(events);
}
-
-
}
Modified: trunk/applications/jason-team/src/java/arch/ACArchitecture.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-04-28 17:38:52 UTC (rev 1276)
+++ trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-04-28 20:54:41 UTC (rev 1277)
@@ -131,7 +131,7 @@
}
*/
- class WaitSleep extends Thread {
+ class WaitSleep extends Thread {
ActionExec lastAction;
String lastActionInCurrentCycle;
@@ -141,6 +141,7 @@
long timestartcycle = 0;
int cycleCounter = 0;
+
WaitSleep() {
super("WaitSpeepToSendAction");
}
Modified: trunk/applications/jason-team/src/java/arch/ACProxy.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/ACProxy.java 2008-04-28 17:38:52 UTC (rev 1276)
+++ trunk/applications/jason-team/src/java/arch/ACProxy.java 2008-04-28 20:54:41 UTC (rev 1277)
@@ -188,8 +188,8 @@
int cowId = Integer.parseInt(type.getAttribute("ID"));
Structure lc = new Literal("cow");
lc.addTerm(new NumberTermImpl( cowId ));
- percepts.add(CowboyArch.createCellPerception(cellx, celly, lc));
- arq.cowPerceived(absx, absy);
+ percepts.add(CowboyArch.createCellPerception(absx, absy, lc));
+ //arq.cowPerceived(absx, absy);
} else if (type.getNodeName().equals("obstacle")) {
arq.obstaclePerceived(absx, absy, CowboyArch.createCellPerception(absx, absy, CowboyArch.aOBSTACLE));
Modified: trunk/applications/jason-team/src/java/arch/CowboyArch.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-04-28 17:38:52 UTC (rev 1276)
+++ trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-04-28 20:54:41 UTC (rev 1277)
@@ -14,8 +14,6 @@
import jason.mas2j.ClassParameters;
import jason.runtime.Settings;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -31,7 +29,7 @@
*/
public class CowboyArch extends IdentifyCrashed {
- LocalWorldModel model = new LocalWorldModel(10,10);
+ LocalWorldModel model = null;
WorldView view = null;
String simId = null;
@@ -57,6 +55,8 @@
@Override
public void initAg(String agClass, ClassParameters bbPars, String asSrc, Settings stts) throws JasonException {
super.initAg(agClass, bbPars, asSrc, stts);
+
+ model = new LocalWorldModel(10,10, WorldModel.agsByTeam, getTS().getAg().getBB()); // just to have a default model
gui = "yes".equals(stts.getUserParameter("gui"));
if ("yes".equals(stts.getUserParameter("write_status"))) {
writeStatusThread = WriteStatusThread.create(this);
@@ -68,7 +68,6 @@
if (massimBackDir != null && massimBackDir.startsWith("\""))
massimBackDir = massimBackDir.substring(1,massimBackDir.length()-1);
logger = Logger.getLogger(CowboyArch.class.getName() + ".CA-" + getAgName());
-
}
@Override
@@ -110,7 +109,7 @@
/** The perception of the grid size is removed from the percepts list
and "directly" added as a belief */
void gsizePerceived(int w, int h, String opponent) throws RevisionFailedException {
- model = new LocalWorldModel(w, h);
+ model = new LocalWorldModel(w, h, WorldModel.agsByTeam, getTS().getAg().getBB());
getTS().getAg().addBel(Literal.parseLiteral("gsize("+w+","+h+")"));
playing = true;
@@ -242,9 +241,10 @@
return l;
}
- private static final Literal cowstoclean = Literal.parseLiteral("cell(_,_,cow(_))");
- private boolean cleanCows = false;
+ //private static final Literal cowstoclean = Literal.parseLiteral("cell(_,_,cow(_))");
+ //private boolean cleanCows = false;
+ /*
@Override
public synchronized void agDidPerceive() {
super.agDidPerceive();
@@ -255,15 +255,18 @@
cleanCows = false;
}
}
+ */
void initKnownCows() {
model.clearCows();
- cleanCows = true;
+ //cleanCows = true;
}
- void cowPerceived(int x, int y) {
- model.addCow(x,y);
- }
+ //void cowPerceived(int x, int y) {
+ // model.addCow(x,y);
+ //}
+
+ /*
void sendCowsToTeam() {
try {
Message m = new Message("tell-cows", null, null, new ArrayList<Location>(model.getCows()));
@@ -272,6 +275,7 @@
e.printStackTrace();
}
}
+ */
void enemyPerceived(int x, int y) {
model.add(WorldModel.ENEMY, x, y);
@@ -327,11 +331,13 @@
Message m = im.next();
if (m.getIlForce().equals("tell-cows")) {
im.remove();
+ /* not used anymore
if (model != null) {
for (Location l: (Collection<Location>)m.getPropCont()) {
cowPerceived(l.x, l.y);
}
}
+ */
} else {
String ms = m.getPropCont().toString();
if (ms.startsWith("cell") && ms.endsWith("obstacle)") && model != null) {
Modified: trunk/applications/jason-team/src/java/arch/LocalWorldModel.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-04-28 17:38:52 UTC (rev 1276)
+++ trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-04-28 20:54:41 UTC (rev 1277)
@@ -1,14 +1,18 @@
package arch;
+import jason.asSyntax.Literal;
+import jason.asSyntax.NumberTerm;
+import jason.bb.BeliefBase;
import jason.environment.grid.Location;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;
+import jia.Vec;
import env.WorldModel;
@@ -24,24 +28,28 @@
private Random random = new Random();
- Set<Location> cows = new HashSet<Location>();
+ Set<Vec> cows = new HashSet<Vec>();
+ boolean isCowsUptodate = false;
int[][] cowsrep; // cows repulsion
int[][] agsrep; // agents repulsion
int[][] obsrep; // obstacle repulsion
+ BeliefBase bb; // agent's BB
+
//private Logger logger = Logger.getLogger("jasonTeamSimLocal.mas2j." + LocalWorldModel.class.getName());
- public static LocalWorldModel create(int w, int h, int nbAg) {
- return new LocalWorldModel(w,h,nbAg);
- }
+ //public static LocalWorldModel create(int w, int h, int nbAg) {
+ // return new LocalWorldModel(w,h,nbAg);
+ //}
- public LocalWorldModel(int w, int h) {
- this(w, h, 6);
- }
+ //public LocalWorldModel(int w, int h) {
+ // this(w, h, 6);
+ //}
- public LocalWorldModel(int w, int h, int nbAg) {
+ public LocalWorldModel(int w, int h, int nbAg, BeliefBase bb) {
super(w, h, nbAg);
+ this.bb = bb;
visited = new int[getWidth()][getHeight()];
for (int i = 0; i < getWidth(); i++)
@@ -81,40 +89,52 @@
}
}
-
+ // cows methods
+
public void clearCows() {
- removeAll(WorldModel.COW);
+ isCowsUptodate = false;
+ }
+
+ public Set<Vec> getCows() {
+ if (!isCowsUptodate)
+ updateCowsFromBB();
+ return cows;
+ }
- for (int i = 0; i < getWidth(); i++)
+ private static final Literal cowLiteral = Literal.parseLiteral("cow(_,_)");
+
+ private void updateCowsFromBB() {
+ if (bb == null) return;
+
+ // clean
+ removeAll(WorldModel.COW);
+
+ for (int i = 0; i < getWidth(); i++)
for (int j = 0; j < getHeight(); j++)
- cowsrep[i][j] = 0;
-
+ cowsrep[i][j] = 0;
+
cows.clear();
+
+ // rebuild
+ Iterator<Literal> i = bb.getCandidateBeliefs(cowLiteral, null);
+ if (i != null) {
+ while (i.hasNext()) {
+ Literal c = i.next();
+ int x = (int)((NumberTerm)c.getTerm(0)).solve();
+ int y = (int)((NumberTerm)c.getTerm(1)).solve();
+ addCow(x,y);
+ }
+ }
+ isCowsUptodate = true;
}
public void addCow(int x, int y) {
add(WorldModel.COW, x, y);
- cows.add(new Location(x,y));
-
+ cows.add(new Vec( this, x, y));
increp(cowsrep, x, y, 2, 1);
}
- private void increp(int[][] m, int x, int y, int maxr, int value) {
- for (int r = 1; r <= maxr; r++)
- for (int c = x-r; c <= x+r; c++)
- for (int l = y-r; l <= y+r; l++)
- if (inGrid(c,l))
- m[c][l] += value;
- }
-
- public void addCow(Location l) {
- addCow(l.x, l.y);
- }
-
- public Collection<Location> getCows() {
- return cows;
- }
-
+
public int getCowsRep(int x, int y) {
return cowsrep[x][y];
}
@@ -125,6 +145,14 @@
return obsrep[x][y];
}
+ private void increp(int[][] m, int x, int y, int maxr, int value) {
+ for (int r = 1; r <= maxr; r++)
+ for (int c = x-r; c <= x+r; c++)
+ for (int l = y-r; l <= y+r; l++)
+ if (inGrid(c,l))
+ m[c][l] += value;
+ }
+
public Location nearFree(Location l) throws Exception {
int w = 0;
List<Location> options = new ArrayList<Location>();
Modified: trunk/applications/jason-team/src/java/jia/Vec.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/Vec.java 2008-04-28 17:38:52 UTC (rev 1276)
+++ trunk/applications/jason-team/src/java/jia/Vec.java 2008-04-28 20:54:41 UTC (rev 1277)
@@ -3,6 +3,7 @@
import jason.environment.grid.Location;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import arch.LocalWorldModel;
@@ -31,6 +32,14 @@
this.t = Math.atan2(y,x);
}
+ /** create a vector based on a location in the model */
+ public Vec(LocalWorldModel model, int x, int y) {
+ this.x = x;
+ this.y = model.getHeight()-y-1;
+ this.r = Math.sqrt(x*x + this.y*this.y);
+ this.t = Math.atan2(this.y,x);
+ }
+
public int getX() { return (int)Math.round(x); }
public int getY() { return (int)Math.round(y); }
public double magnitude() { return r; }
@@ -91,6 +100,10 @@
return ((int)(temp/(Math.PI/2))%4);
}
+ @Override
+ public int hashCode() {
+ return (int)((x + y) * 37);
+ }
@Override
public boolean equals(Object o) {
@@ -123,7 +136,7 @@
// Useful static methods for list of vecs
//
- public static Vec max(List<Vec> vs) {
+ public static Vec max(Collection<Vec> vs) {
Vec max = null;
for (Vec v: vs) {
if (max == null || max.r < v.r)
@@ -132,7 +145,7 @@
return max;
}
- public static List<Vec> sub(List<Vec> vs, Vec ref) {
+ public static List<Vec> sub(Collection<Vec> vs, Vec ref) {
List<Vec> r = new ArrayList<Vec>(vs.size());
for (Vec v: vs) {
r.add(v.sub(ref));
@@ -157,7 +170,7 @@
}
*/
- public static Vec mean(List<Vec> vs) {
+ public static Vec mean(Collection<Vec> vs) {
if (vs.isEmpty())
return new Vec(0,0);
double x = 0, y = 0;
@@ -168,7 +181,7 @@
return new Vec(x/vs.size(), y/vs.size());
}
- public static Vec stddev(List<Vec> vs, Vec mean) {
+ public static Vec stddev(Collection<Vec> vs, Vec mean) {
if (vs.isEmpty())
return new Vec(0,0);
double x = 0, y = 0;
Modified: trunk/applications/jason-team/src/java/jia/herd_position.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-28 17:38:52 UTC (rev 1276)
+++ trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-28 20:54:41 UTC (rev 1277)
@@ -12,6 +12,7 @@
import jason.environment.grid.Location;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -50,6 +51,7 @@
};
LocalWorldModel model;
+ List<Location> lastCluster = null;
public void setModel(LocalWorldModel model) {
this.model = model;
@@ -84,7 +86,7 @@
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(formation));
+ ts.getLogger().info("No target! I am at "+agLoc+" places are "+formationPlaces(formation)+" cluster is "+lastCluster);
}
} else {
// return all the locations for the formation
@@ -139,20 +141,18 @@
}
private List<Location> formationPlaces(Formation formation) throws Exception {
- List<Vec> cows = new ArrayList<Vec>();
- for (Location c: model.getCows()) {
- cows.add(new Vec(model, c));
- }
- if (cows.isEmpty())
- return null;
-
//cows = Vec.cluster(cows, 2); // find center/clusterise
- cows = cluster(cows, WorldModel.cowPerceptionRatio);
+ List<Vec>cows = cluster(model.getCows(), WorldModel.cowPerceptionRatio);
+
List<Location> clusterLocs = new ArrayList<Location>();
for (Vec v: cows) {
clusterLocs.add(v.getLocation(model));
}
+ lastCluster = clusterLocs;
+
+ if (cows.isEmpty())
+ return null;
Vec mean = Vec.mean(cows);
int stepsFromCenter = (int)Math.round(Vec.max(cows).sub(mean).magnitude())+1;
@@ -240,7 +240,7 @@
return t;
}
- public static List<Vec> cluster(List<Vec> cows, int maxDist) {
+ public static List<Vec> cluster(Collection<Vec> cows, int maxDist) {
/*
Vs = set of all seen cows (sorted by distance to the centre of cluster)
Cs = { the cow near to the center of Vs }
Modified: trunk/applications/jason-team/src/java/test/TestBasicHerding.java
===================================================================
--- trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-04-28 17:38:52 UTC (rev 1276)
+++ trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-04-28 20:54:41 UTC (rev 1277)
@@ -22,13 +22,12 @@
public class TestBasicHerding {
- Vec[] cows;
Vec cowboy;
LocalWorldModel model;
@Before
public void scenario() {
- model = new LocalWorldModel(50,50);
+ model = new LocalWorldModel(50,50, WorldModel.agPerceptionRatio, null);
model.setCorral(new Location(0,49), new Location(2,49));
model.wall(7, 44, 7, 49);
}
@@ -37,38 +36,51 @@
cowboy = new Vec(3,5);
model.add(WorldModel.AGENT, cowboy.getLocation(model));
- cows = new Vec[5];
- cows[0] = new Vec(6,7);
- cows[1] = new Vec(5,30);
- cows[2] = new Vec(4,8);
- cows[3] = new Vec(5,10);
- cows[4] = new Vec(0,1);
-
- for (int i=0; i<cows.length; i++)
- model.addCow(cows[i].getLocation(model));
-
+ addToModel(
+ new Vec(6,7),
+ new Vec(5,30),
+ new Vec(4,8),
+ new Vec(5,10),
+ new Vec(0,1));
}
public void scenario2() {
cowboy = new Vec(11,3);
model.add(WorldModel.AGENT, cowboy.getLocation(model));
- cows = new Vec[9];
- cows[0] = new Vec(8,0);
- cows[1] = new Vec(9,0);
- cows[2] = new Vec(10,0);
- cows[3] = new Vec(8,1);
- cows[4] = new Vec(9,1);
- cows[5] = new Vec(10,1);
- cows[6] = new Vec(8,2);
- cows[7] = new Vec(9,2);
- cows[8] = new Vec(10,2);
+ addToModel(
+ new Vec(8,0),
+ new Vec(9,0),
+ new Vec(10,0),
+ new Vec(8,1),
+ new Vec(9,1),
+ new Vec(10,1),
+ new Vec(8,2),
+ new Vec(9,2),
+ new Vec(10,2));
+ }
- for (int i=0; i<cows.length; i++)
- model.addCow(cows[i].getLocation(model));
+ @Test
+ public void bigCluster() {
+ // big cluster
+ for (int x = 10; x < 30; x++) {
+ for (int y = 5; y < 20; y++) {
+ addToModel(new Vec(model,x,y));
+ }
+ }
+ List<Vec> cowsl = herd_position.cluster(model.getCows(), WorldModel.cowPerceptionRatio);
+ assertEquals(model.getCows().size(), cowsl.size());
}
+
+ private void addToModel(Vec... cows) {
+ for (int i=0; i<cows.length; i++) {
+ Location l = cows[i].getLocation(model);
+ model.addCow(l.x, l.y);
+ }
+ }
+
@Test
public void testVec() {
scenario1();
@@ -85,10 +97,7 @@
public void testVecSort() {
scenario1();
- List<Vec> cowsl = new ArrayList<Vec>();
- for (int i=0; i<cows.length; i++) {
- cowsl.add(cows[i]);
- }
+ List<Vec> cowsl = new ArrayList<Vec>(model.getCows());
Collections.sort(cowsl);
assertEquals(new Vec(0,1), cowsl.get(0));
assertEquals(new Vec(4,8), cowsl.get(1));
@@ -146,13 +155,8 @@
public void moveCows2() throws Exception {
scenario1();
- List<Vec> cowsl = new ArrayList<Vec>();
- for (int i=0; i<cows.length; i++) {
- cowsl.add(cows[i]);
- }
-
// find center/clusterise
- cowsl = herd_position.cluster(cowsl, WorldModel.cowPerceptionRatio);
+ List<Vec> cowsl = herd_position.cluster(model.getCows(), WorldModel.cowPerceptionRatio);
//Vec stddev = Vec.stddev(cowsl, Vec.mean(cowsl));
assertEquals(3, cowsl.size());
@@ -205,12 +209,7 @@
scenario2();
model.add(WorldModel.ENEMY, 11,48);
- List<Vec> cowsl = new ArrayList<Vec>();
- for (int i=0; i<cows.length; i++) {
- cowsl.add(cows[i]);
- }
-
- cowsl = herd_position.cluster(cowsl, WorldModel.cowPerceptionRatio);
+ List<Vec> cowsl = herd_position.cluster(model.getCows(), WorldModel.cowPerceptionRatio);
assertEquals(9, cowsl.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.
|