|
From: <jom...@us...> - 2008-04-21 16:47:00
|
Revision: 1236
http://jason.svn.sourceforge.net/jason/?rev=1236&view=rev
Author: jomifred
Date: 2008-04-21 09:46:57 -0700 (Mon, 21 Apr 2008)
Log Message:
-----------
minor changes in jason team
Modified Paths:
--------------
trunk/applications/jason-team/src/asl/dummy.asl
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/arch/WriteStatusThread.java
trunk/applications/jason-team/src/java/env/WorldModel.java
trunk/applications/jason-team/src/java/jia/herd_position.java
trunk/applications/jason-team/todo.org
Removed Paths:
-------------
trunk/applications/jason-team/run.sh
Deleted: trunk/applications/jason-team/run.sh
===================================================================
--- trunk/applications/jason-team/run.sh 2008-04-21 12:59:17 UTC (rev 1235)
+++ trunk/applications/jason-team/run.sh 2008-04-21 16:46:57 UTC (rev 1236)
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-java -cp ../../lib/jason.jar:lib/search.jar:bin/classes \
- jason.infra.centralised.RunCentralisedMAS \
- AC-Local-JasonTeam.mas2j
Modified: trunk/applications/jason-team/src/asl/dummy.asl
===================================================================
--- trunk/applications/jason-team/src/asl/dummy.asl 2008-04-21 12:59:17 UTC (rev 1235)
+++ trunk/applications/jason-team/src/asl/dummy.asl 2008-04-21 16:46:57 UTC (rev 1236)
@@ -6,7 +6,6 @@
gsize(Weight,Height)
steps(MaxSteps)
corral(UpperLeft.x,UpperLeft.y,DownRight.x,DownRight.y)
- pratio(Int) // ratio of perception of the agent
Step:
pos(X,Y,Step)
@@ -19,6 +18,11 @@
*/
+/* -- initial beliefs -- */
+
+ag_perception_ratio(8). // ratio of perception of the agent
+cow_perception_ratio(4).
+
/* -- useful rules */
// find a free random location
@@ -125,5 +129,4 @@
+corral(X1,Y1,X2,Y2) <- .println("corral = ",X1,",",Y1," -- ",X2,",",Y2).
//+cell(X,Y,Type) <- .println("cell = ",X,",",Y," = ",Type).
-+pratio(R) <- .println("pratio = ",R).
+pos(X,Y,S) <- .println("pos = ",X,",",Y,"/",S).
Modified: trunk/applications/jason-team/src/java/arch/ACArchitecture.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-04-21 12:59:17 UTC (rev 1235)
+++ trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-04-21 16:46:57 UTC (rev 1236)
@@ -11,6 +11,10 @@
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -24,6 +28,8 @@
*/
public class ACArchitecture extends CowboyArch {
+ public static final int actionTimeout = 1500; // timeout to send an action
+
private Logger logger;
private ACProxy proxy;
@@ -130,23 +136,29 @@
ActionExec lastAction;
String lastActionInCurrentCycle;
Queue<ActionExec> toExecute = new ConcurrentLinkedQueue<ActionExec>();
-
+ Lock lock = new ReentrantLock();
+ Condition cycle = lock.newCondition();
WaitSleep() {
super("WaitSpeepToSendAction");
}
- synchronized void addAction(ActionExec action) {
- if (lastAction != null)
- toExecute.offer(lastAction);
- lastAction = action;
+ void addAction(ActionExec action) {
+ lock.lock();
+ try {
+ if (lastAction != null)
+ toExecute.offer(lastAction);
+ lastAction = action;
+ } finally {
+ lock.unlock();
+ }
}
void newCycle() {
String w = "";
if (lastActionInCurrentCycle == null) {
+ addRestart();
w = "*** ";
- addRestart();
}
logger.info(w+"Last sent action was "+lastActionInCurrentCycle+" for cycle "+getCycle()+". The following was not sent: "+toExecute);
@@ -160,14 +172,25 @@
action.setResult(true);
feedback.add(action);
}
+ go(); // reset the wait
}
- synchronized void go() {
- notifyAll();
+ void go() {
+ lock.lock();
+ try {
+ cycle.signal();
+ } finally {
+ lock.unlock();
+ }
}
- synchronized void waitSleep() throws InterruptedException {
- // TODO: do something by timeout?
- wait();
+
+ boolean waitSleep() throws InterruptedException {
+ lock.lock();
+ try {
+ return !cycle.await(actionTimeout, TimeUnit.MILLISECONDS);
+ } finally {
+ lock.unlock();
+ }
}
@Override
@@ -175,7 +198,7 @@
while (true) {
try {
lastAction = null;
- waitSleep();
+ waitSleep();
if (lastAction != null) {
lastActionInCurrentCycle = lastAction.getActionTerm().getTerm(0).toString();
proxy.sendAction(lastActionInCurrentCycle);
Modified: trunk/applications/jason-team/src/java/arch/ACProxy.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/ACProxy.java 2008-04-21 12:59:17 UTC (rev 1235)
+++ trunk/applications/jason-team/src/java/arch/ACProxy.java 2008-04-21 16:46:57 UTC (rev 1236)
@@ -136,9 +136,6 @@
}
}
- int maxx = 0; // max value of some cell'x
-
-
public void processRequestAction(Element perception, long currenttime, long deadline) {
try {
List<Literal> percepts = new ArrayList<Literal>();
@@ -172,9 +169,6 @@
int absx = agx + cellx;
int absy = agy + celly;
- if (cellx > maxx)
- maxx = cellx;
-
NodeList cnl = cell.getChildNodes();
for (int j=0; j < cnl.getLength(); j++) {
if (cnl.item(j).getNodeType() == Element.ELEMENT_NODE && cellx != 0 && celly != 0) {
@@ -212,7 +206,6 @@
}
- arq.perceptionRatioPerceived(maxx);
arq.sendCowsToTeam();
arq.startNextStep(step, percepts);
Modified: trunk/applications/jason-team/src/java/arch/CowboyArch.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-04-21 12:59:17 UTC (rev 1235)
+++ trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-04-21 16:46:57 UTC (rev 1236)
@@ -13,6 +13,7 @@
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;
@@ -140,14 +141,6 @@
model.setMaxSteps(s);
}
- /** The perception ratio is discovered */
- void perceptionRatioPerceived(int s) throws RevisionFailedException {
- if (s != model.getPerceptionRatio()) {
- model.setPerceptionRatio(s);
- getTS().getAg().addBel(Literal.parseLiteral("pratio("+s+")"));
- }
- }
-
/** update the model with obstacle and share them with the team mates */
void obstaclePerceived(int x, int y, Literal p) {
if (! model.hasObject(WorldModel.OBSTACLE, x, y)) {
@@ -249,9 +242,22 @@
}
private static final Literal cowstoclean = Literal.parseLiteral("cell(_,_,cow(_))");
- synchronized void initKnownCows() throws RevisionFailedException {
+ private boolean cleanCows = false;
+
+ @Override
+ public synchronized void agDidPerceive() {
+ super.agDidPerceive();
+ if (cleanCows) {
+ try {
+ getTS().getAg().abolish(cowstoclean, null);
+ } catch (RevisionFailedException e) {}
+ cleanCows = false;
+ }
+ }
+
+ void initKnownCows() {
model.clearCows();
- getTS().getAg().abolish(cowstoclean, null);
+ cleanCows = true;
}
void cowPerceived(int x, int y) {
model.addCow(x,y);
@@ -259,7 +265,7 @@
void sendCowsToTeam() {
try {
- Message m = new Message("tell-cows", null, null, model.getCows());
+ Message m = new Message("tell-cows", null, null, new ArrayList<Location>(model.getCows()));
broadcast(m);
} catch (Exception e) {
e.printStackTrace();
@@ -303,7 +309,7 @@
@SuppressWarnings("unchecked")
@Override
- synchronized public void checkMail() {
+ public void checkMail() {
try {
super.checkMail();
Modified: trunk/applications/jason-team/src/java/arch/LocalWorldModel.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-04-21 12:59:17 UTC (rev 1235)
+++ trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-04-21 16:46:57 UTC (rev 1236)
@@ -203,7 +203,7 @@
/** removes enemies/gold around x,y */
public void clearAgView(int x, int y) {
- int r = getPerceptionRatio();
+ int r = agPerceptionRatio;
for (int c=x-r; c<=x+r; c++) {
for (int l=y-r; l<=y+r; l++) {
if (inGrid(c, l)) {
Modified: trunk/applications/jason-team/src/java/arch/WriteStatusThread.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/WriteStatusThread.java 2008-04-21 12:59:17 UTC (rev 1235)
+++ trunk/applications/jason-team/src/java/arch/WriteStatusThread.java 2008-04-21 16:46:57 UTC (rev 1236)
@@ -109,7 +109,7 @@
if (act.equals(WorldModel.Move.southwest.toString())) return "sw";
if (act.equals(WorldModel.Move.north.toString())) return "n ";
if (act.equals(WorldModel.Move.south.toString())) return "s ";
- if (act.equals(WorldModel.Move.skip.toString())) return "sk";
+ if (act.equals(WorldModel.Move.skip.toString())) return "--";
return act;
}
Modified: trunk/applications/jason-team/src/java/env/WorldModel.java
===================================================================
--- trunk/applications/jason-team/src/java/env/WorldModel.java 2008-04-21 12:59:17 UTC (rev 1235)
+++ trunk/applications/jason-team/src/java/env/WorldModel.java 2008-04-21 16:46:57 UTC (rev 1236)
@@ -21,7 +21,10 @@
public static final int nbActions = 8;
- public static final int agsByTeam = 6;
+ public static final int agsByTeam = 6;
+
+ public static final int agPerceptionRatio = 8;
+ public static final int cowPerceptionRatio = 4;
double PSim = 0.1; // probability of action/information failure
@@ -35,8 +38,6 @@
int maxSteps = 0; // number of steps of the simulation
- int pratio = -1; // perception ratio
-
private Logger logger = Logger.getLogger("jasonTeamSimLocal.mas2j." + WorldModel.class.getName());
public enum Move {
@@ -98,46 +99,6 @@
cowsRed = c;
}
- public void setPerceptionRatio(int r) {
- pratio = r;
- }
- public int getPerceptionRatio() {
- return pratio;
- }
-
- /*
- public boolean hasGold() {
- return countObjects(COW) > 0;
- }
-
- public boolean isAllGoldsCollected() {
- return goldsInDepotRed + goldsInDepotBlue == initialNbCows;
- }
-
- public void setInitialNbGolds(int i) {
- initialNbCows = i;
- }
-
- public int getInitialNbGolds() {
- return initialNbCows;
- }
-
- public boolean isCarryingGold(int ag) {
- return goldsWithAg[ag] > 0;
- }
-
- public boolean mayCarryMoreGold(int ag) {
- return goldsWithAg[ag] < AG_CAPACITY;
- }
-
- public int getGoldsWithAg(int ag) {
- return goldsWithAg[ag];
- }
- public void setGoldsWithAg(int ag, int n) {
- goldsWithAg[ag] = n;
- }
- */
-
public void setPSim(double psim) {
PSim = psim;
}
@@ -145,19 +106,6 @@
PMax = pmax;
}
- /** returns the probability of action/perception failure for an agent
- based on the number of golds it is carrying
- */
- /*
- public double getAgFatigue(int ag) {
- return getAgFatigue(ag, goldsWithAg[ag]);
- }
-
- public double getAgFatigue(int ag, int golds) {
- return PSim + ((PMax - PSim)/AG_CAPACITY) * golds;
- }
- */
-
public void setMaxSteps(int s) {
maxSteps = s;
}
Modified: trunk/applications/jason-team/src/java/jia/herd_position.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-21 12:59:17 UTC (rev 1235)
+++ trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-21 16:46:57 UTC (rev 1236)
@@ -45,11 +45,13 @@
if (arch.hasGUI())
setFormationLoc(model, Formation.valueOf(terms[0].toString()));
- Location agTarget = getAgTarget(model,Formation.valueOf(terms[0].toString()), agLoc);
+ Location agTarget = getAgTarget(model, Formation.valueOf(terms[0].toString()), agLoc);
if (agTarget != null) {
agTarget = nearFreeForAg(model, agLoc, agTarget);
return un.unifies(terms[1], new NumberTermImpl(agTarget.x)) &&
un.unifies(terms[2], new NumberTermImpl(agTarget.y));
+ } else {
+ ts.getLogger().info("No target! I am at "+agLoc+" places are "+formationPlaces(model, Formation.valueOf(terms[0].toString())));
}
} catch (Throwable e) {
ts.getLogger().log(Level.SEVERE, "herd_position error: "+e, e);
@@ -60,11 +62,11 @@
public Location getAgTarget(LocalWorldModel model, Formation formation, Location ag) throws Exception {
Location r = null;
List<Location> locs = formationPlaces(model, formation);
- if (locs != null) {
- for (Location l : locs) {
- r = l;
+ if (locs != null) {
+ for (Location l : locs) {
+ r = l;
if (ag.equals(l) || // I am there
- model.countObjInArea(WorldModel.AGENT, l, 1) == 0) { // someone else is there
+ model.countObjInArea(WorldModel.AGENT, l, 1) == 0) { // no one else is there
break;
}
}
Modified: trunk/applications/jason-team/todo.org
===================================================================
--- trunk/applications/jason-team/todo.org 2008-04-21 12:59:17 UTC (rev 1235)
+++ trunk/applications/jason-team/todo.org 2008-04-21 16:46:57 UTC (rev 1236)
@@ -1,20 +1,19 @@
-* faster simulator
-* DONE develop a team of dummies to play against
- CLOSED: [2008-04-20 Sun 22:23]
-** what is a dummy strategy?
-* base components
-** DONE Vectors (operations)
- CLOSED: [2008-04-20 Sun 22:23]
-* new scenarios
* team formations (moise+ representation of the team)
** Structure (we have something from the proposal)
** Functioning (we have noting, but I not sure we need...)
** computation of ideal locations of an agent to maintain a formation (can we use maintainance goal pattern?)
-* protocols
-* exploration strategy
- details
* herding strategy
details
+* exploration strategy
+ details
+* new scenarios
+* protocols
+* faster simulator
+* DONE Vectors (operations)
+ CLOSED: [2008-04-20 Sun 22:23]
+* DONE develop a team of dummies to play against
+ CLOSED: [2008-04-20 Sun 22:23]
+** what is a dummy strategy?
* DONE A* (update previous to new directions)
CLOSED: [2008-03-16 Sun 15:29]
* DONE integration with new simulator
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|