|
From: <jom...@us...> - 2009-03-31 13:51:50
|
Revision: 1480
http://jason.svn.sourceforge.net/jason/?rev=1480&view=rev
Author: jomifred
Date: 2009-03-31 13:51:43 +0000 (Tue, 31 Mar 2009)
Log Message:
-----------
fix problem in TimeSteepedEnvironment
bug reported by Francisco G. Moreno
Modified Paths:
--------------
trunk/examples/game-of-life/LifeEnvironment.java
trunk/release-notes.txt
trunk/src/jason/environment/TimeSteppedEnvironment.java
trunk/src/test/ListTermTest.java
Modified: trunk/examples/game-of-life/LifeEnvironment.java
===================================================================
--- trunk/examples/game-of-life/LifeEnvironment.java 2009-03-24 22:57:14 UTC (rev 1479)
+++ trunk/examples/game-of-life/LifeEnvironment.java 2009-03-31 13:51:43 UTC (rev 1480)
@@ -12,7 +12,6 @@
private Logger logger = Logger.getLogger("game-of-life.mas2j."+LifeEnvironment.class.getName());
private LifeModel model;
- private Literal lstep; // current step
/** Called before the MAS execution with the args informed in .mas2j */
@Override
@@ -43,7 +42,6 @@
@Override
protected void stepStarted(int step) {
//logger.info("start step "+step);
- lstep = ASSyntax.createLiteral("step", ASSyntax.createNumber(step+1));
}
private long sum = 0;
@@ -105,6 +103,6 @@
Literal lAlive = ASSyntax.createLiteral("alive_neighbors", ASSyntax.createNumber(alive));
addPercept(agName, lAlive);
- addPercept(agName, lstep);
+ addPercept(agName, ASSyntax.createLiteral("step", ASSyntax.createNumber(getStep())));
}
}
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2009-03-24 22:57:14 UTC (rev 1479)
+++ trunk/release-notes.txt 2009-03-31 13:51:43 UTC (rev 1480)
@@ -79,8 +79,8 @@
- Some concurrent execution of .wait and .drop_desire/intention
does not work (the intention isn't dropped)
- send askHow with 4th argument blocks the intention
+- TimeSteepedEnvironment wait timeout when it is not required to wait
-
---------------------------
version 1.2
the 5th Anniversary Release
Modified: trunk/src/jason/environment/TimeSteppedEnvironment.java
===================================================================
--- trunk/src/jason/environment/TimeSteppedEnvironment.java 2009-03-24 22:57:14 UTC (rev 1479)
+++ trunk/src/jason/environment/TimeSteppedEnvironment.java 2009-03-31 13:51:43 UTC (rev 1480)
@@ -125,6 +125,8 @@
@Override
public void scheduleAction(String agName, Structure action, Object infraData) {
if (!isRunning()) return;
+
+ //System.out.println("scheduling "+action+" for "+agName);
ActRequest newRequest = new ActRequest(agName, action, requiredStepsForAction(agName, action), infraData);
boolean startNew = false;
@@ -170,13 +172,10 @@
}
if (startNew) {
- // starts the execution of the next step by another thread, so to not look the agent thread
- executor.execute(new Runnable() {
- public void run() {
- if (timeoutThread != null) timeoutThread.allAgFinished();
- startNewStep();
- }
- });
+ if (timeoutThread != null)
+ timeoutThread.allAgFinished();
+ else
+ startNewStep();
}
}
@@ -204,7 +203,9 @@
private void startNewStep() {
if (!isRunning()) return;
+
synchronized (requests) {
+ step++;
//logger.info("#"+requests.size());
//logger.info("#"+overRequests.size());
@@ -250,15 +251,14 @@
if (testEndCycle(requests.keySet())) {
startNewStep();
}
+
+ stepStarted(step);
} catch (Exception ie) {
if (isRunning() && !(ie instanceof InterruptedException)) {
logger.log(Level.WARNING, "act error!",ie);
}
}
-
}
- step++;
- stepStarted(step);
}
/** to be overridden by the user class */
@@ -308,6 +308,7 @@
Lock lock = new ReentrantLock();
Condition agActCond = lock.newCondition();
long timeout = 0;
+ boolean allFinished = false;
public TimeOutThread(long to) {
super("EnvironmentTimeOutThread");
@@ -316,6 +317,7 @@
public void allAgFinished() {
lock.lock();
+ allFinished = true;
agActCond.signal();
lock.unlock();
}
@@ -325,15 +327,16 @@
while (true) {
lock.lock();
long lastStepStart = System.currentTimeMillis();
- boolean byTimeOut = !agActCond.await(timeout, TimeUnit.MILLISECONDS);
+ boolean byTimeOut = false;
+ if (!allFinished) {
+ byTimeOut = !agActCond.await(timeout, TimeUnit.MILLISECONDS);
+ }
+ allFinished = false;
long now = System.currentTimeMillis();
long time = (now-lastStepStart);
stepFinished(step, time, byTimeOut);
lock.unlock();
-
- if (byTimeOut) {
- startNewStep();
- }
+ startNewStep();
}
} catch (InterruptedException e) {
} catch (Exception e) {
Modified: trunk/src/test/ListTermTest.java
===================================================================
--- trunk/src/test/ListTermTest.java 2009-03-24 22:57:14 UTC (rev 1479)
+++ trunk/src/test/ListTermTest.java 2009-03-31 13:51:43 UTC (rev 1480)
@@ -234,6 +234,29 @@
assertEquals("d",a[a.length-1].toString());
}
+ public void testListIterator() {
+ StringBuilder s = new StringBuilder();
+ ListTerm l = l1;
+ while (! l.isEnd()) {
+ s.append(l.toString());
+ l = l.getNext();
+ }
+ s.append(l.toString());
+ assertEquals("[a,b,c][b,c][c][]",s.toString());
+
+ s = new StringBuilder();
+ l = l2;
+ while (! l.isEnd()) {
+ s.append(l.toString());
+ l = l.getNext();
+ }
+ s.append(l.toString());
+ if (l.isTail())
+ s.append(l.getTail());
+ System.out.println(s);
+ assertEquals("[a(1,2),b(r,t)|T][b(r,t)|T]T",s.toString());
+ }
+
public void testReverse() {
ListTerm l = ListTermImpl.parseList("[]");
assertEquals(l, l.reverse());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|