|
From: <jom...@us...> - 2008-06-08 09:36:54
|
Revision: 1326
http://jason.svn.sourceforge.net/jason/?rev=1326&view=rev
Author: jomifred
Date: 2008-06-08 02:36:47 -0700 (Sun, 08 Jun 2008)
Log Message:
-----------
improve documentation of new internal actions
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/tests/TestLoop.java
trunk/applications/jason-team/readme.txt
trunk/applications/jason-team/src/java/arch/CowboyArch.java
trunk/demos/suspend-resume/test.asl
trunk/examples/auction/AuctioneerGUI.java
trunk/release-notes.txt
trunk/src/jason/asSemantics/Agent.java
trunk/src/jason/asSyntax/ListTermImpl.java
trunk/src/jason/stdlib/conditional.java
trunk/src/jason/stdlib/foreach.java
trunk/src/jason/stdlib/loop.java
trunk/src/jason/stdlib/member.java
trunk/src/jason/stdlib/package.html
trunk/src/jason/stdlib/random.java
Added Paths:
-----------
trunk/src/jason/stdlib/range.java
Modified: trunk/applications/as-unit-test/src/jason/tests/TestLoop.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestLoop.java 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/applications/as-unit-test/src/jason/tests/TestLoop.java 2008-06-08 09:36:47 UTC (rev 1326)
@@ -24,7 +24,9 @@
"+!test3 <- L=4; for( p(N,a) & N < L) { jason.asunit.print(N) }; jason.asunit.print(end). "+
- "+!test4 <- for( .member(N, [1,3,4]), { jason.asunit.print(N) }); jason.asunit.print(end). "
+ "+!test4 <- for( .member(N, [1,3,4]), { jason.asunit.print(N) }); jason.asunit.print(end). " +
+
+ "+!test5 <- for( .range(I, 1, 4), { jason.asunit.print(I) }); jason.asunit.print(end). "
);
}
@@ -53,4 +55,14 @@
ag.assertPrint("4", 10);
ag.assertPrint("end", 10);
}
+
+ @Test
+ public void testFor3() {
+ ag.addGoal("test5");
+ ag.assertPrint("1", 4);
+ ag.assertPrint("2", 4);
+ ag.assertPrint("3", 4);
+ ag.assertPrint("4", 4);
+ ag.assertPrint("end", 10);
+ }
}
Modified: trunk/applications/jason-team/readme.txt
===================================================================
--- trunk/applications/jason-team/readme.txt 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/applications/jason-team/readme.txt 2008-06-08 09:36:47 UTC (rev 1326)
@@ -10,35 +10,32 @@
*/
-To run this team:
+To run this team Jason 1.1.2 is required.
+
+Steps:
-1. update sources of Jason and JMoise+
- cd Jason-svn
- svn update
- ant plugin
-
-2. run massim-server
- cd applications/jason-team/massim-server
+1. run massim-server
+ cd massim-server
./startServer.sh
or some configuration for test
./startServerTest.sh conf/<some conf file>.xml
-3. run dummies (written in Jason)
+2. run dummies (written in Jason)
ant -f dummies.xml
or those written by the Contest developers
cd ../massim-agents
./startAgents.sh
-4. run Jason team
+3. run Jason team
ant -f gauchos.xml
-5. start the simulation
+4. start the simulation
go to shell running startServer.sh and press ENTER
-6. you can get the agents location with the command
+5. you can get the agents location with the command
tail -f world-status.txt
@@ -46,9 +43,9 @@
ant -f gauchos.xml mind-view
- or in the files stored in directory mind-ag-gaucho1
+ or in the files stored in directory mind-ag
-7. to enable/disable the graphical view of some agent, add gui=yes
+6. to enable/disable the graphical view of some agent, add gui=yes
or gui=no in the agent's option (.mas2j file)
Modified: trunk/applications/jason-team/src/java/arch/CowboyArch.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-06-08 09:36:47 UTC (rev 1326)
@@ -29,7 +29,7 @@
*
* @author Jomi
*/
-public class CowboyArch extends IdentifyCrashed { //IdentifyCrashed OrgAgent{
+public class CowboyArch extends IdentifyCrashed {
LocalWorldModel model = null;
WorldView view = null;
Modified: trunk/demos/suspend-resume/test.asl
===================================================================
--- trunk/demos/suspend-resume/test.asl 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/demos/suspend-resume/test.asl 2008-06-08 09:36:47 UTC (rev 1326)
@@ -10,13 +10,13 @@
// loop printing dots
+!dots
<- .print(".");
- !!dots.
+ !!dots.
// another loop that resumes and suspend the start
+!control
<- .wait(30);
.suspend(dots); // suspend the intention with goal dots
- .println;
+ .println;
.wait(200);
- .resume(dots); // resume it
- !!control.
+ .resume(dots); // resume it
+ !!control.
Modified: trunk/examples/auction/AuctioneerGUI.java
===================================================================
--- trunk/examples/auction/AuctioneerGUI.java 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/examples/auction/AuctioneerGUI.java 2008-06-08 09:36:47 UTC (rev 1326)
@@ -14,16 +14,18 @@
JTextArea jt;
JFrame f;
-
+ JButton auction;
+
int auctionId = 0;
public AuctioneerGUI() {
jt = new JTextArea(10, 30);
- JButton auction = new JButton("Start new auction");
+ auction = new JButton("Start new auction");
auction.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
auctionId++;
getTS().getC().addAchvGoal(Literal.parseLiteral("start_auction("+auctionId+")"), null);
+ auction.setEnabled(false);
}
});
@@ -39,6 +41,7 @@
if (action.getActionTerm().getFunctor().startsWith("show_winner")) {
jt.append("Winner of auction " + action.getActionTerm().getTerm(0));
jt.append(" is " + action.getActionTerm().getTerm(1) + "\n");
+ auction.setEnabled(true);
}
super.act(action,feedback); // send the action to the environment to be performed.
}
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/release-notes.txt 2008-06-08 09:36:47 UTC (rev 1326)
@@ -6,45 +6,56 @@
. (experimental) control of the execution in plan's body with if, while
and for.
- if ( <expression> ) {
+ --- if ----
+ syntax:
+
+ if ( <logical formula> ) {
<plan_body1>
- [ } else { <plan_body2> }
+ [ } else { <plan_body2> ]
};
- if <expression> is true, <plan_body1> is executed; otherwise,
+ if <logical formula> holds, <plan_body1> is executed; otherwise,
<plan_body2> is executed.
- e.g.: if (vl(X) & X > 10) {
+ e.g.: if (vl(X) & X > 10) { // where vl(X) is a belief
.print("value > 10")
}
+ --- while ---
+ syntax:
- while ( <expression> ) {
+ while ( <logical formula> ) {
<plan_body>
};
- while <expression> is true, the <plan_body> is executed.
+ while <logical formula> holds, the <plan_body> is executed.
e.g.: while (vl(X) & X > 10) {
- -+vl(X+1);
+ -+vl(X+1)
}
- for ( <expression> ) {
+ --- for ---
+ syntax:
+
+ for ( <logical formula> ) {
<plan_body>
};
- for all unifications of <expression> the <plan_body> is executed.
+ for all unifications of <logical formula> the <plan_body> is executed.
e.g.: for ( vl(X) ) {
- .print(X);
+ .print(X)
};
for ( .member(X,[a,b,c]) ) {
- .print(X);
+ .print(X)
};
+ for ( .range(I,1,10) ) {
+ .print(I) // print all values from 1 to 10
+ };
New examples and demos:
-. demos/gui: two simple example of how to make a GUI for agents
+. demos/gui: two simple examples of how to make a GUI for agents
. example/food-simulation: implementation of the scenario of simulation
presented in http://jasss.soc.surrey.ac.uk/1/3/3.html
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/src/jason/asSemantics/Agent.java 2008-06-08 09:36:47 UTC (rev 1326)
@@ -648,8 +648,7 @@
Literal inBB = il.next();
if (!inBB.isRule()) {
// need to clone unifier since it is changed in previous iteration
- Unifier unC = un.copy();
- if (unC.unifiesNoUndo(bel, inBB)) {
+ if (un.copy().unifiesNoUndo(bel, inBB)) {
toDel.add(inBB);
}
}
Modified: trunk/src/jason/asSyntax/ListTermImpl.java
===================================================================
--- trunk/src/jason/asSyntax/ListTermImpl.java 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/src/jason/asSyntax/ListTermImpl.java 2008-06-08 09:36:47 UTC (rev 1326)
@@ -344,6 +344,7 @@
return result;
}
+
/** returns an iterator where each element is a ListTerm */
public Iterator<ListTerm> listTermIterator() {
final ListTermImpl lt = this;
Modified: trunk/src/jason/stdlib/conditional.java
===================================================================
--- trunk/src/jason/stdlib/conditional.java 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/src/jason/stdlib/conditional.java 2008-06-08 09:36:47 UTC (rev 1326)
@@ -35,7 +35,34 @@
import jason.asSyntax.PlanBody;
import jason.asSyntax.Term;
-/** Implementation of if (see manual for more information) */
+/**
+Implementation of <b>if</b>.
+
+<p>Syntax:
+<pre>
+ if ( <i>logical formula</i> ) {
+ <i>plan_body1</i>
+ [ } else { <i>plan_body2</i> ]
+ };
+</pre>
+</p>
+
+<p>if <i>logical formula</i> holds, <i>plan_body1</i> is executed;
+otherwise, <i>plan_body2</i> is executed.</p>
+
+<p>Example:
+<pre>
++event : context
+ <- ....
+ if (vl(X) & X > 10) { // where vl(X) is a belief
+ .print("value > 10")
+ };
+ ....
+</pre>
+The unification is changed by the evaluation of the logical formula, i.e., X might have a value after if.
+</p>
+
+*/
public class conditional extends DefaultInternalAction {
private static InternalAction singleton = null;
@@ -49,7 +76,7 @@
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
if ( !(args[0] instanceof LogicalFormula))
- throw new JasonException("The first argument of .if must be a logical formula.");
+ throw new JasonException("The first argument of if must be a logical formula.");
LogicalFormula logExpr = (LogicalFormula)args[0];
PlanBody whattoadd = null;
@@ -57,12 +84,12 @@
Iterator<Unifier> iu = logExpr.logicalConsequence(ts.getAg(), un);
if (iu.hasNext()) { // .if THEN
if ( !args[1].isPlanBody())
- throw new JasonException("The second argument of .if must be a plan body term.");
+ throw new JasonException("The second argument of if must be a plan body term.");
whattoadd = (PlanBody)args[1];
un.compose(iu.next());
} else if (args.length == 3) { // .if ELSE
if ( !args[2].isPlanBody())
- throw new JasonException("The third argument of .if must be a plan body term.");
+ throw new JasonException("The third argument of if must be a plan body term.");
whattoadd = (PlanBody)args[2];
}
@@ -74,11 +101,11 @@
}
return true;
} catch (ArrayIndexOutOfBoundsException e) {
- throw new JasonException("The internal action 'if' has not received the required arguments.");
+ throw new JasonException("The 'if' has not received the required arguments.");
} catch (JasonException e) {
- throw e;
+ throw e;
} catch (Exception e) {
- throw new JasonException("Error in internal action 'if': " + e, e);
+ throw new JasonException("Error in 'if': " + e, e);
}
}
}
Modified: trunk/src/jason/stdlib/foreach.java
===================================================================
--- trunk/src/jason/stdlib/foreach.java 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/src/jason/stdlib/foreach.java 2008-06-08 09:36:47 UTC (rev 1326)
@@ -42,7 +42,42 @@
import java.util.Iterator;
import java.util.List;
-/** Implementation of for (see manual for more information) */
+/**
+Implementation of <b>for</b>.
+
+<p>Syntax:
+<pre>
+ for ( <i>logical formula</i> ) {
+ <i>plan_body</i>
+ };
+</pre>
+</p>
+
+<p>for all unifications of <i>logical formula</i>, the <i>plan_body</i> is executed.</p>
+
+<p>Example:
+<pre>
++event : context
+ <- ....
+ for ( vl(X) ) {
+ .print(X) // print all values of X
+ };
+ for ( .member(X,[a,b,c]) ) {
+ .print(X) // print all members of the list
+ };
+ for ( .range(I,1,10) ) {
+ .print(I) // print all values from 1 to 10
+ };
+ ....
+</pre>
+The unification resulted from the evaluation of the logical formula is used only inside the loop,
+i.e., the unification after the for is the same as before.
+</p>
+
+@see jason.stdlib.loop while
+
+*/
+
public class foreach extends DefaultInternalAction {
private static InternalAction singleton = null;
@@ -64,9 +99,9 @@
if (args.length != 3) {
// first execution of while
if ( !(args[0] instanceof LogicalFormula))
- throw new JasonException("The first argument of .for must be a logical formula.");
+ throw new JasonException("The first argument of for must be a logical formula.");
if ( !args[1].isPlanBody())
- throw new JasonException("The second argument of .for must be a plan body term.");
+ throw new JasonException("The second argument of for must be a plan body term.");
// get all solutions for the loop
// Note: you should get all solutions here, otherwise I concurrent modification will occur for the iterator
@@ -93,11 +128,11 @@
}
return true;
} catch (ArrayIndexOutOfBoundsException e) {
- throw new JasonException("The internal action 'for' has not received the required arguments.");
+ throw new JasonException("'for' has not received the required arguments.");
} catch (JasonException e) {
throw e;
} catch (Exception e) {
- throw new JasonException("Error in internal action 'for': " + e, e);
+ throw new JasonException("Error in 'for': " + e, e);
}
}
}
Modified: trunk/src/jason/stdlib/loop.java
===================================================================
--- trunk/src/jason/stdlib/loop.java 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/src/jason/stdlib/loop.java 2008-06-08 09:36:47 UTC (rev 1326)
@@ -40,7 +40,36 @@
import java.util.Iterator;
-/** Implementation of while (see manual for more information) */
+/**
+Implementation of <b>while</b>.
+
+<p>Syntax:
+<pre>
+ while ( <i>logical formula</i> ) {
+ <i>plan_body</i>
+ };
+</pre>
+</p>
+
+<p>while <i>logical formula</i> holds, the <i>plan_body</i> is executed.</p>
+
+<p>Example:
+<pre>
++event : context
+ <- ....
+ while(vl(X) & X > 10) { // where vl(X) is a belief
+ .print("value > 10");
+ -+vl(X+1)
+ };
+ ....
+</pre>
+The unification resulted from the evaluation of the logical formula is used only inside the loop,
+i.e., the unification after the while is the same as before.
+</p>
+
+@see jason.stdlib.foreach for
+
+*/
public class loop extends DefaultInternalAction {
private static InternalAction singleton = null;
@@ -63,9 +92,9 @@
if (args.length != 3) {
// first execution of while
if ( !(args[0] instanceof LogicalFormula))
- throw new JasonException("The first argument of .while must be a logical formula.");
+ throw new JasonException("The first argument of while must be a logical formula.");
if ( !args[1].isPlanBody())
- throw new JasonException("The second argument of .while must be a plan body term.");
+ throw new JasonException("The second argument of while must be a plan body term.");
// add backup unifier in the IA
((Structure)whileia.getBodyTerm()).addTerm(new ObjectTermImpl(un.clone()));
@@ -91,11 +120,11 @@
}
return true;
} catch (ArrayIndexOutOfBoundsException e) {
- throw new JasonException("The internal action 'while' has not received the required arguments.");
+ throw new JasonException("'while' has not received the required arguments.");
} catch (JasonException e) {
throw e;
} catch (Exception e) {
- throw new JasonException("Error in internal action 'while': " + e, e);
+ throw new JasonException("Error in 'while': " + e, e);
}
}
}
Modified: trunk/src/jason/stdlib/member.java
===================================================================
--- trunk/src/jason/stdlib/member.java 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/src/jason/stdlib/member.java 2008-06-08 09:36:47 UTC (rev 1326)
@@ -83,7 +83,7 @@
void find() {
while (i.hasNext()) {
- c = (Unifier)un.clone();
+ c = un.copy();
if (c.unifiesNoUndo(member, i.next()))
return; // member found in the list, c is the current response
}
@@ -108,6 +108,8 @@
*/
} catch (ArrayIndexOutOfBoundsException e) {
throw new JasonException("The internal action 'member' has not received two arguments.");
+ } catch (JasonException e) {
+ throw e;
} catch (Exception e) {
throw new JasonException("Error in internal action 'member': " + e, e);
}
Modified: trunk/src/jason/stdlib/package.html
===================================================================
--- trunk/src/jason/stdlib/package.html 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/src/jason/stdlib/package.html 2008-06-08 09:36:47 UTC (rev 1326)
@@ -53,7 +53,7 @@
</ul>
-<h2>List</h2>
+<h2>Lists and Sets</h2>
<ul>
<li>{@link jason.stdlib.member}: list members. </li>
<li>{@link jason.stdlib.length}: size of lists. </li>
@@ -61,16 +61,17 @@
<li>{@link jason.stdlib.concat}: concat lists. </li>
<li>{@link jason.stdlib.delete}: delete members of a lists. </li>
- <li>{@link jason.stdlib.difference}: difference of sets. </li>
- <li>{@link jason.stdlib.intersection}: intersection of sets. </li>
- <li>{@link jason.stdlib.union}: union of sets. </li>
-
<li>{@link jason.stdlib.reverse}: reverse lists. </li>
<li>{@link jason.stdlib.nth}: nth element of a lists. </li>
<li>{@link jason.stdlib.max}: maximum value of a lists. </li>
<li>{@link jason.stdlib.min}: minimum value of a lists. </li>
<li>{@link jason.stdlib.sort}: sort lists. </li>
<li>{@link jason.stdlib.list}: check whether an argument is a list.</li>
+
+ <li>{@link jason.stdlib.difference}: difference of sets. </li>
+ <li>{@link jason.stdlib.intersection}: intersection of sets. </li>
+ <li>{@link jason.stdlib.union}: union of sets. </li>
+
</ul>
@@ -84,6 +85,14 @@
<li>{@link jason.stdlib.string}: check whether an argument is a string.</li>
</ul>
+<h2>Execution control</h2>
+<ul>
+ <li>{@link jason.stdlib.conditional}: implementation of <b>if</b>.</li>
+ <li>{@link jason.stdlib.loop}: implementation of <b>while</b>.</li>
+ <li>{@link jason.stdlib.foreach}: implementation of <b>for</b>.</li>
+</ul>
+
+
<h2>Meta programming</h2>
<ul>
<li>{@link jason.stdlib.atom}: check whether an argument is an atom.</li>
@@ -111,17 +120,8 @@
<li>{@link jason.stdlib.time}: get the current time.</li>
<li>{@link jason.stdlib.fail}: an action that always fails.</li>
<li>{@link jason.stdlib.perceive}: force perception.</li>
+ <li>{@link jason.stdlib.range}: backtrack values in a range (used in <b>for</b>).</li>
</ul>
-
-<!--h2>Related Documentation</h2>
-
-For overviews, tutorials, examples, guides, and tool documentation, please see:
-<ul>
- <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
-</ul>
-
--->
-
</body>
</html>
Modified: trunk/src/jason/stdlib/random.java
===================================================================
--- trunk/src/jason/stdlib/random.java 2008-06-06 17:12:25 UTC (rev 1325)
+++ trunk/src/jason/stdlib/random.java 2008-06-08 09:36:47 UTC (rev 1326)
@@ -27,6 +27,8 @@
</ul>
+ @see jason.functions.Random function version
+
*/
public class random extends DefaultInternalAction {
Added: trunk/src/jason/stdlib/range.java
===================================================================
--- trunk/src/jason/stdlib/range.java (rev 0)
+++ trunk/src/jason/stdlib/range.java 2008-06-08 09:36:47 UTC (rev 1326)
@@ -0,0 +1,91 @@
+package jason.stdlib;
+
+import jason.JasonException;
+import jason.asSemantics.DefaultInternalAction;
+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;
+
+/**
+
+ <p>Internal action: <b><code>.range(<i>Var</i>,<i>Start</i>,<i>End</i>)</code></b>.
+
+ <p>Description: backtrack all values for <i>Var</i> starting at <i>Start</i>
+ and finishing at <i>End</i>.
+
+ <p>Parameters:<ul>
+
+ <li>+/- var (Variable): the variable that unifies with all values.</li>
+ <li>+ start (number): initial value.</li>
+ <li>+ end (number): last value.</li>
+
+ </ul>
+
+ <p>Examples:<ul>
+
+ <li> <code>.range(3,1,5)</code>: true.</li>
+ <li> <code>.range(6,1,5)</code>: false.</li>
+ <li> <code>.range(X,1,5)</code>: unifies X with 1, 2, 3, 4, and 5.</li>
+
+ </ul>
+
+ @see jason.stdlib.foreach for
+*/
+public class range extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new range();
+ return singleton;
+ }
+
+ @Override
+ public Object execute(TransitionSystem ts, final Unifier un, Term[] args) throws Exception {
+ try {
+ if (!args[1].isNumeric())
+ throw new JasonException("The second parameter ('" + args[1] + "') to the internal action 'range' is not a number!");
+ if (!args[2].isNumeric())
+ throw new JasonException("The third parameter ('" + args[1] + "') to the internal action 'range' is not a number!");
+
+ final int start = (int)((NumberTerm)args[1]).solve();
+ final int end = (int)((NumberTerm)args[2]).solve();
+ if (!args[0].isVar()) {
+ // first arg is not a var
+ int vl = (int)((NumberTerm)args[0]).solve();
+ return vl >= start && vl <= end;
+ } else {
+ // first arg is a var, backtrack
+ final Term var = args[0];
+
+ return new Iterator<Unifier>() {
+ int vl = start-1;
+
+ public boolean hasNext() {
+ return vl < end;
+ }
+
+ public Unifier next() {
+ vl++;
+ Unifier c = un.copy();
+ c.unifiesNoUndo(var,new NumberTermImpl(vl));
+ return c;
+ }
+
+ public void remove() {}
+ };
+ }
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new JasonException("The internal action 'range' has not received two arguments.");
+ } catch (JasonException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new JasonException("Error in internal action 'range': " + e, e);
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|