|
From: <jom...@us...> - 2008-05-26 13:54:20
|
Revision: 1309
http://jason.svn.sourceforge.net/jason/?rev=1309&view=rev
Author: jomifred
Date: 2008-05-26 06:54:15 -0700 (Mon, 26 May 2008)
Log Message:
-----------
jason team: avoid to lead cows to enemy corral
Modified Paths:
--------------
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/env/WorldModel.java
trunk/applications/jason-team/src/java/jia/Search.java
trunk/applications/jason-team/src/java/jia/direction.java
trunk/applications/jason-team/src/java/jia/herd_position.java
trunk/applications/jason-team/src/java/test/TestBasicHerding.java
Modified: trunk/applications/jason-team/src/java/arch/ACProxy.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/ACProxy.java 2008-05-25 18:46:25 UTC (rev 1308)
+++ trunk/applications/jason-team/src/java/arch/ACProxy.java 2008-05-26 13:54:15 UTC (rev 1309)
@@ -197,7 +197,7 @@
} else if (type.getNodeName().equals("obstacle")) {
arq.obstaclePerceived(absx, absy, CowboyArch.createCellPerception(absx, absy, CowboyArch.aOBSTACLE));
} else if (type.getNodeName().equals("corral") && type.getAttribute("type").equals("enemy")) {
- arq.obstaclePerceived(absx, absy, CowboyArch.createCellPerception(absx, absy, CowboyArch.aOBSTACLE));
+ arq.enemyCorralPerceived(absx, absy, CowboyArch.createCellPerception(absx, absy, CowboyArch.aENEMYCORRAL));
//} else if (type.getNodeName().equals("empty")) {
// percepts.add(CowboyArch.createCellPerception(cellx, celly, CowboyArch.aEMPTY));
Modified: trunk/applications/jason-team/src/java/arch/CowboyArch.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-05-25 18:46:25 UTC (rev 1308)
+++ trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-05-26 13:54:15 UTC (rev 1309)
@@ -48,10 +48,11 @@
protected Logger logger = Logger.getLogger(CowboyArch.class.getName());
- public static Atom aOBSTACLE = new Atom("obstacle");
- public static Atom aENEMY = new Atom("enemy");
- public static Atom aALLY = new Atom("ally");
- public static Atom aEMPTY = new Atom("empty");
+ public static Atom aOBSTACLE = new Atom("obstacle");
+ public static Atom aENEMY = new Atom("enemy");
+ public static Atom aENEMYCORRAL = new Atom("enemycorral");
+ public static Atom aALLY = new Atom("ally");
+ public static Atom aEMPTY = new Atom("empty");
@Override
@@ -156,6 +157,17 @@
}
}
+ public void enemyCorralPerceived(int x, int y, Literal p) {
+ if (! model.hasObject(WorldModel.ENEMYCORRAL, x, y)) {
+ model.add(WorldModel.ENEMYCORRAL, x, y);
+ if (acView != null) acView.addObject(WorldModel.OBSTACLE, x, y);
+ Message m = new Message("tell", null, null, p);
+ try {
+ broadcast(m);
+ } catch (Exception e) { e.printStackTrace(); }
+ }
+ }
+
Location lo1 = new Location(-1,-1), // last locations of the agent
lo2 = new Location(-1,-1),
lo3 = new Location(-1,-1),
@@ -323,6 +335,17 @@
}
//getTS().getAg().getLogger().info("received obs="+p);
+ } else if (ms.startsWith("cell") && ms.endsWith(aENEMYCORRAL.toString()+")") && model != null) {
+ im.remove();
+
+ Literal p = (Literal)m.getPropCont();
+ int x = (int)((NumberTerm)p.getTerm(0)).solve();
+ int y = (int)((NumberTerm)p.getTerm(1)).solve();
+ if (model.inGrid(x,y)) {
+ model.add(WorldModel.ENEMYCORRAL, x, y);
+ if (acView != null) acView.addObject(WorldModel.OBSTACLE, x, y);
+ }
+
} else if (ms.startsWith("my_status") && model != null) {
im.remove();
Modified: trunk/applications/jason-team/src/java/arch/LocalWorldModel.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-05-25 18:46:25 UTC (rev 1308)
+++ trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-05-26 13:54:15 UTC (rev 1309)
@@ -34,6 +34,7 @@
int[][] cowsrep; // cows repulsion
int[][] agsrep; // agents repulsion
int[][] obsrep; // obstacle repulsion
+ int[][] enemycorralrep; // repulsion from enemy corral
BeliefBase bb; // agent's BB
@@ -48,29 +49,32 @@
for (int j = 0; j < getHeight(); j++)
visited[i][j] = 0;
- cowsrep = new int[getWidth()][getHeight()];
+ cowsrep = new int[getWidth()][getHeight()];
- agsrep = new int[getWidth()][getHeight()];
+ agsrep = new int[getWidth()][getHeight()];
+ obsrep = new int[getWidth()][getHeight()];
+ enemycorralrep = new int[getWidth()][getHeight()];
for (int i = 0; i < getWidth(); i++)
- for (int j = 0; j < getHeight(); j++)
+ for (int j = 0; j < getHeight(); j++) {
agsrep[i][j] = 0;
-
- obsrep = new int[getWidth()][getHeight()];
- for (int i = 0; i < getWidth(); i++)
- for (int j = 0; j < getHeight(); j++)
obsrep[i][j] = 0;
+ enemycorralrep[i][j] = 0;
+ }
}
@Override
public void add(int value, int x, int y) {
- super.add(value, x, y);
//if (value == WorldModel.AGENT || value == WorldModel.ENEMY) {
if (value == WorldModel.ENEMY) {
increp(agsrep, x, y, 2, 2);
} else if (value == WorldModel.OBSTACLE) {
increp(obsrep, x, y, 1, 1);
+ } else if (value == WorldModel.ENEMYCORRAL) {
+ increp(enemycorralrep, x, y, 3, 3);
+ value = OBSTACLE;
}
+ super.add(value, x, y);
}
@Override
public void remove(int value, int x, int y) {
@@ -136,13 +140,21 @@
public int getObsRep(int x, int y) {
return obsrep[x][y];
}
+ public int getEnemyCorralRep(int x, int y) {
+ return enemycorralrep[x][y];
+ }
private void increp(int[][] m, int x, int y, int maxr, int value) {
- for (int r = 1; r <= maxr; r++)
+ System.out.println("in for "+x+" "+y+" "+value);
+ for (int r = 1; r <= maxr; r++) {
+ System.out.println(" "+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;
+ if (inGrid(c,l)) {
+ System.out.println(" "+c+" "+l+" +"+value);
+ m[c][l] += value;
+ }
+ }
}
// occupied means the places that can not be considered as nearFree
Modified: trunk/applications/jason-team/src/java/env/WorldModel.java
===================================================================
--- trunk/applications/jason-team/src/java/env/WorldModel.java 2008-05-25 18:46:25 UTC (rev 1308)
+++ trunk/applications/jason-team/src/java/env/WorldModel.java 2008-05-26 13:54:15 UTC (rev 1309)
@@ -18,6 +18,7 @@
public static final int ENEMY = 64;
public static final int TARGET = 128; // one agent target location
public static final int FORPLACE = 256; // a place in a formation
+ public static final int ENEMYCORRAL = 512; // a place in a formation
public static final int nbActions = 8;
Modified: trunk/applications/jason-team/src/java/jia/Search.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/Search.java 2008-05-25 18:46:25 UTC (rev 1308)
+++ trunk/applications/jason-team/src/java/jia/Search.java 2008-05-26 13:54:15 UTC (rev 1309)
@@ -28,6 +28,7 @@
final boolean considerCorralAsObstacles;
final boolean considerCowsAsObstacles;
final boolean considerRepulsionForCows;
+ final boolean considerEnemyCorralRepulsion;
int maxDistFromCluster;
WorldModel.Move[] actionsOrder;
@@ -52,6 +53,7 @@
boolean considerCorralAsObstacles,
boolean considerCowsAsObstacles,
boolean considerRepulsionForCows,
+ boolean considerEnemyCorralRepulsion,
AgArch agArch) {
this.model = m;
@@ -61,6 +63,7 @@
this.considerCorralAsObstacles = considerCorralAsObstacles;
this.considerCowsAsObstacles = considerCowsAsObstacles;
this.considerRepulsionForCows = considerRepulsionForCows;
+ this.considerEnemyCorralRepulsion = considerEnemyCorralRepulsion;
this.agArch = agArch;
if (actions != null)
this.actionsOrder = actions;
@@ -78,7 +81,7 @@
/** used normally to discover the distance from 'from' to 'to' (or if there is path to) */
Search(LocalWorldModel m, Location from, Location to, AgArch agArch) {
- this(m,from,to,null,false, false, false, false, agArch);
+ this(m,from,to,null,false, false, false, false, false, agArch);
}
public Nodo search() throws Exception {
@@ -176,17 +179,25 @@
public int custo() {
if (isRoot)
return 0;
+
+ int c = 1;
+
if (ia.considerCowsAsObstacles)
- return ia.model.getCowsRep(pos.x, pos.y)+1;
+ c += ia.model.getCowsRep(pos.x, pos.y);
if (ia.considerRepulsionForCows) {
// consider the cost of agents only if they are near
- int c = ia.model.getObsRep(pos.x, pos.y) + 1;
+ c += ia.model.getObsRep(pos.x, pos.y);
if (ia.from.maxBorder(pos) <= ia.maxDistFromCluster)
c += ia.model.getAgsRep(pos.x, pos.y);
- return c;
}
- return 1;
+
+ if (ia.considerEnemyCorralRepulsion) {
+ System.out.println("using "+ia.model.getEnemyCorralRep(pos.x, pos.y)+" for "+pos);
+ c += ia.model.getEnemyCorralRep(pos.x, pos.y);
+ }
+
+ return c;
}
public boolean ehMeta() {
Modified: trunk/applications/jason-team/src/java/jia/direction.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/direction.java 2008-05-25 18:46:25 UTC (rev 1308)
+++ trunk/applications/jason-team/src/java/jia/direction.java 2008-05-26 13:54:15 UTC (rev 1309)
@@ -61,7 +61,7 @@
actionsOrder[i2] = actionsOrder[i1];
actionsOrder[i1] = temp;
- Search astar = new Search(model, from, to, actionsOrder, true, false, true, false, arch);
+ Search astar = new Search(model, from, to, actionsOrder, true, false, true, false, false, arch);
Nodo solution = astar.search();
if (solution == null) {
@@ -79,7 +79,7 @@
}
// run A* again
- astar = new Search(model, from, to, actionsOrder, true, false, true, false, arch);
+ astar = new Search(model, from, to, actionsOrder, true, false, true, false, false, arch);
solution = astar.search();
}
Modified: trunk/applications/jason-team/src/java/jia/herd_position.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/herd_position.java 2008-05-25 18:46:25 UTC (rev 1308)
+++ trunk/applications/jason-team/src/java/jia/herd_position.java 2008-05-26 13:54:15 UTC (rev 1309)
@@ -159,7 +159,7 @@
//Vec max = Vec.max(cows);
// run A* to see the cluster target in n steps
- Search s = new Search(model, mean.getLocation(model), model.getCorralCenter(), null, false, false, false, true, null);
+ Search s = new Search(model, mean.getLocation(model), model.getCorralCenter(), null, false, false, false, true, true, null);
s.setMaxDistFromCluster(stepsFromCenter+Search.DIST_FOR_AG_OBSTACLE);
List<Nodo> np = s.normalPath(s.search());
int n = Math.min(stepsFromCenter, np.size());
Modified: trunk/applications/jason-team/src/java/test/TestBasicHerding.java
===================================================================
--- trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-05-25 18:46:25 UTC (rev 1308)
+++ trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-05-26 13:54:15 UTC (rev 1309)
@@ -167,12 +167,24 @@
@Test
public void testAStar1() throws Exception {
scenario1();
- Search s = new Search(model, cowboy.getLocation(model), new Location(8,37), null, true, true, true, false, null);
+ Search s = new Search(model, cowboy.getLocation(model), new Location(8,37), null, true, true, true, false, false, null);
Nodo path = s.search();
assertEquals(15, s.normalPath(path).size());
}
@Test
+ public void testAStarPathInEnemyCorral() throws Exception {
+ scenario3();
+ model.add(WorldModel.ENEMYCORRAL, 10, 7);
+ model.add(WorldModel.ENEMYCORRAL, 11, 7);
+ model.add(WorldModel.ENEMYCORRAL, 12, 7);
+ Search s = new Search(model,new Location(12,12), new Location(10,1), null, true, false, true, false, true, null);
+ Nodo path = s.search();
+ System.out.println(s.normalPath(path));
+ //assertEquals(15, s.normalPath(path).size());
+ }
+
+ @Test
public void moveCows2() throws Exception {
scenario1();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|