|
From: <jom...@us...> - 2009-06-16 18:56:47
|
Revision: 1496
http://jason.svn.sourceforge.net/jason/?rev=1496&view=rev
Author: jomifred
Date: 2009-06-16 18:56:41 +0000 (Tue, 16 Jun 2009)
Log Message:
-----------
add a second parameter in .random to setup the backtrack
Modified Paths:
--------------
trunk/applications/jason-moise/src/jmoise/OrgAgent.java
trunk/applications/jason-moise/src/jmoise/OrgManager.java
trunk/release-notes.txt
trunk/src/jason/asSyntax/Literal.java
trunk/src/jason/environment/Environment.java
trunk/src/jason/stdlib/random.java
Modified: trunk/applications/jason-moise/src/jmoise/OrgAgent.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2009-05-14 19:00:01 UTC (rev 1495)
+++ trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2009-06-16 18:56:41 UTC (rev 1496)
@@ -537,7 +537,7 @@
// goal states
private static final Atom aWaiting = new Atom("waiting");
- private static final Atom aPossible = new Atom("possible");
+ private static final Atom aReady = new Atom("ready");
private static final Atom aImpossible = new Atom("impossible");
private static final Atom aAchieved = new Atom("achieved");
@@ -549,9 +549,9 @@
}
Atom gState = aWaiting;
- if (gi.isPossible()) {
- gState = aPossible;
- } else if (gi.isAchieved()) {
+ if (gi.isReady()) {
+ gState = aReady;
+ } else if (gi.isSatisfied()) {
gState = aAchieved;
} else if (gi.isImpossible()) {
gState = aImpossible;
Modified: trunk/applications/jason-moise/src/jmoise/OrgManager.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/OrgManager.java 2009-05-14 19:00:01 UTC (rev 1495)
+++ trunk/applications/jason-moise/src/jmoise/OrgManager.java 2009-06-16 18:56:41 UTC (rev 1496)
@@ -489,7 +489,7 @@
}
if (state.equals("satisfied")) {
- gi.setSatisfied(sender);
+ gi.setAchieved(sender);
} else if (state.equals("impossible")) {
gi.setImpossible(sender);
}
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2009-05-14 19:00:01 UTC (rev 1495)
+++ trunk/release-notes.txt 2009-06-16 18:56:41 UTC (rev 1496)
@@ -5,8 +5,11 @@
New demo
- use of controllers to write a customised mind inspector
+Internal actions
+- .random has an optional second parameter to setup backtrack
+
Bugs fixed
-- foreach whe no solution exists causes failure
+- foreach when no solution exists causes failure
---------------------------
version 1.3
Modified: trunk/src/jason/asSyntax/Literal.java
===================================================================
--- trunk/src/jason/asSyntax/Literal.java 2009-05-14 19:00:01 UTC (rev 1495)
+++ trunk/src/jason/asSyntax/Literal.java 2009-06-16 18:56:41 UTC (rev 1496)
@@ -208,7 +208,7 @@
// pred
public void setAnnots(ListTerm l) { logger.log(Level.SEVERE, "setAnnots is not implemented in the class "+this.getClass().getSimpleName(), new Exception()); }
- public boolean addAnnot(Term t) { logger.log(Level.SEVERE, "addAnnot is not implemented in the class "+this.getClass().getSimpleName(), new Exception()); return false; }
+ public boolean addAnnot(Term t) { logger.log(Level.SEVERE, "addAnnot("+t+") is not implemented in the class "+this.getClass().getSimpleName()+" of object "+this, new Exception()); return false; }
/** adds some annots and return this */
public Literal addAnnots(Term ... terms) { logger.log(Level.SEVERE, "addAnnots is not implemented in the class "+this.getClass().getSimpleName(), new Exception()); return null; }
Modified: trunk/src/jason/environment/Environment.java
===================================================================
--- trunk/src/jason/environment/Environment.java 2009-05-14 19:00:01 UTC (rev 1495)
+++ trunk/src/jason/environment/Environment.java 2009-06-16 18:56:41 UTC (rev 1496)
@@ -71,7 +71,7 @@
protected ExecutorService executor; // the thread pool used to execute actions
- /** creates an environment class with n threads to execute actions requited by the agents */
+ /** creates an environment class with n threads to execute actions required by the agents */
public Environment(int n) {
// creates a thread pool with n threads
executor = Executors.newFixedThreadPool(n);
@@ -118,7 +118,7 @@
return environmentInfraTier;
}
- public Logger getLoger() {
+ public Logger getLogger() {
return logger;
}
@@ -324,7 +324,7 @@
}
/**
- * Execute an action on the environment. This method is probably overridden in the user environment class.
+ * Executes an action on the environment. This method is probably overridden in the user environment class.
*/
public boolean executeAction(String agName, Structure act) {
logger.info("The action "+act+" done by "+agName+" is not implemented in the default environment.");
Modified: trunk/src/jason/stdlib/random.java
===================================================================
--- trunk/src/jason/stdlib/random.java 2009-05-14 19:00:01 UTC (rev 1495)
+++ trunk/src/jason/stdlib/random.java 2009-06-16 18:56:41 UTC (rev 1496)
@@ -5,9 +5,11 @@
import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
+import jason.asSyntax.NumberTerm;
import jason.asSyntax.NumberTermImpl;
import jason.asSyntax.Term;
+import java.util.Iterator;
import java.util.Random;
/**
@@ -18,12 +20,15 @@
<p>Parameter:<ul>
<li>- value (number): the variable to receive the random value<br/>
+ <li><i>+ quantify of random numbers</i> (number, optional): default value is 1, value = 0 means that an infinify number of random numbers will be produced (this is useful for some backtrack circumstances).</li>
</ul>
<p>Example:<ul>
- <li><code>.random(X)</code>.</li>
+ <li><code>.random(X)</code>: unifies X with one random number between 0 and 1.</li>
+ <li><code>.random(X, 5)</code>: unifies X with a random number between 0 and 1, and backtracks 5 times. For example: .findall(X, .random(X,5), L) will produce a list of 5 random numbers.</li>
+ <li><code>.random(X, 0)</code>: unifies X with a random number between 0 and 1, and but backtracks infinitely.</li>
</ul>
@@ -42,18 +47,39 @@
private Random random = new Random();
@Override public int getMinArgs() { return 1; }
- @Override public int getMaxArgs() { return 1; }
+ @Override public int getMaxArgs() { return 2; }
@Override protected void checkArguments(Term[] args) throws JasonException {
super.checkArguments(args); // check number of arguments
- if (!args[0].isVar()) {
+ if (!args[0].isVar())
throw JasonException.createWrongArgument(this,"first argument must be a variable.");
- }
+ if (args.length == 2 && !args[1].isNumeric())
+ throw JasonException.createWrongArgument(this,"second argument must be a number.");
}
@Override
- public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ public Object execute(final TransitionSystem ts, final Unifier un, final Term[] args) throws Exception {
checkArguments(args);
- return un.unifies(args[0], new NumberTermImpl(random.nextDouble()));
+ if (args.length == 1) {
+ return un.unifies(args[0], new NumberTermImpl(random.nextDouble()));
+ } else {
+ final int max = (int)((NumberTerm)args[1]).solve();
+
+ return new Iterator<Unifier>() {
+ int n = 0;
+ // we always have a next random number
+ public boolean hasNext() {
+ return (n < max || max == 0) && ts.getUserAgArch().isRunning();
+ }
+ public Unifier next() {
+ Unifier c = un.clone();
+ c.unifies(args[0], new NumberTermImpl(random.nextDouble()));
+ n++;
+ return c;
+ }
+ public void remove() {}
+ };
+
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|