|
From: <jom...@us...> - 2008-05-25 18:26:43
|
Revision: 1307
http://jason.svn.sourceforge.net/jason/?rev=1307&view=rev
Author: jomifred
Date: 2008-05-25 11:26:39 -0700 (Sun, 25 May 2008)
Log Message:
-----------
jason team: final changes!
Modified Paths:
--------------
trunk/applications/jason-team/contest.xml
trunk/applications/jason-team/src/java/agent/UniqueBelsBB.java
trunk/applications/jason-team/src/java/arch/ACArchitecture.java
trunk/applications/jason-team/src/java/arch/CowboyArch.java
trunk/applications/jason-team/src/java/jia/herd_position.java
trunk/src/jason/asSemantics/Agent.java
Modified: trunk/applications/jason-team/contest.xml
===================================================================
--- trunk/applications/jason-team/contest.xml 2008-05-25 13:45:14 UTC (rev 1306)
+++ trunk/applications/jason-team/contest.xml 2008-05-25 18:26:39 UTC (rev 1307)
@@ -29,8 +29,7 @@
<target name="user-init">
<ant antfile="../jason-moise/build.xml" target="jar" inheritall="false" />
<copy file="../jason-moise/lib/jmoise.jar" todir="lib" />
- <copy file="../jason-moise/lib/moise.jar" todir="lib" />
- <mkdir dir="tmp-ag-mind" />
+ <copy file="../jason-moise/lib/moise.jar" todir="lib" />
</target>
<target name="user-end">
</target>
@@ -50,6 +49,9 @@
</target>
<target name="run" depends="compile" >
+ <delete failonerror="no" includeEmptyDirs="true" verbose="false">
+ <fileset dir="mind-ag" includes="**/*.xml"/>
+ </delete>
<echo message="Running project ${ant.project.name}" />
<java classname="jason.infra.centralised.RunCentralisedMAS"
failonerror="true" fork="yes" dir="${basedir}" >
Modified: trunk/applications/jason-team/src/java/agent/UniqueBelsBB.java
===================================================================
--- trunk/applications/jason-team/src/java/agent/UniqueBelsBB.java 2008-05-25 13:45:14 UTC (rev 1306)
+++ trunk/applications/jason-team/src/java/agent/UniqueBelsBB.java 2008-05-25 18:26:39 UTC (rev 1307)
@@ -97,8 +97,12 @@
if (t.isStructure()) {
Structure s = (Structure)t;
if (s.getFunctor().equals(timeAnnot)) {
- if (bTime == null || bTime.compareTo(s) < 0)
+ if (bTime == null) {
bTime = s;
+ } else if (bTime.compareTo(s) < 0) {
+ linbb.delAnnot(bTime); // remove old time annot
+ bTime = s;
+ }
}
}
}
Modified: trunk/applications/jason-team/src/java/arch/ACArchitecture.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-05-25 13:45:14 UTC (rev 1306)
+++ trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-05-25 18:26:39 UTC (rev 1307)
@@ -67,7 +67,7 @@
@Override
public List<Literal> perceive() {
- agDidPerceive(); // for crash control
+ /* agDidPerceive(); // for crash control */
return new ArrayList<Literal>(percepts); // it must be a copy!
}
Modified: trunk/applications/jason-team/src/java/arch/CowboyArch.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-05-25 13:45:14 UTC (rev 1306)
+++ trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-05-25 18:26:39 UTC (rev 1307)
@@ -3,6 +3,7 @@
import jason.JasonException;
import jason.ReceiverNotFoundException;
import jason.RevisionFailedException;
+import jason.architecture.AgArch;
import jason.asSemantics.Intention;
import jason.asSemantics.Message;
import jason.asSyntax.Atom;
@@ -28,7 +29,7 @@
*
* @author Jomi
*/
-public class CowboyArch extends IdentifyCrashed {
+public class CowboyArch extends AgArch { //IdentifyCrashed {
LocalWorldModel model = null;
WorldView view = null;
@@ -77,11 +78,13 @@
if (writeStatusThread != null) writeStatusThread.interrupt();
super.stopAg();
}
-
+
+ /*
@Override
public boolean isCrashed() {
return playing && super.isCrashed();
}
+ */
void setSimId(String id) {
simId = id;
Modified: trunk/applications/jason-team/src/java/jia/herd_position.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/herd_position.java 2008-05-25 13:45:14 UTC (rev 1306)
+++ trunk/applications/jason-team/src/java/jia/herd_position.java 2008-05-25 18:26:39 UTC (rev 1307)
@@ -197,11 +197,10 @@
t = t.newAngle(t.angle()+direction.angle());
//System.out.println(start + " to "+ direction + " = " + end);
- Location l = start.add(ref).getLocation(model);
- //Location lastloc = null;
int maxSize = (int)direction.magnitude();
- l = t.newMagnitude(maxSize).add(startandref).getLocation(model);
- /*
+ Location l = t.newMagnitude(maxSize).add(startandref).getLocation(model);
+
+ Location lastloc = null;
for (int s = 1; s <= maxSize; s++) {
l = t.newMagnitude(s).add(startandref).getLocation(model);
//System.out.println(" test "+s+" = "+l+" -- ");
@@ -209,7 +208,7 @@
return lastloc;
lastloc = l;
}
- */
+
return l;
}
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2008-05-25 13:45:14 UTC (rev 1306)
+++ trunk/src/jason/asSemantics/Agent.java 2008-05-25 18:26:39 UTC (rev 1307)
@@ -457,7 +457,11 @@
// if perception t is already in BB
if (l.equalsAsStructure(t) && l.negated() == t.negated()) {
wasPerceived = true;
- // ip.remove(); // remove in percepts, since it already is in BB [can not be removed, since annots in this percepts should be added in BB/Jason team for AC, for example, use annots in perceptions]
+ // remove in percepts, since it already is in BB
+ // [can not be always removed, since annots in this percepts should be added in BB
+ // Jason team for AC, for example, use annots in perceptions]
+ if (!l.hasAnnot())
+ ip.remove();
break;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-05-31 10:47:14
|
Revision: 1318
http://jason.svn.sourceforge.net/jason/?rev=1318&view=rev
Author: jomifred
Date: 2008-05-31 03:47:10 -0700 (Sat, 31 May 2008)
Log Message:
-----------
jason team: remove monitor
Modified Paths:
--------------
trunk/src/jason/stdlib/conditional.java
trunk/src/jason/stdlib/foreach.java
trunk/src/jason/stdlib/loop.java
Added Paths:
-----------
trunk/src/jason/asSemantics/SynchronousInternalAction.java
Removed Paths:
-------------
trunk/applications/jason-team/massim-servermonitor/
Added: trunk/src/jason/asSemantics/SynchronousInternalAction.java
===================================================================
--- trunk/src/jason/asSemantics/SynchronousInternalAction.java (rev 0)
+++ trunk/src/jason/asSemantics/SynchronousInternalAction.java 2008-05-31 10:47:10 UTC (rev 1318)
@@ -0,0 +1,99 @@
+package jason.asSemantics;
+
+import jason.asSemantics.Circumstance;
+import jason.asSemantics.Intention;
+import jason.asSemantics.InternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSyntax.InternalActionLiteral;
+import jason.asSyntax.PlanBody;
+import jason.asSyntax.PlanBodyImpl;
+import jason.asSyntax.PlanBody.BodyType;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+
+ This class can be used in place of DefaultInternalAction to create synchronous IA.
+
+ A sync. IA is one that suspend the intention that uses it until some event.
+
+ Example: a plan should to ask something to an user and wait until he/she answer some.
+ If DefaultInternalAction is used for that, all the agent thread is suspended until
+ the answer. With SynchronousInternalAction, only the intention using the IA is
+ suspended. See demos/gui/gui1.
+
+ @author jomi
+*/
+public abstract class SynchronousInternalAction implements InternalAction {
+
+ protected ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
+ private static int actcount = 0;
+
+ public boolean canBeUsedInContext() {
+ return false;
+ }
+
+ public boolean suspendIntention() {
+ return true;
+ }
+
+ /**
+ * Suspend the current intention, put it in the PendingIntention (PI) structure and assigns it to a key.
+ *
+ * @param basekey the base key to form final key used to get the intention back from PI (e.g. "moise", "cartago", ...)
+ * @param timeout the max time the intention will be in PI, the value 0 means until "resume"
+ * @return the final key used to store the intention in PI
+ */
+ public String suspend(final TransitionSystem ts, String basekey, int timeout) {
+ final String key = basekey + "/" + (actcount++);
+ final Circumstance C = ts.getC();
+ Intention i = C.getSelectedIntention();
+ i.setSuspended(true);
+ C.getPendingIntentions().put(key, i);
+
+ if (timeout > 0) {
+ // schedule a future test of the end of the action
+ scheduler.schedule( new Runnable() {
+ public void run() {
+ // finish the IA by timeout
+ if (C.getPendingIntentions().get(key) != null) { // test if the intention is still there
+ timeout(ts,key);
+ }
+ }
+ }, timeout, TimeUnit.MILLISECONDS);
+ }
+ return key;
+ }
+
+ /** called back when some intention should be resumed/failed by timeout */
+ abstract public void timeout(TransitionSystem ts, String intentionKey);
+
+ /** resume the intention identified by intentionKey */
+ public void resume(TransitionSystem ts, String intentionKey) {
+ resume(ts, intentionKey, false);
+ }
+
+ /** fails the intention identified by intentionKey */
+ public void fail(TransitionSystem ts, String intentionKey) {
+ resume(ts, intentionKey, true);
+ }
+
+ synchronized private void resume(TransitionSystem ts, String intentionKey, boolean abort) {
+ Circumstance C = ts.getC();
+ Intention pi = C.getPendingIntentions().remove(intentionKey);
+ if (pi != null) {
+ pi.setSuspended(false);
+ C.addIntention(pi); // add it back in I
+ pi.peek().removeCurrentStep(); // remove the internal action that put the intention in suspend
+
+ if (abort) {
+ // fail the IA
+ PlanBody pbody = pi.peek().getPlan().getBody();
+ pbody.add(0, new PlanBodyImpl(BodyType.internalAction, new InternalActionLiteral(".fail")));
+ }
+ ts.getUserAgArch().getArchInfraTier().wake();
+ }
+ }
+}
Modified: trunk/src/jason/stdlib/conditional.java
===================================================================
--- trunk/src/jason/stdlib/conditional.java 2008-05-29 18:40:56 UTC (rev 1317)
+++ trunk/src/jason/stdlib/conditional.java 2008-05-31 10:47:10 UTC (rev 1318)
@@ -35,7 +35,7 @@
import jason.asSyntax.PlanBody;
import jason.asSyntax.Term;
-// TODO: comments
+/** Implementation of if (see manual for more information) */
public class conditional extends DefaultInternalAction {
private static InternalAction singleton = null;
Modified: trunk/src/jason/stdlib/foreach.java
===================================================================
--- trunk/src/jason/stdlib/foreach.java 2008-05-29 18:40:56 UTC (rev 1317)
+++ trunk/src/jason/stdlib/foreach.java 2008-05-31 10:47:10 UTC (rev 1318)
@@ -42,7 +42,7 @@
import java.util.Iterator;
import java.util.List;
-// TODO: comments
+/** Implementation of for (see manual for more information) */
public class foreach extends DefaultInternalAction {
private static InternalAction singleton = null;
Modified: trunk/src/jason/stdlib/loop.java
===================================================================
--- trunk/src/jason/stdlib/loop.java 2008-05-29 18:40:56 UTC (rev 1317)
+++ trunk/src/jason/stdlib/loop.java 2008-05-31 10:47:10 UTC (rev 1318)
@@ -40,7 +40,7 @@
import java.util.Iterator;
-// TODO: comments
+/** Implementation of while (see manual for more information) */
public class loop extends DefaultInternalAction {
private static InternalAction singleton = null;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-05-31 11:11:34
|
Revision: 1319
http://jason.svn.sourceforge.net/jason/?rev=1319&view=rev
Author: jomifred
Date: 2008-05-31 04:11:27 -0700 (Sat, 31 May 2008)
Log Message:
-----------
add gui examples
add food-simulation example
Modified Paths:
--------------
trunk/release-notes.txt
Added Paths:
-----------
trunk/demos/gui/
trunk/demos/gui/gui1/
trunk/demos/gui/gui1/gui/
trunk/demos/gui/gui1/gui/yes_no.java
trunk/demos/gui/gui1/gui1.mas2j
trunk/demos/gui/gui1/sample.asl
trunk/demos/gui/gui2/
trunk/demos/gui/gui2/gui/
trunk/demos/gui/gui2/gui/create.java
trunk/demos/gui/gui2/gui2.mas2j
trunk/demos/gui/gui2/sample.asl
trunk/demos/gui/readme.txt
trunk/examples/food-simulation/
trunk/examples/food-simulation/FoodSimulation.mas2j
trunk/examples/food-simulation/lib/
trunk/examples/food-simulation/lib/jcommon-1.0.12.jar
trunk/examples/food-simulation/lib/jfreechart-1.0.8a.jar
trunk/examples/food-simulation/src/
trunk/examples/food-simulation/src/asl/
trunk/examples/food-simulation/src/asl/blind.asl
trunk/examples/food-simulation/src/asl/normative.asl
trunk/examples/food-simulation/src/asl/reputation.asl
trunk/examples/food-simulation/src/asl/strategic.asl
trunk/examples/food-simulation/src/java/
trunk/examples/food-simulation/src/java/FoodEnvironment.java
trunk/examples/food-simulation/src/java/FoodModel.java
trunk/examples/food-simulation/src/java/FoodView.java
trunk/examples/food-simulation/src/java/bb/
trunk/examples/food-simulation/src/java/bb/list.java
trunk/examples/food-simulation/src/java/math/
trunk/examples/food-simulation/src/java/math/distance.java
trunk/src/jason/asSemantics/SuspendInternalAction.java
Removed Paths:
-------------
trunk/src/jason/asSemantics/SynchronousInternalAction.java
Added: trunk/demos/gui/gui1/gui/yes_no.java
===================================================================
--- trunk/demos/gui/gui1/gui/yes_no.java (rev 0)
+++ trunk/demos/gui/gui1/gui/yes_no.java 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,49 @@
+package gui;
+
+import jason.asSemantics.*;
+import jason.asSyntax.*;
+import java.util.logging.*;
+
+import javax.swing.JOptionPane;
+
+public class yes_no extends SuspendInternalAction {
+
+ private Logger logger = Logger.getLogger("gui."+yes_no.class.getName());
+
+ @Override
+ public Object execute(final TransitionSystem ts, Unifier un, final Term[] args) throws Exception {
+ try {
+ // suspend the intention (max 5 seconds)
+ final String key = suspend(ts, "gui", 5000);
+
+ // to not block the agent thread,
+ // create a new thread that show the GUI and resume the intention latter
+ new Thread() {
+ public void run() {
+ int answer = JOptionPane.showConfirmDialog(null, args[0].toString());
+ // resume the intention with success
+ if (answer == JOptionPane.YES_OPTION)
+ yes_no.this.resume(ts, key);
+ else
+ fail(ts, key);
+ }
+ }.start();
+
+ return true;
+ } catch (Exception e) {
+ logger.warning("Error in internal action 'gui.yes_no'! "+e);
+ }
+ return false;
+ }
+
+ /** called back when some intention should be resumed/failed by timeout */
+ @Override
+ public void timeout(TransitionSystem ts, String intentionKey) {
+ // this method have to decide what to do with actions finished by timeout
+ // 1: resume
+ //resume(ts,intentionKey);
+
+ // 2: fail
+ fail(ts, intentionKey);
+ }
+}
Property changes on: trunk/demos/gui/gui1/gui/yes_no.java
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/demos/gui/gui1/gui1.mas2j
===================================================================
--- trunk/demos/gui/gui1/gui1.mas2j (rev 0)
+++ trunk/demos/gui/gui1/gui1.mas2j 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,15 @@
+/* Jason Project
+
+ Simple exaple of GUI: and internal action is used to ask something for the user
+
+*/
+
+MAS gui1 {
+
+ infrastructure: Centralised
+
+ agents:
+ sample;
+
+}
+
Added: trunk/demos/gui/gui1/sample.asl
===================================================================
--- trunk/demos/gui/gui1/sample.asl (rev 0)
+++ trunk/demos/gui/gui1/sample.asl 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,19 @@
+/* Initial goals */
+
+!start.
+!print.
+
+/* Plans */
+
+
+// the internal action gui.yes_no succeed if the user click Yes and fails otherwise
+//
+// note that this IA blocks only the intention using it (the !start) and not all the
+// intentions (the agent continues to print "." while the interface is being shown
+
++!start <- gui.yes_no("Is it Ok?"); .print(ok).
+-!start <- .print(nok).
+
++!print <- .wait(500); .print("."); !!print.
+
+
Added: trunk/demos/gui/gui2/gui/create.java
===================================================================
--- trunk/demos/gui/gui2/gui/create.java (rev 0)
+++ trunk/demos/gui/gui2/gui/create.java 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,63 @@
+package gui;
+
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.Literal;
+import jason.asSyntax.StringTerm;
+import jason.asSyntax.Term;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+
+/** internal action that creates a simple GUI with two buttons that trigger AS plans */
+public class create extends DefaultInternalAction {
+
+ int runCount = 0;
+
+ @Override
+ public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+
+ // get the window title
+ String title = ((StringTerm)args[0]).getString();
+
+ // create the windows
+ final JButton run = new JButton("run");
+ final JButton stop = new JButton("stop");
+ stop.setEnabled(false);
+ JPanel buttons = new JPanel();
+ buttons.add(new JLabel("Use the following buttons to control the agent intentions: "));
+ buttons.add(run);
+ buttons.add(stop);
+
+ JFrame frame = new JFrame(title);
+ frame.getContentPane().add(buttons);
+ frame.pack();
+ frame.setVisible(true);
+
+ // add the event listeners
+ run.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ // creates a new event +!run so that the agent can react to the button
+ runCount++;
+ ts.getC().addAchvGoal(Literal.parseLiteral("run("+runCount+")"), null);
+ stop.setEnabled(true);
+ run.setEnabled(false);
+ }
+ });
+ stop.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ ts.getC().addAchvGoal(Literal.parseLiteral("stop("+runCount+")"), null);
+ stop.setEnabled(false);
+ run.setEnabled(true);
+ }
+ });
+
+ return true;
+ }
+}
Added: trunk/demos/gui/gui2/gui2.mas2j
===================================================================
--- trunk/demos/gui/gui2/gui2.mas2j (rev 0)
+++ trunk/demos/gui/gui2/gui2.mas2j 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,16 @@
+/*
+ Jason Project
+
+ Example of GUI that create events the agent can react to.
+
+ -- created on May 30, 2008
+*/
+
+
+
+MAS gui2 {
+ infrastructure: Centralised
+
+ agents:
+ sample;
+}
\ No newline at end of file
Added: trunk/demos/gui/gui2/sample.asl
===================================================================
--- trunk/demos/gui/gui2/sample.asl (rev 0)
+++ trunk/demos/gui/gui2/sample.asl 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,15 @@
+
+/* Initial goals */
+
+!start.
+
+/* Plans */
+
++!start <- gui.create("Example GUI").
+
+// the event !run is created by the GUI
++!run(X) <- .print("running ",X,"...."); .wait(100); !!run(X).
+
+
+// the event !stop is created by the GUI
++!stop(X) <- .drop_desire(run(X)).
Added: trunk/demos/gui/readme.txt
===================================================================
--- trunk/demos/gui/readme.txt (rev 0)
+++ trunk/demos/gui/readme.txt 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,18 @@
+There are many ways of creating GUI for Jason agents.
+All of them relies on Java.
+
+This directory contains the following examples:
+
+gui1: uses and internal action to ask something to the user
+
+gui2: creates a window with buttons that, when pressed,
+ produce events the agent can react to.
+
+
+Some examples of Jason also use GUI:
+
+auction: uses a customised agent architecture that provides special
+ actions to show information in a GUI
+
+domestic-robot, iterated-prisoners-dilemma, and many others: the GUI
+ is implemented and maintained by the environment.
\ No newline at end of file
Added: trunk/examples/food-simulation/FoodSimulation.mas2j
===================================================================
--- trunk/examples/food-simulation/FoodSimulation.mas2j (rev 0)
+++ trunk/examples/food-simulation/FoodSimulation.mas2j 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,66 @@
+/*
+ Jason Project
+
+ -- create on December 20, 2007
+
+ -- Food Simulation --
+
+ based on the description available at
+ http://jasss.soc.surrey.ac.uk/1/3/3.html
+
+*/
+
+/*
+
+The environment implementation provides the following perception and actions
+
+Percepts:
+. step(X): the step X has started.
+
+. food(X,Y,P,O): food perception
+ X is the column
+ Y is the line
+ P can be
+ my_pos if the food is the same location as the agent
+ see if the food is in the agent's territory
+ smell if the food is two steps away from the agent
+ O is the agent allocated to the food, -1 if none
+
+. pos(AgId,X,Y): agent position
+ AgId the agent's identification in the environment
+
+. agent(AgId, X, Y, S, A): perception of other agents in the agent's territory
+ AgId is the identification of the other agent
+ S is its strength
+ A is its action (moving or eating)
+
+. strength(S): the strength of the agent
+
+. attacked(AgId,Name): the agent is beign attacked by AgId
+
+
+
+Actions:
+. eat
+. move(X,Y)
+. attack(X,Y)
+. random_move
+. pause
+
+*/
+
+
+MAS normative_simulation {
+ // the class that implements the environment is FoodEnvironment
+ // parameters are: grid size, number of agents, number of food units
+ environment: FoodEnvironment(10,50,25)
+
+ agents:
+ //blind [verbose=0] #50;
+ strategic [verbose=0] #25;
+ //normative [verbose=0] #25;
+ //normativerule [verbose=0] #50;
+ reputation [verbose=0] #25;
+
+ aslSourcePath: "src/asl";
+}
\ No newline at end of file
Property changes on: trunk/examples/food-simulation/FoodSimulation.mas2j
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/examples/food-simulation/lib/jcommon-1.0.12.jar
===================================================================
(Binary files differ)
Property changes on: trunk/examples/food-simulation/lib/jcommon-1.0.12.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/examples/food-simulation/lib/jfreechart-1.0.8a.jar
===================================================================
(Binary files differ)
Property changes on: trunk/examples/food-simulation/lib/jfreechart-1.0.8a.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/examples/food-simulation/src/asl/blind.asl
===================================================================
--- trunk/examples/food-simulation/src/asl/blind.asl (rev 0)
+++ trunk/examples/food-simulation/src/asl/blind.asl 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,14 @@
+// rule 1: food in my position
++step(_) : food(X,Y,my_pos,_) <- eat.
+
+// rule 2: food I see
++step(_) : food(X,Y,see,_) & not agent(_,X,Y,_,_) <- move(X,Y).
+
+// rule 3: food I see
++step(_) : food(X,Y,see,_) & agent(_,X,Y,_,eating) <- attack(X,Y).
+
+// rule 4: food I smell
++step(_) : food(X,Y,smell,_) <- move(X,Y).
+
+// rule 5
++step(_) <- random_move.
Property changes on: trunk/examples/food-simulation/src/asl/blind.asl
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/examples/food-simulation/src/asl/normative.asl
===================================================================
--- trunk/examples/food-simulation/src/asl/normative.asl (rev 0)
+++ trunk/examples/food-simulation/src/asl/normative.asl 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,16 @@
+
+// food in my position
++step(_) : food(X,Y,my_pos,A) & (pos(A,_,_) | A == -1) <- eat.
+
+// food I see
++step(_) : food(X,Y,see,Me) & pos(Me,_,_) & not agent(_,X,Y,_,_) <- move(X,Y).
++step(_) : food(X,Y,see,-1) & not agent(_,X,Y,_,_) <- move(X,Y).
++step(_) : food(X,Y,see,OAg) & agent(AgId,X,Y,_,eating) &
+ AgId \== OAg & OAg \== -1
+ <- attack(X,Y).
+
+// food I smell
++step(_) : food(X,Y,smell,Me) & pos(Me,_,_) <- move(X,Y).
++step(_) : food(X,Y,smell,-1) <- move(X,Y).
+
++step(_) <- random_move.
Property changes on: trunk/examples/food-simulation/src/asl/normative.asl
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/examples/food-simulation/src/asl/reputation.asl
===================================================================
--- trunk/examples/food-simulation/src/asl/reputation.asl (rev 0)
+++ trunk/examples/food-simulation/src/asl/reputation.asl 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,26 @@
+
+// food in my position
++step(_) : food(_,_,my_pos,A) & (pos(A,_,_) | A == -1 | cheater(A)) <- eat.
+
+// food I see
++step(_) : food(X,Y,see,Me) & pos(Me,_,_) & not agent(_,X,Y,_,_) <- move(X,Y).
++step(_) : food(X,Y,see,-1) & not agent(_,X,Y,_,_) <- move(X,Y).
++step(_) : food(X,Y,see,_) & agent(AgId,X,Y,S,eating) &
+ cheater(AgId) &
+ strength(MS) & MS > S
+ <- attack(X,Y).
+
+
+// food I smell
++step(_) : food(X,Y,smell,Me) & pos(Me,_,_) <- move(X,Y).
++step(_) : food(X,Y,smell,-1) <- move(X,Y).
+
++step(_) <- random_move.
+
+
+// reputation model
+
++attacked(A,_) <- +cheater(A); .broadcast(tell, cheater(A)).
+
+//+new_cheater(A,N) <- +cheater(A)[name(N)]; -new_cheater(A,N)[source(_)].
+
Property changes on: trunk/examples/food-simulation/src/asl/reputation.asl
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/examples/food-simulation/src/asl/strategic.asl
===================================================================
--- trunk/examples/food-simulation/src/asl/strategic.asl (rev 0)
+++ trunk/examples/food-simulation/src/asl/strategic.asl 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,13 @@
+
+// food in my position
++step(_) : food(X,Y,my_pos,_) <- eat.
+
+// food I see
++step(_) : food(X,Y,see,_) & not agent(_,X,Y,_,_) <- move(X,Y).
++step(_) : food(X,Y,see,_) & agent(_,X,Y,S,eating) & strength(MS) & MS > S <- attack(X,Y).
+
+// food I smell
++step(_) : food(X,Y,smell,_) <- move(X,Y).
+
+// nothing else
++step(_) <- random_move.
Property changes on: trunk/examples/food-simulation/src/asl/strategic.asl
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/examples/food-simulation/src/java/FoodEnvironment.java
===================================================================
--- trunk/examples/food-simulation/src/java/FoodEnvironment.java (rev 0)
+++ trunk/examples/food-simulation/src/java/FoodEnvironment.java 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,247 @@
+// Environment code for project game-of-life.mas2j
+
+import jason.asSyntax.Atom;
+import jason.asSyntax.Literal;
+import jason.asSyntax.NumberTerm;
+import jason.asSyntax.NumberTermImpl;
+import jason.asSyntax.Structure;
+import jason.environment.SteppedEnvironment;
+import jason.environment.grid.Location;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+public class FoodEnvironment extends SteppedEnvironment {
+
+ private Logger logger = Logger.getLogger("game-of-life.mas2j."+FoodEnvironment.class.getName());
+
+ private FoodModel model;
+ private FoodView view;
+
+ private Literal lstep; // current step
+ private Atom aMyPos = new Atom("my_pos");
+ private Atom aSee = new Atom("see");
+ private Atom aSmell = new Atom("smell");
+
+ Map<String,Integer> ag2id = new HashMap<String,Integer>();
+ Map<Integer,String> id2ag = new HashMap<Integer,String>();
+
+ /** Called before the MAS execution with the args informed in .mas2j */
+ @Override
+ public void init(String[] args) {
+ super.init(new String[] { "1000" } ); // set step timeout
+ setOverActionsPolicy(OverActionsPolicy.ignoreSecond);
+
+ model = new FoodModel(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]));
+ view = new FoodView(model, this);
+ model.setView(view);
+ }
+
+ @Override
+ public List<Literal> getPercepts(String agName) {
+ // if the agent is not in the map, add it and update its perception
+ if (ag2id.get(agName) == null) {
+ updateAgPercept(addAg2IdMap(agName));
+ }
+ return super.getPercepts(agName);
+ }
+
+ private static int lastUsedId = -1;
+ private synchronized int addAg2IdMap(String agName) {
+ lastUsedId++;
+ ag2id.put(agName,lastUsedId);
+ id2ag.put(lastUsedId, agName);
+ return lastUsedId;
+ }
+
+ @Override
+ public boolean executeAction(String agName, Structure action) {
+ String actId = action.getFunctor();
+ if (actId.equals("pause"))
+ return true;
+
+ int agId = ag2id.get(agName);
+ try {
+ if (actId.equals("eat")) {
+ model.eat(agId);
+ } else if (actId.equals("move")) {
+ int x = (int)(((NumberTerm)(action.getTerm(0))).solve());
+ int y = (int)(((NumberTerm)(action.getTerm(1))).solve());
+ model.move(agId, x, y);
+ } else if (actId.equals("attack")) {
+ int x = (int)(((NumberTerm)(action.getTerm(0))).solve());
+ int y = (int)(((NumberTerm)(action.getTerm(1))).solve());
+ model.attack(agId, x, y);
+ } else if (actId.equals("random_move")) {
+ model.randomMove(agId);
+ } else {
+ logger.warning("Unknown action: "+action);
+ }
+ } catch (Exception e) {}
+ return true;
+ }
+
+ @Override
+ protected int requiredStepsForAction(String agName, Structure action) {
+ if (action.getFunctor().equals("eat")) {
+ return 3; // eat takes 2 steps
+ }
+ return super.requiredStepsForAction(agName, action);
+ }
+
+ @Override
+ protected void stepStarted(int step) {
+ //logger.info("start step "+step);
+ lstep = new Literal("step");
+ lstep.addTerm(new NumberTermImpl(step+1));
+ }
+
+ long sum = 0;
+ List<Double> strategicValues = new ArrayList<Double>();
+ List<Double> reputationValues = new ArrayList<Double>();
+
+
+ @Override
+ protected void stepFinished(int step, long time, boolean timeout) {
+ if (step % 100 == 0) {
+ long mean = (step > 0 ? sum / step : 0);
+ logger.info(String.format("step %10d finished in %3d ms. Str/Var/Att %7.0f %7.0f %7d", step, mean, +model.getStrengthMean(),model.getVarianceOfStrength(),model.getAttackCounter() ));
+ //logger.info(String.format(" Strategic Str/Var/Att %7.0f", getStrength("strategic") ));
+ //logger.info(String.format(" Normative Str/Var/Att %7.0f", getStrength("normative") ));
+ //logger.info(String.format(" Reputation Str/Var/Att %7.0f", getStrength("reputation") ));
+
+ if (view != null) {
+ view.addSerie("strategic", getData(strategicValues));
+ view.addSerie("reputation", getData(reputationValues));
+ }
+ }
+ sum += time;
+ strategicValues.add(getStrength("strategic"));
+ reputationValues.add(getStrength("reputation"));
+ }
+
+
+ double getStrength(String typeOfAg) {
+ double sum = 0;
+ double q = 0;
+ for (int i=0; i<getNbAgs(); i++) {
+ if (id2ag.get(i).startsWith(typeOfAg)) {
+ sum += model.getAgStrength(i);
+ q++;
+ }
+ }
+ if (q > 0)
+ return sum / q;
+ else
+ return 0;
+ }
+
+ private double[][] getData(List<Double> values) {
+ double[][] r = new double[2][values.size()];
+ int i = 0;
+ for (double v: values) {
+ r[0][i] = i;
+ r[1][i] = v;
+ i++;
+ }
+ return r;
+ }
+
+ @Override
+ protected void updateAgsPercept() {
+ for (int i = 0; i < model.getNbOfAgs(); i++) {
+ updateAgPercept(i);
+ }
+ }
+
+ void updateAgPercept(int ag) {
+ //if (ag < 0 || ag >= model.getNbOfAgs()) return;
+ String name = id2ag.get(ag);
+ if (name != null) {
+ updateAgPercept(name, ag);
+ } else {
+ logger.warning("Can not give perception to "+ag+" bacause it is no registered!");
+ }
+ }
+
+ void updateAgPercept(String agName, int ag) {
+ clearPercepts(agName);
+
+ Location l = model.getAgPos(ag);
+ Literal lpos = new Literal("pos");
+ lpos.addTerm(new NumberTermImpl(ag));
+ lpos.addTerm(new NumberTermImpl(l.x));
+ lpos.addTerm(new NumberTermImpl(l.y));
+ addPercept(agName, lpos);
+
+ Literal lstrength = new Literal("strength");
+ lstrength.addTerm(new NumberTermImpl(model.getAgStrength(ag)));
+ addPercept(agName, lstrength);
+
+ testAg(agName, l.x - 1, l.y);
+ testAg(agName, l.x + 1, l.y);
+ testAg(agName, l.x, l.y + 1);
+ testAg(agName, l.x, l.y - 1);
+
+ testFood(agName, ag, aMyPos, l.x, l.y);
+ testFood(agName, ag, aSee, l.x - 1, l.y);
+ testFood(agName, ag, aSee, l.x + 1, l.y);
+ testFood(agName, ag, aSee, l.x, l.y + 1);
+ testFood(agName, ag, aSee, l.x, l.y - 1);
+
+ testFood(agName, ag, aSmell, l.x, l.y - 2);
+ testFood(agName, ag, aSmell, l.x, l.y + 2);
+ testFood(agName, ag, aSmell, l.x+1, l.y - 1);
+ testFood(agName, ag, aSmell, l.x+1, l.y + 1);
+ testFood(agName, ag, aSmell, l.x+2, l.y);
+ testFood(agName, ag, aSmell, l.x-2, l.y);
+ testFood(agName, ag, aSmell, l.x-1, l.y - 1);
+ testFood(agName, ag, aSmell, l.x-1, l.y + 1);
+
+ addPercept(agName, lstep);
+
+ int a = model.isAttacked(ag);
+ if (a >= 0) {
+ addPercept(agName, Literal.parseLiteral("attacked("+a+","+id2ag.get(a)+")"));
+ }
+ }
+
+ void testFood(String agName, int ag, Atom where, int x, int y) {
+ if (model.hasObject(FoodModel.FOOD, x, y)) {
+ Literal f = new Literal("food");
+ f.addTerm(new NumberTermImpl(x));
+ f.addTerm(new NumberTermImpl(y));
+ f.addTerm(where);
+ f.addTerm(new NumberTermImpl(model.getFoodOwner(x, y)));
+ addPercept(agName, f);
+ }
+ }
+
+ private static Atom aEating = new Atom("eating");
+ private static Atom aMoving = new Atom("moving");
+ void testAg(String agName, int x, int y) {
+ int other = model.getAgAtPos(x, y);
+ if (other >= 0) {
+ Literal f = new Literal("agent"); // seeing
+ f.addTerm(new NumberTermImpl(other));
+ f.addTerm(new NumberTermImpl(x));
+ f.addTerm(new NumberTermImpl(y));
+ f.addTerm(new NumberTermImpl(model.getAgStrength(other)));
+
+ if (isEating(agName)) {
+ f.addTerm(aEating);
+ } else {
+ f.addTerm(aMoving);
+ }
+ addPercept(agName, f);
+ }
+ }
+
+ private boolean isEating(String agName) {
+ Structure actInSchedule = getActionInSchedule(agName);
+ return actInSchedule != null && actInSchedule.getFunctor().equals("eat");
+ }
+}
Property changes on: trunk/examples/food-simulation/src/java/FoodEnvironment.java
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/examples/food-simulation/src/java/FoodModel.java
===================================================================
--- trunk/examples/food-simulation/src/java/FoodModel.java (rev 0)
+++ trunk/examples/food-simulation/src/java/FoodModel.java 2008-05-31 11:11:27 UTC (rev 1319)
@@ -0,0 +1,203 @@
+import jason.environment.grid.GridWorldModel;
+import jason.environment.grid.Location;
+
+/** class that implements the Model of the Food application */
+public class FoodModel extends GridWorldModel {
+
+ public static final int FOOD = 16; // represent a cell with food
+
+ public static final int INITIAL_STR = 40;
+ public static final int FOOD_NUTRITIVE_VALUE = 20;
+ public static final int MOVING_COST = 1;
+ public static final int ATTACK_COST = 4;
+
+ //private Logger logger = Logger.getLogger(FoodModel.class.getName());
+
+ int[] strengths;
+ int[] attacked;
+ int[][] owner; // the owner (agent id) of each food
+ private int attackCount = 0;
+
+ public FoodModel(int size, int ags, int foods) {
+ super(size, size, ags);
+
+ strengths = new int[ags];
+ attacked = new int[ags];
+ owner = new int[size][size];
+
+ // create agents
+ for (int i=0; i<ags; i++) {
+ setAgPos(i, getFreePos());
+ strengths[i] = INITIAL_STR;
+ }
+
+ // set attackers
+ clearAttackers();
+
+ // create food
+ for (int i=0; i<foods; i++) {
+ add(FOOD, getFreePos(FOOD));
+ }
+ setFoodOwners();
+ }
+
+ protected void clearAttackers() {
+ for (int i=0; i<attacked.length; i++) {
+ attacked[i] = -1;
+ }
+ }
+
+ protected void setFoodOwners() {
+ for (int x=0; x<getWidth(); x++) {
+ for (int y=0; y<getHeight(); y++) {
+ setFoodOwner(x, y);
+ }
+ }
+ }
+
+ private void setFoodOwner(int x, int y) {
+ if (hasObject(FOOD, x, y)) {
+ // find an agent around
+ int ag;
+ // food pos
+ ag = getAgAtPos(x, y); if (ag >= 0) { owner[x][y] = ag; return; }
+ // up
+ ag = getAgAtPos(x, y-1); if (ag >= 0) { owner[x][y] = ag; return; }
+ // down
+ ag = getAgAtPos(x, y+1); if (ag >= 0) { owner[x][y] = ag; return; }
+ // left
+ ag = getAgAtPos(x-1, y); if (ag >= 0) { owner[x][y] = ag; return; }
+ // right
+ ag = getAgAtPos(x+1, y); if (ag >= 0) { owner[x][y] = ag; return; }
+ }
+ owner[x][y] = -1;
+ }
+
+ public int getFoodOwner(int x, int y) {
+ return owner[x][y];
+ }
+
+ public boolean eat(int ag) {
+ Location l = getAgPos(ag);
+ return eat(ag, l.x, l.y);
+ }
+
+ private boolean eat(int ag, int x, int y) {
+ if (hasObject(FOOD, x, y)) {
+ remove(FOOD, x, y);
+ owner[x][y] = -1;
+ strengths[ag] += FOOD_NUTRITIVE_VALUE;
+ Location l = getFreePos(FOOD);
+ add(FOOD, l);
+ setFoodOwner(l.x, l.y);
+ return true;
+ }
+ return false;
+ }
+
+ public boolean move(int ag, int x, int y) {
+ //if (strengths[ag] < MOVING_COST)
+ // return false;
+
+ Location l = getAgPos(ag);
+ strengths[ag] -= MOVING_COST;
+
+ // should go right
+ if (l.x < x && isFree(l.x+1,l.y)) {
+ setAgPos(ag, l.x+1, l.y);
+ return true;
+ }
+ // should go left
+ if (l.x > x && isFree(l.x-1,l.y)) {
+ setAgPos(ag, l.x-1, l.y);
+ return true;
+ }
+ // should go up
+ if (l.y > y && isFree(l.x,l.y-1)) {
+ setAgPos(ag, l.x, l.y-1);
+ return true;
+ }
+ // should go down
+ if (l.y < y && isFree(l.x,l.y+1)) {
+ setAgPos(ag, l.x, l.y+1);
+ return true;
+ }
+ return false;
+ }
+
+ public boolean randomMove(int ag) {
+ Location l = getAgPos(ag);
+ Location nl = null;
+ for (int i=0; i<4; i++) {
+ switch (random.nextInt(4)) {
+ case 0: nl = new Location(l.x+1, l.y); break;
+ case 1: nl = new Location(l.x-1, l.y); break;
+ case 2: nl = new Location(l.x, l.y+1); break;
+ case 3: nl = new Location(l.x, l.y-1); break;
+ }
+ if (isFree(nl) && isFree(FOOD, nl)) {
+ return move(ag,nl.x,nl.y);
+ }
+ }
+ return false;
+ }
+
+ public boolean attack(int ag, int x, int y) {
+ //if (strengths[ag] < ATTACK_COST)
+ // return false;
+
+ strengths[ag] -= ATTACK_COST;
+
+ int other = getAgAtPos(x, y);
+ if (other < 0)
+ return false;
+
+ attackCount++;
+ if (strengths[ag] > strengths[other]) {
+ strengths[other] -= ATTACK_COST;
+ attacked[other] = ag;
+
+ Location agl = getAgPos(ag);
+
+ // move food of position
+ if (isFree(FOOD, agl) && hasObject(FOOD, x, y)) {
+ remove(FOOD, x, y);
+ owner[x][y] = -1;
+ add(FOOD, agl);
+ return true;
+ }
+ //eat(ag, x, y);
+ }
+ return false;
+ }
+
+ public int isAttacked(int ag) {
+ return attacked[ag];
+ }
+
+ public int getAgStrength(int ag) {
+ return strengths[ag];
+ }
+
+ public double getStrengthMean() {
+ double sum = 0;
+ for (int i=0; i<strengths.length; i++) ...
[truncated message content] |
|
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.
|
|
From: <jom...@us...> - 2008-06-09 15:05:49
|
Revision: 1328
http://jason.svn.sourceforge.net/jason/?rev=1328&view=rev
Author: jomifred
Date: 2008-06-09 08:05:42 -0700 (Mon, 09 Jun 2008)
Log Message:
-----------
add a new method to create source annotations
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/tests/TestIF.java
trunk/applications/jason-moise/src/jmoise/OrgAgent.java
trunk/src/jason/asSyntax/Pred.java
trunk/src/jason/bb/BeliefBase.java
Modified: trunk/applications/as-unit-test/src/jason/tests/TestIF.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestIF.java 2008-06-08 10:46:16 UTC (rev 1327)
+++ trunk/applications/as-unit-test/src/jason/tests/TestIF.java 2008-06-09 15:05:42 UTC (rev 1328)
@@ -18,12 +18,12 @@
ag.parseAScode(
"b(3). " +
"+!test1 <- a1; "+
- " .if( b(X), {jason.asunit.print(X); b1}, {jason.asunit.print(no)}); "+
+ " if( b(X), {jason.asunit.print(X); b1}, {jason.asunit.print(no)}); "+
" a2. "+
"+!test2 <- -b(_); !test1. "+
- "+!test3 <- .if( b(X), { Y = X*10; Z = 10 }, { Y = 60; Z=20 }); jason.asunit.print(Y,\" \",Z). "+
+ "+!test3 <- if( b(X), { Y = X*10; Z = 10 }, { Y = 60; Z=20 }); jason.asunit.print(Y,\" \",Z). "+
"+!test4 <- -b(_); !test3. "
);
}
Modified: trunk/applications/jason-moise/src/jmoise/OrgAgent.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2008-06-08 10:46:16 UTC (rev 1327)
+++ trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2008-06-09 15:05:42 UTC (rev 1328)
@@ -53,7 +53,7 @@
*/
public class OrgAgent extends AgArch {
- private static final Term managerSource = DefaultTerm.parse("source(orgManager)");
+ private static final Term managerSource = Pred.createSource("orgManager");
private static final Atom rootAtom = new Atom("root");
private Logger logger = Logger.getLogger(OrgAgent.class.getName());
Modified: trunk/src/jason/asSyntax/Pred.java
===================================================================
--- trunk/src/jason/asSyntax/Pred.java 2008-06-08 10:46:16 UTC (rev 1327)
+++ trunk/src/jason/asSyntax/Pred.java 2008-06-09 15:05:42 UTC (rev 1328)
@@ -308,23 +308,29 @@
* Adds a source annotation like "source(<i>agName</i>)".
*/
public void addSource(Structure agName) {
- if (agName != null) {
- Structure ts = new Structure("source", 1);
- ts.addTerm(agName);
- addAnnot(ts);
- }
+ if (agName != null)
+ addAnnot(createSource(agName));
}
/** deletes "source(<i>agName</i>)" */
public boolean delSource(Structure agName) {
- if (annots != null) {
- Structure ts = new Structure("source");
- ts.addTerm(agName);
- return annots.remove(ts);
- }
- return false;
+ if (annots != null)
+ return annots.remove(createSource(agName));
+ else
+ return false;
}
+ public static Term createSource(String source) {
+ Structure s = new Structure("source",1);
+ s.addTerm(new Atom(source));
+ return s;
+ }
+ public static Term createSource(Structure source) {
+ Structure s = new Structure("source",1);
+ s.addTerm(source);
+ return s;
+ }
+
/**
* returns the sources of this Pred as a new list. e.g.: from annots
* [source(a), source(b)], it returns [a,b]
Modified: trunk/src/jason/bb/BeliefBase.java
===================================================================
--- trunk/src/jason/bb/BeliefBase.java 2008-06-08 10:46:16 UTC (rev 1327)
+++ trunk/src/jason/bb/BeliefBase.java 2008-06-09 15:05:42 UTC (rev 1328)
@@ -25,8 +25,8 @@
import jason.asSemantics.Agent;
import jason.asSemantics.Unifier;
-import jason.asSyntax.DefaultTerm;
import jason.asSyntax.Literal;
+import jason.asSyntax.Pred;
import jason.asSyntax.PredicateIndicator;
import jason.asSyntax.Term;
@@ -42,9 +42,9 @@
*/
public interface BeliefBase extends Iterable<Literal>, Cloneable {
- public static final Term TPercept = DefaultTerm.parse("source(percept)");
- public static final Term TSelf = DefaultTerm.parse("source(self)");
-
+ public static final Term TPercept = Pred.createSource("percept");
+ public static final Term TSelf = Pred.createSource("self");
+
/**
* Called before the MAS execution with the agent that uses this
* BB and the args informed in .mas2j project.<br>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-06-09 20:39:50
|
Revision: 1331
http://jason.svn.sourceforge.net/jason/?rev=1331&view=rev
Author: jomifred
Date: 2008-06-09 13:39:41 -0700 (Mon, 09 Jun 2008)
Log Message:
-----------
improve implementation of .at and .wait based on ThreadPoolScheduler
Modified Paths:
--------------
trunk/applications/jasdl-owlapi/build.xml
trunk/applications/jasdl-owlapi/examples/commerce/MAS.mas2j
trunk/applications/jasdl-owlapi/examples/commerce/bin/build.xml
trunk/applications/jasdl-owlapi/lib/owl2mas.jar
trunk/applications/owl2mas/lib/owl2mas.jar
trunk/src/jason/architecture/AgArch.java
trunk/src/jason/asSemantics/Agent.java
trunk/src/jason/asSemantics/SuspendInternalAction.java
trunk/src/jason/stdlib/at.java
trunk/src/jason/stdlib/drop_all_intentions.java
trunk/src/jason/stdlib/print.java
trunk/src/jason/stdlib/wait.java
Modified: trunk/applications/jasdl-owlapi/build.xml
===================================================================
--- trunk/applications/jasdl-owlapi/build.xml 2008-06-09 19:58:41 UTC (rev 1330)
+++ trunk/applications/jasdl-owlapi/build.xml 2008-06-09 20:39:41 UTC (rev 1331)
@@ -18,7 +18,7 @@
<!-- For conveniently building bebops, jason and jmca if present -->
- <property name="jason.dir" value="../../../jason"/>
+ <property name="jason.dir" value="../.."/>
<property name="apps.dir" value="${jason.dir}/applications"/>
<property name="bebops.dir" value="${apps.dir}/bebops"/>
<property name="bebops.jar" value="${bebops.dir}/lib/bebops.jar"/>
Modified: trunk/applications/jasdl-owlapi/examples/commerce/MAS.mas2j
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/MAS.mas2j 2008-06-09 19:58:41 UTC (rev 1330)
+++ trunk/applications/jasdl-owlapi/examples/commerce/MAS.mas2j 2008-06-09 20:39:41 UTC (rev 1331)
@@ -1,7 +1,7 @@
/*
Jason Project
- -- created on June 06, 2008
+ -- created on June 09, 2008
*/
MAS soc {
@@ -10,19 +10,19 @@
environment: commerce.env.CommerceEnvironment
agents:
- a_greengrocers shop.asl [jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_ontologies="c,s", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
- delivery_van_4 delivery_van.asl [jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_ontologies="c,s", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
- a_supermarket shop.asl [jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_ontologies="c,s", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
- toms_pa pa.asl [jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_ontologies="c,s", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
- a_butchers shop.asl [jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_ontologies="c,s", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
- jims_pa pa.asl [jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_ontologies="c,s", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
- caz customer.asl [jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_ontologies="c,s", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
- cazs_pa pa.asl [jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_ontologies="c,s", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
- delivery_van_1 delivery_van.asl [jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_ontologies="c,s", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
- delivery_van_3 delivery_van.asl [jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_ontologies="c,s", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
- jim customer.asl [jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_ontologies="c,s", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
- tom customer.asl [jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_ontologies="c,s", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
- delivery_van_2 delivery_van.asl [jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_ontologies="c,s", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
+ delivery_van_1 delivery_van.asl [jasdl_ontologies="c,s", jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
+ caz customer.asl [jasdl_ontologies="c,s", jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
+ a_butchers shop.asl [jasdl_ontologies="c,s", jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
+ a_greengrocers shop.asl [jasdl_ontologies="c,s", jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
+ jims_pa pa.asl [jasdl_ontologies="c,s", jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
+ tom customer.asl [jasdl_ontologies="c,s", jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
+ delivery_van_2 delivery_van.asl [jasdl_ontologies="c,s", jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
+ delivery_van_3 delivery_van.asl [jasdl_ontologies="c,s", jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
+ delivery_van_4 delivery_van.asl [jasdl_ontologies="c,s", jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
+ toms_pa pa.asl [jasdl_ontologies="c,s", jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
+ a_supermarket shop.asl [jasdl_ontologies="c,s", jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
+ cazs_pa pa.asl [jasdl_ontologies="c,s", jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
+ jim customer.asl [jasdl_ontologies="c,s", jasdl_s_uri="/onts/society.owl", jasdl_c_uri="/onts/commerce.owl", jasdl_useContraction="true"] agentArchClass jasdl.architecture.JASDLAgArch agentClass jasdl.asSemantics.JASDLAgent beliefBaseClass jasdl.bb.JASDLBeliefBase;
classpath: "../../lib/**/*.jar";
aslSourcePath: "src/asl";
Modified: trunk/applications/jasdl-owlapi/examples/commerce/bin/build.xml
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/bin/build.xml 2008-06-09 19:58:41 UTC (rev 1330)
+++ trunk/applications/jasdl-owlapi/examples/commerce/bin/build.xml 2008-06-09 20:39:41 UTC (rev 1331)
@@ -2,10 +2,10 @@
<!--
- This file was generated by Jason 1.0.2
+ This file was generated by Jason 1.1.2
http://jason.sf.net
- June 06, 2008 - 17:38:11
+ June 09, 2008 - 22:03:32
-->
<project name ="soc"
@@ -16,7 +16,7 @@
<property name="debug" value=""/> <!-- use "-debug" to run in debug mode -->
<property name="build.dir" value="${basedir}/bin/classes" />
- <property name="jasonJar" value="/home/tom/workspace/jason/bin/../lib/jason.jar"/>
+ <property name="jasonJar" value="/Users/jomi/Jason/Jason-svn/lib/jason.jar"/>
<path id="project.classpath">
<pathelement location="${basedir}"/>
@@ -73,10 +73,10 @@
<copy todir="${basedir}/${ant.project.name}-jws" failonerror="no">
<fileset dir="${basedir}/lib" includes="**/*.jar" />
<fileset dir="${basedir}" includes="${ant.project.name}.jar" />
- <fileset dir="/home/tom/workspace/jason/bin/../src/images" includes="Jason-GMoreau-Icon.jpg" />
+ <fileset dir="/Users/jomi/Jason/Jason-svn/src/images" includes="Jason-GMoreau-Icon.jpg" />
</copy>
<signjar jar="${basedir}/${ant.project.name}-jws/${ant.project.name}.jar" alias="jason"
- storepass="rbjhja" keypass="rbjhja" keystore="/home/tom/workspace/jason/bin/../src/jasonKeystore" />
+ storepass="rbjhja" keypass="rbjhja" keystore="/Users/jomi/Jason/Jason-svn/src/jasonKeystore" />
<echo message="**" />
<echo message="** Java Web Start application created in directory ${ant.project.name}-jws" />
<echo message="** Update the codebase (in the second line of the .jnlp file)" />
Modified: trunk/applications/jasdl-owlapi/lib/owl2mas.jar
===================================================================
(Binary files differ)
Modified: trunk/applications/owl2mas/lib/owl2mas.jar
===================================================================
(Binary files differ)
Modified: trunk/src/jason/architecture/AgArch.java
===================================================================
--- trunk/src/jason/architecture/AgArch.java 2008-06-09 19:58:41 UTC (rev 1330)
+++ trunk/src/jason/architecture/AgArch.java 2008-06-09 20:39:41 UTC (rev 1331)
@@ -31,7 +31,6 @@
import jason.bb.BeliefBase;
import jason.mas2j.ClassParameters;
import jason.runtime.Settings;
-import jason.stdlib.at;
import java.util.List;
@@ -85,17 +84,7 @@
* when the agent is about to be killed.
*/
public void stopAg() {
- ts.getAg().getBB().stop();
-
- // cancel future events generated by .at
- try {
- ((at)getTS().getAg().getIA(at.atAtom)).stopAllWaits();
- } catch (Exception e) {}
-
- // stop wait threads
- try {
- ((jason.stdlib.wait)getTS().getAg().getIA(jason.stdlib.wait.waitAtom)).stopAllWaits();
- } catch (Exception e) {}
+ ts.getAg().stopAg();
}
public void setArchInfraTier(AgArchInfraTier ai) {
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2008-06-09 19:58:41 UTC (rev 1330)
+++ trunk/src/jason/asSemantics/Agent.java 2008-06-09 20:39:41 UTC (rev 1331)
@@ -60,6 +60,8 @@
import java.util.List;
import java.util.Map;
import java.util.Queue;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -92,6 +94,9 @@
private boolean hasCustomSelOp = true;
+ private ScheduledExecutorService scheduler = null;
+
+
protected Logger logger = Logger.getLogger(Agent.class.getName());
public Agent() {
@@ -156,6 +161,13 @@
throw new JasonException("Error creating the agent class! - " + e);
}
}
+
+ public void stopAg() {
+ bb.stop();
+
+ if (scheduler != null)
+ scheduler.shutdownNow();
+ }
/**
* Clone BB, PL, Circumstance.
@@ -184,6 +196,13 @@
public Logger getLogger() {
return logger;
}
+
+ public ScheduledExecutorService getScheduler() {
+ if (scheduler == null)
+ scheduler = Executors.newScheduledThreadPool(1);
+ return scheduler;
+ }
+
/** Returns the .asl file source used to create this agent */
public String getASLSrc() {
Modified: trunk/src/jason/asSemantics/SuspendInternalAction.java
===================================================================
--- trunk/src/jason/asSemantics/SuspendInternalAction.java 2008-06-09 19:58:41 UTC (rev 1330)
+++ trunk/src/jason/asSemantics/SuspendInternalAction.java 2008-06-09 20:39:41 UTC (rev 1331)
@@ -1,16 +1,10 @@
package jason.asSemantics;
-import jason.asSemantics.Circumstance;
-import jason.asSemantics.Intention;
-import jason.asSemantics.InternalAction;
-import jason.asSemantics.TransitionSystem;
import jason.asSyntax.InternalActionLiteral;
import jason.asSyntax.PlanBody;
import jason.asSyntax.PlanBodyImpl;
import jason.asSyntax.PlanBody.BodyType;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
@@ -27,8 +21,7 @@
*/
public abstract class SuspendInternalAction implements InternalAction {
- protected ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
- private static int actcount = 0;
+ private static int actcount = 0;
public boolean canBeUsedInContext() {
return false;
@@ -54,7 +47,7 @@
if (timeout > 0) {
// schedule a future test of the end of the action
- scheduler.schedule( new Runnable() {
+ ts.getAg().getScheduler().schedule( new Runnable() {
public void run() {
// finish the IA by timeout
if (C.getPendingIntentions().get(key) != null) { // test if the intention is still there
Modified: trunk/src/jason/stdlib/at.java
===================================================================
--- trunk/src/jason/stdlib/at.java 2008-06-09 19:58:41 UTC (rev 1330)
+++ trunk/src/jason/stdlib/at.java 2008-06-09 20:39:41 UTC (rev 1331)
@@ -37,6 +37,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
/**
<p>Internal action: <b><code>.at</code></b>.
@@ -74,12 +75,11 @@
public static final String atAtom = ".at";
@Override
- public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
- StringTerm time = (StringTerm)args[0];
- StringTerm sevent = (StringTerm)args[1];
- Trigger te = Trigger.parseTrigger(sevent.getString());
- String stime = time.getString();
+ StringTerm time = (StringTerm)args[0];
+ String stime = time.getString();
+ StringTerm sevent = (StringTerm)args[1];
// parse time
long deadline = -1;
@@ -118,9 +118,10 @@
if (deadline == -1) {
throw new JasonException("The time parameter ('"+time+"') of the internal action 'at' did not parse correctly!");
}
+
+ Trigger te = Trigger.parseTrigger(sevent.getString());
- new CheckDeadline(deadline, te, ts.getC()).start();
-
+ ts.getAg().getScheduler().schedule(new CheckDeadline(te, ts.getC()), deadline, TimeUnit.MILLISECONDS);
return true;
} catch (ArrayIndexOutOfBoundsException e) {
throw new JasonException("The internal action 'at' has not received two arguments.");
@@ -128,39 +129,38 @@
}
private static int idCount = 0;
- private Map<Integer,CheckDeadline> threads = new ConcurrentHashMap<Integer,CheckDeadline>();
+ private Map<Integer,CheckDeadline> ats = new ConcurrentHashMap<Integer,CheckDeadline>();
- public void stopAllWaits() {
- for (CheckDeadline t: threads.values()) {
- t.interrupt();
- }
+ public void cancelAts() {
+ for (CheckDeadline t: ats.values())
+ t.cancel();
}
- class CheckDeadline extends Thread {
+ class CheckDeadline implements Runnable {
private int id = 0;
- private long deadline = 0;
private Event event;
private Circumstance c;
+ private boolean cancelled = false;
- public CheckDeadline(long d, Trigger te, Circumstance c) {
+ public CheckDeadline(Trigger te, Circumstance c) {
idCount++;
this.id = idCount;
- this.deadline = d;
this.event = new Event(te, Intention.EmptyInt);
this.c = c;
-
- threads.put(id, this);
+ ats.put(id, this);
}
- synchronized public void run() {
+ void cancel() {
+ cancelled = true;
+ }
+
+ public void run() {
try {
- wait(deadline);
- // add event to Circumstance.Events
- c.addEvent(event);
- } catch (InterruptedException e) {
+ if (!cancelled)
+ c.addEvent(event);
} finally {
- threads.remove(id);
+ ats.remove(id);
}
}
}
Modified: trunk/src/jason/stdlib/drop_all_intentions.java
===================================================================
--- trunk/src/jason/stdlib/drop_all_intentions.java 2008-06-09 19:58:41 UTC (rev 1330)
+++ trunk/src/jason/stdlib/drop_all_intentions.java 2008-06-09 20:39:41 UTC (rev 1331)
@@ -83,7 +83,7 @@
// cancel future events generated by .at
at atia = (at)ts.getAg().getIA(at.atAtom);
- atia.stopAllWaits();
+ atia.cancelAts();
return true;
}
Modified: trunk/src/jason/stdlib/print.java
===================================================================
--- trunk/src/jason/stdlib/print.java 2008-06-09 19:58:41 UTC (rev 1330)
+++ trunk/src/jason/stdlib/print.java 2008-06-09 20:39:41 UTC (rev 1331)
@@ -61,7 +61,7 @@
private static InternalAction singleton = null;
public static InternalAction create() {
if (singleton == null)
- singleton = new println();
+ singleton = new print();
return singleton;
}
Modified: trunk/src/jason/stdlib/wait.java
===================================================================
--- trunk/src/jason/stdlib/wait.java 2008-06-09 19:58:41 UTC (rev 1330)
+++ trunk/src/jason/stdlib/wait.java 2008-06-09 20:39:41 UTC (rev 1331)
@@ -40,9 +40,7 @@
import jason.asSyntax.Trigger;
import jason.asSyntax.PlanBody.BodyType;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
/**
@@ -99,14 +97,12 @@
public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws Exception {
long timeout = -1;
Trigger te = null;
-
- Term elapseTime = null;
+ Term elapsedTime = null;
try {
if (args[0].isNumeric()) {
// time in milliseconds
NumberTerm time = (NumberTerm)args[0];
timeout = (long) time.solve();
- // Thread.sleep((long) time.solve());
} else if (args[0].isString()) {
// wait for event
StringTerm st = (StringTerm) args[0];
@@ -116,15 +112,14 @@
if (args.length >= 2)
timeout = (long) ((NumberTerm) args[1]).solve();
if (args.length == 3)
- elapseTime = args[2];
+ elapsedTime = args[2];
}
+ new WaitEvent(te, un, ts, timeout, elapsedTime);
+ return true;
} catch (Exception e) {
ts.getLogger().log(Level.SEVERE, "Error at .wait.", e);
- return false;
}
- WaitEvent wet = new WaitEvent(te, un, ts, timeout, elapseTime);
- wet.start();
- return true;
+ return false;
}
@Override
@@ -132,38 +127,24 @@
return true;
}
- private List<WaitEvent> threads = Collections.synchronizedList(new ArrayList<WaitEvent>());
-
- public void stopAllWaits() {
- for (WaitEvent t: threads) {
- t.interrupt();
- }
- }
-
-
- class WaitEvent extends Thread implements CircumstanceListener {
- Trigger te;
- String sTE; // a string version of TE
- Unifier un;
- Intention si;
- TransitionSystem ts;
- Circumstance c;
- boolean ok = false;
- boolean drop = false;
- boolean stopByTimeout = false;
- Term elapseTimeTerm;
- long timeout = -1;
- long elapseTime;
+ class WaitEvent implements CircumstanceListener {
+ private Trigger te;
+ private String sTE; // a string version of TE
+ private Unifier un;
+ private Intention si;
+ private TransitionSystem ts;
+ private Circumstance c;
+ private boolean dropped = false;
+ private Term elapsedTimeTerm;
+ private long startTime;
- WaitEvent(Trigger te, Unifier un, TransitionSystem ts, long to, Term elapseTimeTerm) {
- super("wait "+te);
+ WaitEvent(Trigger te, Unifier un, TransitionSystem ts, long timeout, Term elapsedTimeTerm) {
this.te = te;
this.un = un;
this.ts = ts;
c = ts.getC();
si = c.getSelectedIntention();
- this.timeout = to;
- this.elapseTimeTerm = elapseTimeTerm;
+ this.elapsedTimeTerm = elapsedTimeTerm;
// register listener
c.addEventListener(this);
@@ -176,27 +157,34 @@
sTE = si.getId()+"/"+sTE;
c.getPendingIntentions().put(sTE, si);
- threads.add(this);
+ startTime = System.currentTimeMillis();
+
+ if (timeout > 0) {
+ ts.getAg().getScheduler().schedule(new Runnable() {
+ public void run() {
+ resume(true);
+ }
+ }, timeout, TimeUnit.MILLISECONDS);
+ }
}
- public void run() {
+ void resume(boolean stopByTimeout) {
try {
- waitEvent();
-
// unregister (for not to receive intentionAdded again)
c.removeEventListener(this);
- // add SI again in C.I if it was not removed and this
- // wait was not dropped
- if (c.getPendingIntentions().remove(sTE) == si && !c.getIntentions().contains(si) && !drop) {
- if (stopByTimeout && te != null && elapseTimeTerm == null) {
+ // add SI again in C.I if it was not removed and this wait was not dropped
+ if (c.getPendingIntentions().remove(sTE) == si && !c.getIntentions().contains(si) && !dropped) {
+ if (stopByTimeout && te != null && elapsedTimeTerm == null) {
// fail the .wait
PlanBody body = si.peek().getPlan().getBody();
body.add(1, new PlanBodyImpl(BodyType.internalAction, new InternalActionLiteral(".fail")));
}
si.peek().removeCurrentStep();
- if (elapseTimeTerm != null)
- si.peek().getUnif().unifies(elapseTimeTerm, new NumberTermImpl(elapseTime));
+ if (elapsedTimeTerm != null) {
+ long elapsedTime = System.currentTimeMillis() - startTime;
+ un.unifies(elapsedTimeTerm, new NumberTermImpl(elapsedTime));
+ }
if (si.isSuspended()) { // if the intention was suspended by .suspend
String k = suspend.SUSPENDED_INT+si.getId();
c.getPendingIntentions().put(k, si);
@@ -204,52 +192,21 @@
c.addIntention(si);
}
}
-
} catch (Exception e) {
ts.getLogger().log(Level.SEVERE, "Error at .wait thread", e);
- } finally {
- threads.remove(this);
}
}
- synchronized public void waitEvent() {
- long init = System.currentTimeMillis();
- elapseTime = 0;
- while (!ok && !drop) {
- try {
- if (timeout == -1) {
- wait();
- } else {
- long to = timeout - elapseTime;
- if (to <= 0)
- to = 100;
- wait(to);
- elapseTime = System.currentTimeMillis() - init;
- if (elapseTime >= timeout) {
- stopByTimeout = true;
- break;
- }
- }
- } catch (InterruptedException e) {
- drop = true;
- } catch (Exception e) {
- e.printStackTrace();
- }
+ public void eventAdded(Event e) {
+ if (te != null && !dropped && un.unifies(te, e.getTrigger())) {
+ resume(false);
}
}
- synchronized public void eventAdded(Event e) {
- if (te != null && !drop && un.unifies(te, e.getTrigger())) {
- ok = true;
- notifyAll();
- }
- }
-
- synchronized public void intentionDropped(Intention i) {
+ public void intentionDropped(Intention i) {
if (i.equals(si)) {
- ok = false;
- drop = true;
- notifyAll();
+ dropped = true;
+ resume(false);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-06-11 21:27:40
|
Revision: 1337
http://jason.svn.sourceforge.net/jason/?rev=1337&view=rev
Author: jomifred
Date: 2008-06-11 14:27:35 -0700 (Wed, 11 Jun 2008)
Log Message:
-----------
improve comments in the food-simulation example
Modified Paths:
--------------
trunk/examples/food-simulation/FoodSimulation.mas2j
trunk/examples/food-simulation/src/asl/blind.asl
trunk/examples/food-simulation/src/asl/normative.asl
trunk/examples/food-simulation/src/asl/reputation.asl
trunk/examples/food-simulation/src/asl/strategic.asl
trunk/release-notes.txt
Modified: trunk/examples/food-simulation/FoodSimulation.mas2j
===================================================================
--- trunk/examples/food-simulation/FoodSimulation.mas2j 2008-06-09 22:54:15 UTC (rev 1336)
+++ trunk/examples/food-simulation/FoodSimulation.mas2j 2008-06-11 21:27:35 UTC (rev 1337)
@@ -1,13 +1,15 @@
/*
Jason Project
- -- create on December 20, 2007
-
-- Food Simulation --
based on the description available at
http://jasss.soc.surrey.ac.uk/1/3/3.html
-
+
+ used in the chapter about Jason in the book
+ "Agents, Simulation and Applications" by
+ Adelinde M. Uhrmacher and Danny Weyns
+
*/
/*
@@ -63,4 +65,4 @@
reputation [verbose=0] #25;
aslSourcePath: "src/asl";
-}
\ No newline at end of file
+}
Modified: trunk/examples/food-simulation/src/asl/blind.asl
===================================================================
--- trunk/examples/food-simulation/src/asl/blind.asl 2008-06-09 22:54:15 UTC (rev 1336)
+++ trunk/examples/food-simulation/src/asl/blind.asl 2008-06-11 21:27:35 UTC (rev 1337)
@@ -1,14 +1,16 @@
-// rule 1: food in my position
+/* -- blind agent -- */
+
+// rule 1: If there is food in my cell, eat.
+step(_) : food(X,Y,my_pos,_) <- eat.
-// rule 2: food I see
+// rule 2: If I see food in a free cell, move to there
+step(_) : food(X,Y,see,_) & not agent(_,X,Y,_,_) <- move(X,Y).
-// rule 3: food I see
+// rule 3: If I see food in an occupied cell, attack the agent at that cell
+step(_) : food(X,Y,see,_) & agent(_,X,Y,_,eating) <- attack(X,Y).
-// rule 4: food I smell
+// rule 4: If I smell food, move to there
+step(_) : food(X,Y,smell,_) <- move(X,Y).
-// rule 5
+// rule 5: Otherwise, do a random movement
+step(_) <- random_move.
Modified: trunk/examples/food-simulation/src/asl/normative.asl
===================================================================
--- trunk/examples/food-simulation/src/asl/normative.asl 2008-06-09 22:54:15 UTC (rev 1336)
+++ trunk/examples/food-simulation/src/asl/normative.asl 2008-06-11 21:27:35 UTC (rev 1337)
@@ -1,16 +1,24 @@
+/* -- normative agent -- */
-// food in my position
+// Rule-n1: only eat food that is free or allocated to me
+step(_) : food(X,Y,my_pos,A) & (pos(A,_,_) | A == -1) <- eat.
-// food I see
+// Rule-n2: if I see food allocated to me, move to there
+step(_) : food(X,Y,see,Me) & pos(Me,_,_) & not agent(_,X,Y,_,_) <- move(X,Y).
+
+// Rule-n3: if I see unallocated food, move to there
+step(_) : food(X,Y,see,-1) & not agent(_,X,Y,_,_) <- move(X,Y).
+
+// Rule-n4: if I see another agent eating food owned by others, attack it
+step(_) : food(X,Y,see,OAg) & agent(AgId,X,Y,_,eating) &
AgId \== OAg & OAg \== -1
<- attack(X,Y).
-// food I smell
+// Rule-n5: if I smell my food, move to there
+step(_) : food(X,Y,smell,Me) & pos(Me,_,_) <- move(X,Y).
+
+// Rule-n6: if I smell unallocated food, move to there
+step(_) : food(X,Y,smell,-1) <- move(X,Y).
+// Rule-n7: otherwise, move randomly
+step(_) <- random_move.
Modified: trunk/examples/food-simulation/src/asl/reputation.asl
===================================================================
--- trunk/examples/food-simulation/src/asl/reputation.asl 2008-06-09 22:54:15 UTC (rev 1336)
+++ trunk/examples/food-simulation/src/asl/reputation.asl 2008-06-11 21:27:35 UTC (rev 1337)
@@ -1,20 +1,28 @@
+/* -- reputation agent -- */
-// food in my position
+// Rule-r1: eat food that is either allocate to me, free, or belongs to a cheater
+step(_) : food(_,_,my_pos,A) & (pos(A,_,_) | A == -1 | cheater(A)) <- eat.
-// food I see
+// Rule-r2: if I see food allocated to me, move to there
+step(_) : food(X,Y,see,Me) & pos(Me,_,_) & not agent(_,X,Y,_,_) <- move(X,Y).
+
+// Rule-r3: if I see unallocated food, move to there
+step(_) : food(X,Y,see,-1) & not agent(_,X,Y,_,_) <- move(X,Y).
+
+// Rule-r4: attack cheaters that are weaker than me
+step(_) : food(X,Y,see,_) & agent(AgId,X,Y,S,eating) &
cheater(AgId) &
strength(MS) & MS > S
<- attack(X,Y).
-// food I smell
+// Rule-r5: if I smell my food, move to there
+step(_) : food(X,Y,smell,Me) & pos(Me,_,_) <- move(X,Y).
+
+// Rule-r6: if I smell unallocated food, move to there
+step(_) : food(X,Y,smell,-1) <- move(X,Y).
+// Rule-r7: otherwise, move randomly
+step(_) <- random_move.
Modified: trunk/examples/food-simulation/src/asl/strategic.asl
===================================================================
--- trunk/examples/food-simulation/src/asl/strategic.asl 2008-06-09 22:54:15 UTC (rev 1336)
+++ trunk/examples/food-simulation/src/asl/strategic.asl 2008-06-11 21:27:35 UTC (rev 1337)
@@ -1,3 +1,4 @@
+/* -- strategic agent -- */
// food in my position
+step(_) : food(X,Y,my_pos,_) <- eat.
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-06-09 22:54:15 UTC (rev 1336)
+++ trunk/release-notes.txt 2008-06-11 21:27:35 UTC (rev 1337)
@@ -62,7 +62,8 @@
Bugs fixed:
. BUF add annotation "source(percept)" in the perception deletion event
. drop_desire does not remove desires in Circumstance.Event correctly
- when annotations are used.
+ when annotations are used
+. print works like println
-------------
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-06-14 20:29:40
|
Revision: 1341
http://jason.svn.sourceforge.net/jason/?rev=1341&view=rev
Author: jomifred
Date: 2008-06-14 13:29:35 -0700 (Sat, 14 Jun 2008)
Log Message:
-----------
update faq for new "style" of c-build.xml
Modified Paths:
--------------
trunk/doc/faq/faq.tex
trunk/examples/food-simulation/src/java/FoodEnvironment.java
trunk/release-notes.txt
Modified: trunk/doc/faq/faq.tex
===================================================================
--- trunk/doc/faq/faq.tex 2008-06-13 17:42:44 UTC (rev 1340)
+++ trunk/doc/faq/faq.tex 2008-06-14 20:29:35 UTC (rev 1341)
@@ -304,11 +304,26 @@
Several items can be added as strings separated by ";". This
approach is used in the examples/sniffer.
-\item If a more customised startup is required for your system, rename
- bin/build.xml to bin/c-build.xml and edit the c-build.xml script as
- you want. If a c-build.xml file exists, it is used instead of
- build.xml and no new script is created each time you execute the
- system.
+\item If a more customised startup is required for your system, create
+ a file named bin/c-build.xml with the template below:
+
+\begin{verbatim}
+<project name ="mybuild" basedir="..">
+ <import file="build.xml"/>
+
+ <target name="user-init">
+ <!-- add here all your custom initialisation -->
+ </target>
+
+ <target name="user-end">
+ <!-- add here all your custom termination -->
+ </target>
+
+ <!-- you can also "override" other tasks from build.xml -->
+</project>
+\end{verbatim}
+ If a c-build.xml file exists, it is used to run your application
+ instead of build.xml.
\end{enumerate}
\subsection{Which execution modes are available?}
Modified: trunk/examples/food-simulation/src/java/FoodEnvironment.java
===================================================================
--- trunk/examples/food-simulation/src/java/FoodEnvironment.java 2008-06-13 17:42:44 UTC (rev 1340)
+++ trunk/examples/food-simulation/src/java/FoodEnvironment.java 2008-06-14 20:29:35 UTC (rev 1341)
@@ -56,6 +56,8 @@
id2ag.put(lastUsedId, agName);
return lastUsedId;
}
+
+ // TODO: implement simultaneous attack
@Override
public boolean executeAction(String agName, Structure action) {
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-06-13 17:42:44 UTC (rev 1340)
+++ trunk/release-notes.txt 2008-06-14 20:29:35 UTC (rev 1341)
@@ -60,7 +60,7 @@
presented in http://jasss.soc.surrey.ac.uk/1/3/3.html
Bugs fixed:
-. BUF add annotation "source(percept)" in the perception deletion event
+. BUF doesn't add annotation "source(percept)" in the perception deletion event
. drop_desire does not remove desires in Circumstance.Event correctly
when annotations are used
. print works like println
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-06-24 13:15:08
|
Revision: 1342
http://jason.svn.sourceforge.net/jason/?rev=1342&view=rev
Author: jomifred
Date: 2008-06-24 06:15:06 -0700 (Tue, 24 Jun 2008)
Log Message:
-----------
fix bug in =..
start fixing the bug reported by Sthepen
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/tests/TestAll.java
trunk/release-notes.txt
trunk/src/jason/asSemantics/TransitionSystem.java
trunk/src/jason/asSemantics/Unifier.java
trunk/src/jason/asSyntax/Atom.java
trunk/src/jason/asSyntax/ListTermImpl.java
trunk/src/jason/asSyntax/Literal.java
trunk/src/jason/asSyntax/Structure.java
trunk/src/jason/asSyntax/UnnamedVar.java
trunk/src/jason/asSyntax/VarTerm.java
trunk/src/jason/environment/Environment.java
trunk/src/test/VarTermTest.java
Added Paths:
-----------
trunk/applications/as-unit-test/src/jason/tests/BugVarsAsArg.java
Added: trunk/applications/as-unit-test/src/jason/tests/BugVarsAsArg.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/BugVarsAsArg.java (rev 0)
+++ trunk/applications/as-unit-test/src/jason/tests/BugVarsAsArg.java 2008-06-24 13:15:06 UTC (rev 1342)
@@ -0,0 +1,39 @@
+package jason.tests;
+
+import jason.asunit.TestAgent;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/** based on bug found by Stephen Cranefield -- see jason list */
+public class BugVarsAsArg {
+
+ TestAgent ag;
+
+ // initialisation of the agent test
+ @Before
+ public void setupAg() {
+ ag = new TestAgent();
+
+ // defines the agent's AgentSpeak code
+ ag.parseAScode(
+ "test_rule(A,a(A)). "+
+ "ml0(L,L). "+
+ "ml(V1,V2,R) :- ml0([V1,V2],R). "+
+ "+!test1 <- ?test_rule(T,A); A = a(V); T=45; jason.asunit.print(V). "+
+ "+!test2 <- ?ml(A,B,L); A=1; B=2; jason.asunit.print(L). "
+ );
+ }
+
+ @Test
+ public void testRule1() {
+ ag.addGoal("test1");
+ ag.assertPrint("45", 5);
+ }
+
+ @Test
+ public void testRule2() {
+ ag.addGoal("test2");
+ ag.assertPrint("[1,2]", 5);
+ }
+}
Modified: trunk/applications/as-unit-test/src/jason/tests/TestAll.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2008-06-14 20:29:35 UTC (rev 1341)
+++ trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2008-06-24 13:15:06 UTC (rev 1342)
@@ -8,6 +8,7 @@
@SuiteClasses({
BugListReturnUnification.class,
BugVarsInInitBels.class,
+ BugVarsAsArg.class,
TestAddLogExprInBB.class,
TestGoalSource.class,
TestIF.class,
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-06-14 20:29:35 UTC (rev 1341)
+++ trunk/release-notes.txt 2008-06-24 13:15:06 UTC (rev 1342)
@@ -64,6 +64,7 @@
. drop_desire does not remove desires in Circumstance.Event correctly
when annotations are used
. print works like println
+. =.. with atoms
-------------
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2008-06-14 20:29:35 UTC (rev 1341)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2008-06-24 13:15:06 UTC (rev 1342)
@@ -658,6 +658,7 @@
// they are anonymous)
Literal tel = topIM.getPlan().getTrigger().getLiteral();
tel.apply(topIM.unif);
+ tel.makeVarsAnnon();
im.unif.unifies(tel, g);
}
}
Modified: trunk/src/jason/asSemantics/Unifier.java
===================================================================
--- trunk/src/jason/asSemantics/Unifier.java 2008-06-14 20:29:35 UTC (rev 1341)
+++ trunk/src/jason/asSemantics/Unifier.java 2008-06-24 13:15:06 UTC (rev 1342)
@@ -207,9 +207,9 @@
return unifiesNoUndo(t1gv, t2vl);
}
- // both are var (not unnamedvar) with no value, like X=Y
+ // both are var with no value, like X=Y
// we must ensure that these vars will form a cluster
- if (! t1gv.isUnnamedVar() && ! t2gv.isUnnamedVar()) {
+ //if (! t1gv.isUnnamedVar() && ! t2gv.isUnnamedVar()) {
VarTerm t1c = (VarTerm) t1gv.clone();
VarTerm t2c = (VarTerm) t2gv.clone();
VarsCluster cluster = new VarsCluster(t1c, t2c, this);
@@ -219,7 +219,7 @@
function.put(vtc, cluster);
}
}
- }
+ //}
return true;
}
Modified: trunk/src/jason/asSyntax/Atom.java
===================================================================
--- trunk/src/jason/asSyntax/Atom.java 2008-06-14 20:29:35 UTC (rev 1341)
+++ trunk/src/jason/asSyntax/Atom.java 2008-06-24 13:15:06 UTC (rev 1342)
@@ -115,6 +115,11 @@
}
@Override
+ public List<Term> getTerms() {
+ return emptyTermList;
+ }
+
+ @Override
public Term[] getTermsArray() {
return emptyTermArray;
}
Modified: trunk/src/jason/asSyntax/ListTermImpl.java
===================================================================
--- trunk/src/jason/asSyntax/ListTermImpl.java 2008-06-14 20:29:35 UTC (rev 1341)
+++ trunk/src/jason/asSyntax/ListTermImpl.java 2008-06-24 13:15:06 UTC (rev 1342)
@@ -436,6 +436,7 @@
@SuppressWarnings("unchecked")
public boolean addAll(Collection c) {
+ if (c == null) return false;
ListTerm lt = this; // where to add
Iterator i = c.iterator();
while (i.hasNext()) {
Modified: trunk/src/jason/asSyntax/Literal.java
===================================================================
--- trunk/src/jason/asSyntax/Literal.java 2008-06-14 20:29:35 UTC (rev 1341)
+++ trunk/src/jason/asSyntax/Literal.java 2008-06-24 13:15:06 UTC (rev 1342)
@@ -165,6 +165,7 @@
Unifier ruleUn = ruleIt.next(); // evaluation result
Literal rhead = rule.headClone();
rhead.apply(ruleUn);
+ rhead.makeVarsAnnon();
Unifier unC = un.copy();
if (unC.unifiesNoUndo(Literal.this, rhead)) {
Modified: trunk/src/jason/asSyntax/Structure.java
===================================================================
--- trunk/src/jason/asSyntax/Structure.java 2008-06-14 20:29:35 UTC (rev 1341)
+++ trunk/src/jason/asSyntax/Structure.java 2008-06-24 13:15:06 UTC (rev 1342)
@@ -48,7 +48,9 @@
private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(Structure.class.getName());
- protected static final Term[] emptyTermArray = new Term[0]; // just to have a type for toArray in the getTermsArray method
+
+ protected static final List<Term> emptyTermList = new ArrayList<Term>(0);
+ protected static final Term[] emptyTermArray = new Term[0]; // just to have a type for toArray in the getTermsArray method
private final String functor; // immutable field
Modified: trunk/src/jason/asSyntax/UnnamedVar.java
===================================================================
--- trunk/src/jason/asSyntax/UnnamedVar.java 2008-06-14 20:29:35 UTC (rev 1341)
+++ trunk/src/jason/asSyntax/UnnamedVar.java 2008-06-24 13:15:06 UTC (rev 1342)
@@ -35,12 +35,16 @@
private static int varCont = 1;
public UnnamedVar() {
- super("_" + (varCont++));
+ super(createNewName());
}
public UnnamedVar(String name) {
super( name.length() == 1 ? "_" + (varCont++) : name);
}
+
+ public static String createNewName() {
+ return "_" + (varCont++);
+ }
public Object clone() {
if (hasValue()) {
Modified: trunk/src/jason/asSyntax/VarTerm.java
===================================================================
--- trunk/src/jason/asSyntax/VarTerm.java 2008-06-14 20:29:35 UTC (rev 1341)
+++ trunk/src/jason/asSyntax/VarTerm.java 2008-06-24 13:15:06 UTC (rev 1342)
@@ -53,6 +53,8 @@
private Term value = null;
+ private String unnamedId = null; // set when transformed in unnamed var
+
public VarTerm(String s) {
super(s);
if (s != null && Character.isLowerCase(s.charAt(0))) {
@@ -79,6 +81,7 @@
// do not call constructor with term parameter!
VarTerm t = new VarTerm(super.getFunctor());
t.setSrc(this);
+ t.unnamedId = this.unnamedId;
if (hasAnnot())
t.setAnnots((ListTerm) getAnnots().clone());
return t;
@@ -91,8 +94,21 @@
}
public boolean isUnnamedVar() {
- return false;
+ return unnamedId != null;
}
+
+ /** change the functor of the var to _ */
+ public void setUnnamed() {
+ unnamedId = UnnamedVar.createNewName();
+ }
+ public void setUnnamed(String id) {
+ unnamedId = id;
+ }
+
+ /** undo the setUnanamed() */
+ public void setNamed() {
+ unnamedId = null;
+ }
@Override
public boolean isGround() {
@@ -192,7 +208,10 @@
@Override
public String getFunctor() {
if (value == null) {
- return super.getFunctor();
+ if (unnamedId != null)
+ return unnamedId;
+ else
+ return super.getFunctor();
} else if (value.isStructure()) {
return ((Structure)getValue()).getFunctor();
} else {
Modified: trunk/src/jason/environment/Environment.java
===================================================================
--- trunk/src/jason/environment/Environment.java 2008-06-14 20:29:35 UTC (rev 1341)
+++ trunk/src/jason/environment/Environment.java 2008-06-24 13:15:06 UTC (rev 1342)
@@ -324,6 +324,7 @@
* Execute 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.");
return true;
}
}
Modified: trunk/src/test/VarTermTest.java
===================================================================
--- trunk/src/test/VarTermTest.java 2008-06-14 20:29:35 UTC (rev 1341)
+++ trunk/src/test/VarTermTest.java 2008-06-24 13:15:06 UTC (rev 1342)
@@ -485,4 +485,14 @@
x.apply(u);
assertEquals(x.toString(), "10");
}
+
+ public void testTransformUnnamed() {
+ VarTerm x = new VarTerm("X");
+ assertFalse(x.isUnnamedVar());
+ x.setUnnamed();
+ assertTrue(x.isUnnamedVar());
+ assertFalse("X".equals(x.toString()));
+ x.setNamed();
+ assertTrue("X".equals(x.toString()));
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-06-24 16:19:18
|
Revision: 1344
http://jason.svn.sourceforge.net/jason/?rev=1344&view=rev
Author: jomifred
Date: 2008-06-24 09:19:11 -0700 (Tue, 24 Jun 2008)
Log Message:
-----------
add order in the unnamed vars based on their ids.
Modified Paths:
--------------
trunk/release-notes.txt
trunk/src/jason/asSyntax/UnnamedVar.java
trunk/src/test/VarTermTest.java
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-06-24 15:20:36 UTC (rev 1343)
+++ trunk/release-notes.txt 2008-06-24 16:19:11 UTC (rev 1344)
@@ -65,6 +65,7 @@
when annotations are used
. print works like println
. =.. with atoms
+. unbound vars as arguments for rules (as identified by Stephen Cranefield)
-------------
Modified: trunk/src/jason/asSyntax/UnnamedVar.java
===================================================================
--- trunk/src/jason/asSyntax/UnnamedVar.java 2008-06-24 15:20:36 UTC (rev 1343)
+++ trunk/src/jason/asSyntax/UnnamedVar.java 2008-06-24 16:19:11 UTC (rev 1344)
@@ -33,17 +33,21 @@
private static final long serialVersionUID = 1L;
private static int varCont = 1;
-
+ private int myId;
+
public UnnamedVar() {
- super(createNewName());
+ super("_" + (varCont++));
+ myId = varCont;
}
public UnnamedVar(String name) {
super( name.length() == 1 ? "_" + (varCont++) : name);
+ myId = varCont;
}
-
- public static String createNewName() {
- return "_" + (varCont++);
+
+ public UnnamedVar(int id) {
+ super("_" + id);
+ myId = id;
}
public Object clone() {
@@ -51,11 +55,27 @@
return getValue().clone();
} else {
UnnamedVar newv = new UnnamedVar(getFunctor());
+ newv.myId = this.myId;
if (hasAnnot())
newv.addAnnots((ListTerm)this.getAnnots().clone());
return newv;
}
}
+
+ public int compareTo(Term t) {
+ if (hasValue()) {
+ return super.compareTo(t);
+ } else if (t instanceof UnnamedVar) {
+ if (myId > ((UnnamedVar)t).myId)
+ return 1;
+ else if (myId < ((UnnamedVar)t).myId)
+ return -1;
+ else
+ return 0;
+ } else {
+ return super.compareTo(t);
+ }
+ }
@Override
public boolean isUnnamedVar() {
Modified: trunk/src/test/VarTermTest.java
===================================================================
--- trunk/src/test/VarTermTest.java 2008-06-24 15:20:36 UTC (rev 1343)
+++ trunk/src/test/VarTermTest.java 2008-06-24 16:19:11 UTC (rev 1344)
@@ -15,6 +15,7 @@
import jason.asSyntax.Pred;
import jason.asSyntax.Structure;
import jason.asSyntax.Term;
+import jason.asSyntax.UnnamedVar;
import jason.asSyntax.VarTerm;
import jason.asSyntax.ArithExpr.ArithmeticOp;
import jason.asSyntax.parser.SimpleCharStream;
@@ -23,8 +24,11 @@
import jason.infra.centralised.CentralisedAgArch;
import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
@@ -484,5 +488,16 @@
x.apply(u);
assertEquals(x.toString(), "10");
- }
+ }
+
+ public void testUnnamedvarsorder() {
+ // the order is important for the "return" of plans/rules (where makeVarAnnon is used)
+ // the most recently created unnamed vars should come first
+ List<UnnamedVar> l = new ArrayList<UnnamedVar>();
+ l.add(new UnnamedVar(5));
+ l.add(new UnnamedVar(6));
+ l.add(new UnnamedVar(11));
+ Collections.sort(l);
+ assertEquals("[_5, _6, _11]", l.toString());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-07-05 09:37:56
|
Revision: 1347
http://jason.svn.sourceforge.net/jason/?rev=1347&view=rev
Author: jomifred
Date: 2008-07-05 02:37:52 -0700 (Sat, 05 Jul 2008)
Log Message:
-----------
test all exampels/demos and fix some minor issues
Modified Paths:
--------------
trunk/demos/function/a.asl
trunk/demos/persistent-belief-base/VoidBB.java
trunk/demos/persistent-belief-base/bookstore.properties
trunk/examples/gold-miners-II/arch/MinerArch.java
trunk/src/jason/asSemantics/SuspendInternalAction.java
trunk/src/jason/infra/centralised/CentralisedAgArch.java
trunk/src/jason/jeditplugin/JasonID.java
trunk/src/jason/mas2j/MAS2JProject.java
trunk/src/jeditPlugin/Jason.props
trunk/src/jeditPlugin/actions.xml
Modified: trunk/demos/function/a.asl
===================================================================
--- trunk/demos/function/a.asl 2008-07-02 10:13:59 UTC (rev 1346)
+++ trunk/demos/function/a.asl 2008-07-05 09:37:52 UTC (rev 1347)
@@ -32,7 +32,7 @@
/* Initial goals */
-//!show_predef_funtion.
+!show_predef_funtion.
!show_userdef_funtion.
/* Plans */
Modified: trunk/demos/persistent-belief-base/VoidBB.java
===================================================================
--- trunk/demos/persistent-belief-base/VoidBB.java 2008-07-02 10:13:59 UTC (rev 1346)
+++ trunk/demos/persistent-belief-base/VoidBB.java 2008-07-05 09:37:52 UTC (rev 1347)
@@ -43,6 +43,7 @@
return new ArrayList<Literal>().iterator();
}
+ @Deprecated
public Iterator<Literal> getAll() {
return iterator();
}
@@ -59,6 +60,7 @@
return new ArrayList<Literal>().iterator();
}
+ @Deprecated
public Iterator<Literal> getRelevant(Literal l) {
return new ArrayList<Literal>().iterator();
}
Modified: trunk/demos/persistent-belief-base/bookstore.properties
===================================================================
--- trunk/demos/persistent-belief-base/bookstore.properties 2008-07-02 10:13:59 UTC (rev 1346)
+++ trunk/demos/persistent-belief-base/bookstore.properties 2008-07-05 09:37:52 UTC (rev 1347)
@@ -1,5 +1,5 @@
#HSQL Database Engine
-#Tue Jan 08 10:15:50 CET 2008
+#Sat Jul 05 11:30:42 CEST 2008
hsqldb.script_format=0
runtime.gc_interval=0
sql.enforce_strict_size=false
Modified: trunk/examples/gold-miners-II/arch/MinerArch.java
===================================================================
--- trunk/examples/gold-miners-II/arch/MinerArch.java 2008-07-02 10:13:59 UTC (rev 1346)
+++ trunk/examples/gold-miners-II/arch/MinerArch.java 2008-07-05 09:37:52 UTC (rev 1347)
@@ -4,7 +4,6 @@
import jason.RevisionFailedException;
import jason.architecture.AgArch;
import jason.asSemantics.Message;
-import jason.asSyntax.Atom;
import jason.asSyntax.Literal;
import jason.asSyntax.NumberTerm;
import jason.asSyntax.PredicateIndicator;
Modified: trunk/src/jason/asSemantics/SuspendInternalAction.java
===================================================================
--- trunk/src/jason/asSemantics/SuspendInternalAction.java 2008-07-02 10:13:59 UTC (rev 1346)
+++ trunk/src/jason/asSemantics/SuspendInternalAction.java 2008-07-05 09:37:52 UTC (rev 1347)
@@ -3,6 +3,7 @@
import jason.asSyntax.InternalActionLiteral;
import jason.asSyntax.PlanBody;
import jason.asSyntax.PlanBodyImpl;
+import jason.asSyntax.Term;
import jason.asSyntax.PlanBody.BodyType;
import java.util.concurrent.TimeUnit;
@@ -31,6 +32,10 @@
return true;
}
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ return false;
+ }
+
/**
* Suspend the current intention, put it in the PendingIntention (PI) structure and assigns it to a key.
*
Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2008-07-02 10:13:59 UTC (rev 1346)
+++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2008-07-05 09:37:52 UTC (rev 1347)
@@ -233,6 +233,8 @@
// this is used by the .send internal action in stdlib
public void sendMsg(Message m) throws ReceiverNotFoundException {
// actually send the message
+ if (m.getSender() == null) m.setSender(getAgName());
+
CentralisedAgArch rec = masRunner.getAg(m.getReceiver());
if (rec == null) {
Modified: trunk/src/jason/jeditplugin/JasonID.java
===================================================================
--- trunk/src/jason/jeditplugin/JasonID.java 2008-07-02 10:13:59 UTC (rev 1346)
+++ trunk/src/jason/jeditplugin/JasonID.java 2008-07-05 09:37:52 UTC (rev 1347)
@@ -627,8 +627,8 @@
ex.printStackTrace();
}
}
-
- public void createJar() {
+
+ public void runAntTask(String task) {
final Buffer b = getProjectBuffer();
if (b == null) {
textArea.setText("There is no Jason project opened!");
@@ -636,28 +636,12 @@
}
MAS2JProject project = parseProject(b);
if (project == null) // || !parseProjectAS(project)) {
- return;
- CentralisedMASLauncherAnt script = new CentralisedMASLauncherAnt("jar");
- script.setProject(project);
- if (script.writeScripts(false)) {
- new Thread(script, "Ant-Task").start();
- }
- }
-
- public void createJnlp() {
- final Buffer b = getProjectBuffer();
- if (b == null) {
- textArea.setText("There is no Jason project opened!");
return;
- }
- MAS2JProject project = parseProject(b);
- if (project == null) // || !parseProjectAS(project)) {
- return;
- CentralisedMASLauncherAnt script = new CentralisedMASLauncherAnt("jnlp");
+ CentralisedMASLauncherAnt script = new CentralisedMASLauncherAnt(task);
script.setProject(project);
if (script.writeScripts(false)) {
new Thread(script, "Ant-Task").start();
}
- }
-
+
+ }
}
Modified: trunk/src/jason/mas2j/MAS2JProject.java
===================================================================
--- trunk/src/jason/mas2j/MAS2JProject.java 2008-07-02 10:13:59 UTC (rev 1346)
+++ trunk/src/jason/mas2j/MAS2JProject.java 2008-07-05 09:37:52 UTC (rev 1347)
@@ -198,7 +198,7 @@
r.add(getDirectory());
}
for (String p: sourcepaths) {
- if (isDefaultDirectory()) {
+ if (getDirectory().startsWith(".") || getDirectory().startsWith("/") || getDirectory().charAt(1) == ':') {
r.add(p);
} else {
r.add(getDirectory()+File.separator+p);
Modified: trunk/src/jeditPlugin/Jason.props
===================================================================
--- trunk/src/jeditPlugin/Jason.props 2008-07-02 10:13:59 UTC (rev 1346)
+++ trunk/src/jeditPlugin/Jason.props 2008-07-05 09:37:52 UTC (rev 1347)
@@ -14,7 +14,7 @@
# application menu items
plugin.jason.jeditplugin.JasonIDPlugin.menu=jason - \
- jason.run-project jason.debug-project jason.stop-mas \
+ jason.run-project jason.debug-project jason.stop-mas jason.clean-project \
- \
jason.new-project \
jason.new-ag \
@@ -36,6 +36,7 @@
jason.new-ag.label=New Agent
jason.create-env.label=Create project environment
jason.new-ia.label=New internal action
+jason.clean-project.label=Clean Project
jason.edit-log.label=Edit log parameters
jason.asl2html.label=ASL to HTML
jason.asl2tex.label=ASL to LaTeX
Modified: trunk/src/jeditPlugin/actions.xml
===================================================================
--- trunk/src/jeditPlugin/actions.xml 2008-07-02 10:13:59 UTC (rev 1346)
+++ trunk/src/jeditPlugin/actions.xml 2008-07-05 09:37:52 UTC (rev 1347)
@@ -27,6 +27,12 @@
wm.getDockable(jason.jeditplugin.JasonIDPlugin.NAME).newProject();
</CODE>
</ACTION>
+ <ACTION NAME="jason.clean-project">
+ <CODE>
+ wm.addDockableWindow(jason.jeditplugin.JasonIDPlugin.NAME);
+ wm.getDockable(jason.jeditplugin.JasonIDPlugin.NAME).runAntTask("clean");
+ </CODE>
+ </ACTION>
<ACTION NAME="jason.new-ag">
<CODE>
wm.addDockableWindow(jason.jeditplugin.JasonIDPlugin.NAME);
@@ -66,13 +72,13 @@
<ACTION NAME="jason.create-jar">
<CODE>
wm.addDockableWindow(jason.jeditplugin.JasonIDPlugin.NAME);
- wm.getDockable(jason.jeditplugin.JasonIDPlugin.NAME).createJar();
+ wm.getDockable(jason.jeditplugin.JasonIDPlugin.NAME).runAntTask("jar");
</CODE>
</ACTION>
<ACTION NAME="jason.create-jnlp">
<CODE>
wm.addDockableWindow(jason.jeditplugin.JasonIDPlugin.NAME);
- wm.getDockable(jason.jeditplugin.JasonIDPlugin.NAME).createJnlp();
+ wm.getDockable(jason.jeditplugin.JasonIDPlugin.NAME).runAntTask("jnlp");
</CODE>
</ACTION>
</ACTIONS>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-07-06 15:58:22
|
Revision: 1348
http://jason.svn.sourceforge.net/jason/?rev=1348&view=rev
Author: jomifred
Date: 2008-07-06 08:58:16 -0700 (Sun, 06 Jul 2008)
Log Message:
-----------
small changes for 1.1.2
Modified Paths:
--------------
trunk/applications/jason-team/readme.txt
trunk/applications/jason-team/screenshots/s1b.txt
trunk/applications/jason-team/screenshots/s1c ag against their curral.txt
trunk/demos/gui/readme.txt
trunk/release-notes.txt
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
Added Paths:
-----------
trunk/src/jason/stdlib/if_then_else.java
Removed Paths:
-------------
trunk/src/jason/stdlib/conditional.java
Modified: trunk/applications/jason-team/readme.txt
===================================================================
--- trunk/applications/jason-team/readme.txt 2008-07-05 09:37:52 UTC (rev 1347)
+++ trunk/applications/jason-team/readme.txt 2008-07-06 15:58:16 UTC (rev 1348)
@@ -10,8 +10,8 @@
*/
-To run this team Jason 1.1.2 is required.
-
+To run this team Jason 1.1.2 is required.
+
Steps:
1. run massim-server
Modified: trunk/applications/jason-team/screenshots/s1b.txt
===================================================================
--- trunk/applications/jason-team/screenshots/s1b.txt 2008-07-05 09:37:52 UTC (rev 1347)
+++ trunk/applications/jason-team/screenshots/s1b.txt 2008-07-06 15:58:16 UTC (rev 1348)
@@ -1,79 +1,79 @@
-|---------------------------------------------------------------------------------|
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| X XXXXXXXXX X |
-| X XXX XXX X |
-| XX XXX XXX XX |
-| XX XXX XXX XX |
-| XXX XXX XXX XXX |
-| XXXX XXX XXX XXXX |
-| XXXXXX XXXXXX |
-| X X |
-| XXXXXX X X XXXXXX |
-| X XXXXX XX XX XXXXX X |
-| XX XXXXXXXX XXXXXXXX XX |
-| X ------ XXXXXX X |
-| X ------ XXXXXX X |
-| X ------ XXXXXX X |
-| X c ------ XXXXXX X |
-| XX cc ------ XXXXXX XX |
-| XX ------ XXXXXX XX |
-| XX 1 XXX ------ XXXXXX XXX XX |
-| XX X ------ XXXXXX X XX |
-| X X |
-| X X |
-| c X X |
-| c X X 32 |
-| X X |
-| XX XX 6 |
-| c X X 4 |
-| X X |
-| XX XX |
-| X X |
-| XX XX |
-| X X |
-| XX X X XX |
-| X X X X |
-| XX XX XX XX |
-| X XXX XXX X |
-| X XXXX XXXX X |
-| X XXX XXX X |
-| X XX XX X |
-| XX XX |
-| X X X X |
-| X X |
-| XXX XXX XXX XXX |
-| X X |
-| XXXX XXXX |
-| X XXXXXXXXXX XX X |
-| XX X X XX |
-| XX XX |
-| XX XX X |
-| XXXX |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-| |
-|---------------------------------------------------------------------------------|
+|---------------------------------------------------------------------------------|
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| X XXXXXXXXX X |
+| X XXX XXX X |
+| XX XXX XXX XX |
+| XX XXX XXX XX |
+| XXX XXX XXX XXX |
+| XXXX XXX XXX XXXX |
+| XXXXXX XXXXXX |
+| X X |
+| XXXXXX X X XXXXXX |
+| X XXXXX XX XX XXXXX X |
+| XX XXXXXXXX XXXXXXXX XX |
+| X ------ XXXXXX X |
+| X ------ XXXXXX X |
+| X ------ XXXXXX X |
+| X c ------ XXXXXX X |
+| XX cc ------ XXXXXX XX |
+| XX ------ XXXXXX XX |
+| XX 1 XXX ------ XXXXXX XXX XX |
+| XX X ------ XXXXXX X XX |
+| X X |
+| X X |
+| c X X |
+| c X X 32 |
+| X X |
+| XX XX 6 |
+| c X X 4 |
+| X X |
+| XX XX |
+| X X |
+| XX XX |
+| X X |
+| XX X X XX |
+| X X X X |
+| XX XX XX XX |
+| X XXX XXX X |
+| X XXXX XXXX X |
+| X XXX XXX X |
+| X XX XX X |
+| XX XX |
+| X X X X |
+| X X |
+| XXX XXX XXX XXX |
+| X X |
+| XXXX XXXX |
+| X XXXXXXXXXX XX X |
+| XX X X XX |
+| XX XX |
+| XX XX X |
+| XXXX |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+| |
+|---------------------------------------------------------------------------------|
Modified: trunk/applications/jason-team/screenshots/s1c ag against their curral.txt
===================================================================
--- trunk/applications/jason-team/screenshots/s1c ag against their curral.txt 2008-07-05 09:37:52 UTC (rev 1347)
+++ trunk/applications/jason-team/screenshots/s1c ag against their curral.txt 2008-07-06 15:58:16 UTC (rev 1348)
@@ -1,64 +1,64 @@
-| |
-| |
-| |
-| |
-| |
-| XXXXXXXXX |
-| XXX XXX |
-| X XXX XXX |
-| XX XXX XXX XX |
-| XXX XXX XXX XXX |
-| XXXX XXX XXX XXXX |
-| XXXXXX XXXXXX |
-| X X |
-| XXXXXX X X c XXXXXX |
-| X XXXXX XX XX c XXXXX X |
-| X XXXXXXXX XXXXXXXX XX |
-| X ------ XXXXXX X |
-| X ------ XXXXXX c X |
-| X ------ XXXXXX X |
-| X ------ XXXXXX X |
-| XX ------ XXXXXX 1 4 XX |
-| XX ------ XXXXXX E cE XX |
-| XX XXX ------ XXXXXX XXX 3 XX |
-| XX X ------ XXXXXX X XX |
-| X X |
-| X X c |
-| X X E |
-| X X |
-| X X |
-| XX XX |
-| X X |
-| X X |
-| X X |
-| X X |
-| X X |
-| XX XX |
-| XX XX |
-| X X |
-| XX XX |
-| X 2 X |
-| XX X X XX |
-| X X X X |
-| XX XX XX XX |
-| X XX XXX X |
-| X XXXX X |
-| X XXX X |
-| X XX X |
-| XX XX |
-| X X X X |
-| X X |
-| XXX XXX XXX |
-| X |
-| XXXX |
-| XXXXXXXXXX X |
-| X XX5 |
-| XX |
-| XXXX XX 6 |
-| XXXX |
-| |
-| |
-| |
-| |
-| |
-| |
+| |
+| |
+| |
+| |
+| |
+| XXXXXXXXX |
+| XXX XXX |
+| X XXX XXX |
+| XX XXX XXX XX |
+| XXX XXX XXX XXX |
+| XXXX XXX XXX XXXX |
+| XXXXXX XXXXXX |
+| X X |
+| XXXXXX X X c XXXXXX |
+| X XXXXX XX XX c XXXXX X |
+| X XXXXXXXX XXXXXXXX XX |
+| X ------ XXXXXX X |
+| X ------ XXXXXX c X |
+| X ------ XXXXXX X |
+| X ------ XXXXXX X |
+| XX ------ XXXXXX 1 4 XX |
+| XX ------ XXXXXX E cE XX |
+| XX XXX ------ XXXXXX XXX 3 XX |
+| XX X ------ XXXXXX X XX |
+| X X |
+| X X c |
+| X X E |
+| X X |
+| X X |
+| XX XX |
+| X X |
+| X X |
+| X X |
+| X X |
+| X X |
+| XX XX |
+| XX XX |
+| X X |
+| XX XX |
+| X 2 X |
+| XX X X XX |
+| X X X X |
+| XX XX XX XX |
+| X XX XXX X |
+| X XXXX X |
+| X XXX X |
+| X XX X |
+| XX XX |
+| X X X X |
+| X X |
+| XXX XXX XXX |
+| X |
+| XXXX |
+| XXXXXXXXXX X |
+| X XX5 |
+| XX |
+| XXXX XX 6 |
+| XXXX |
+| |
+| |
+| |
+| |
+| |
+| |
Modified: trunk/demos/gui/readme.txt
===================================================================
--- trunk/demos/gui/readme.txt 2008-07-05 09:37:52 UTC (rev 1347)
+++ trunk/demos/gui/readme.txt 2008-07-06 15:58:16 UTC (rev 1348)
@@ -1,18 +1,18 @@
-There are many ways of creating GUI for Jason agents.
-All of them relies on Java.
-
-This directory contains the following examples:
-
-gui1: uses and internal action to ask something to the user
-
-gui2: creates a window with buttons that, when pressed,
- produce events the agent can react to.
-
-
-Some examples of Jason also use GUI:
-
-auction: uses a customised agent architecture that provides special
- actions to show information in a GUI
-
-domestic-robot, iterated-prisoners-dilemma, and many others: the GUI
- is implemented and maintained by the environment.
\ No newline at end of file
+There are many ways of creating GUI for Jason agents.
+All of them relies on Java.
+
+This directory contains the following examples:
+
+gui1: uses and internal action to ask something to the user
+
+gui2: creates a window with buttons that, when pressed,
+ produce events the agent can react to.
+
+
+Some examples of Jason also use GUI:
+
+auction: uses a customised agent architecture that provides special
+ actions to show information in a GUI
+
+domestic-robot, iterated-prisoners-dilemma, and many others: the GUI
+ is implemented and maintained by the environment.
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-07-05 09:37:52 UTC (rev 1347)
+++ trunk/release-notes.txt 2008-07-06 15:58:16 UTC (rev 1348)
@@ -3,7 +3,7 @@
-------------
New features
-. (experimental) control of the execution in plan's body with if, while
+. (experimental) control of the execution in plan bodies with if, while,
and for.
--- if ----
@@ -17,8 +17,9 @@
if <logical formula> holds, <plan_body1> is executed; otherwise,
<plan_body2> is executed.
- e.g.: if (vl(X) & X > 10) { // where vl(X) is a belief
- .print("value > 10")
+ e.g.: if (vl(X) & X > 10 & X < 20) { // where vl(X) is a belief
+ .print("value > 10 and ");
+ .print("value < 20")
}
--- while ---
@@ -41,7 +42,7 @@
<plan_body>
};
- for all unifications of <logical formula> the <plan_body> is executed.
+ the <plan_body> is executed for all unifications of <logical formula>.
e.g.: for ( vl(X) ) {
.print(X)
@@ -55,19 +56,19 @@
New examples and demos:
-. demos/gui: two simple examples of how to make a GUI for agents
+. demos/gui: two simple examples of how to make a GUI for individual agents
. example/food-simulation: implementation of the scenario of simulation
presented in http://jasss.soc.surrey.ac.uk/1/3/3.html
Bugs fixed:
-. BUF doesn't add annotation "source(percept)" in the perception deletion event
-. drop_desire does not remove desires in Circumstance.Event correctly
+. BUF didn't add annotation "source(percept)" in the perception deletion event
+. drop_desire did not remove desires in Circumstance.Event correctly
when annotations are used
-. print works like println
-. =.. with atoms
-. unbound vars as arguments for rules (as identified by Stephen Cranefield)
+. print worked like println
+. problem in =.. with atoms
+. problem in unification whe unbound vars were used as arguments
+ for rules (as identified by Stephen Cranefield)
-
-------------
version 1.1.1
-------------
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-07-05 09:37:52 UTC (rev 1347)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-07-06 15:58:16 UTC (rev 1348)
@@ -403,7 +403,7 @@
]
F=pred() {
if (F.getFunctor().equals("if")) {
- Pred c = new Pred(".conditional");
+ Pred c = new Pred(".if_then_else");
c.setTerms(F.getTerms());
F = c;
} el...
[truncated message content] |
|
From: <jom...@us...> - 2008-07-06 18:04:51
|
Revision: 1349
http://jason.svn.sourceforge.net/jason/?rev=1349&view=rev
Author: jomifred
Date: 2008-07-06 11:04:48 -0700 (Sun, 06 Jul 2008)
Log Message:
-----------
update eclipse-plugin for 1.1.2
Modified Paths:
--------------
trunk/applications/jason-eclipse-plugin/build.xml
trunk/build.xml
Modified: trunk/applications/jason-eclipse-plugin/build.xml
===================================================================
--- trunk/applications/jason-eclipse-plugin/build.xml 2008-07-06 15:58:16 UTC (rev 1348)
+++ trunk/applications/jason-eclipse-plugin/build.xml 2008-07-06 18:04:48 UTC (rev 1349)
@@ -12,12 +12,12 @@
<property name="dist.properties" value="${basedir}/bin/dist.properties" />
<property name="version" value="1" />
- <property name="release" value="1.1" />
+ <property name="release" value="1.2" />
<property name="distDir" value="${basedir}/dist" />
<property name="distDirPlugins" value="${distDir}/plugins" />
<property name="pluginJar" value="${distDirPlugins}/net.sourceforge.jasonide_${version}.${release}.jar" />
- <property name="pluginZip" value="${distDir}/jason-eclipse-plugin-${version}.${release}.zip" />
+ <property name="pluginZip" value="${env.HOME}/jason-eclipse-plugin-${version}.${release}.zip" />
<path id="project.classpath">
<pathelement location="${regexpJar}" />
@@ -35,12 +35,8 @@
</javac>
</target>
- <target name="initJar">
- <mkdir dir="${distDir}" />
- <mkdir dir="${distDirPlugins}" />
- </target>
-
- <target name="jar" depends="compile,initJar">
+ <target name="jar" depends="compile">
+ <mkdir dir="${distDirPlugins}" />
<jar jarfile="${pluginJar}" manifest="${basedir}/META-INF/MANIFEST.MF">
<fileset dir="${build.dir}">
<include name="**/*.class" />
@@ -52,7 +48,13 @@
<include name="plugin.xml" />
</fileset>
</jar>
-
+ </target>
+
+ <target name="dist">
+ <delete failonerror="no" includeEmptyDirs="true">
+ <fileset dir="${distDir}" />
+ </delete>
+ <antcall target="jar" />
<zip destfile="${pluginZip}" basedir="${distDir}" />
</target>
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2008-07-06 15:58:16 UTC (rev 1348)
+++ trunk/build.xml 2008-07-06 18:04:48 UTC (rev 1349)
@@ -15,7 +15,7 @@
<property name="dist.properties" value="${basedir}/bin/dist.properties" />
<property name="version" value="1" />
- <property name="release" value="1.2" />
+ <property name="release" value="1.3" />
<property name="distDir" value="${env.HOME}/tmp/x/Jason-${version}.${release}" />
<property name="distFile" value="${env.HOME}/Jason-${version}.${release}" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-07-10 15:52:27
|
Revision: 1350
http://jason.svn.sourceforge.net/jason/?rev=1350&view=rev
Author: jomifred
Date: 2008-07-10 08:52:25 -0700 (Thu, 10 Jul 2008)
Log Message:
-----------
add two new functions: sum and average
one new IA: term2string
Modified Paths:
--------------
trunk/applications/jason-team/src/team-os.xml
trunk/release-notes.txt
trunk/src/jason/asSyntax/directives/FunctionRegister.java
trunk/src/jason/stdlib/package.html
Added Paths:
-----------
trunk/src/jason/functions/Average.java
trunk/src/jason/functions/Sum.java
trunk/src/jason/stdlib/term2string.java
Modified: trunk/applications/jason-team/src/team-os.xml
===================================================================
--- trunk/applications/jason-team/src/team-os.xml 2008-07-06 18:04:48 UTC (rev 1349)
+++ trunk/applications/jason-team/src/team-os.xml 2008-07-10 15:52:25 UTC (rev 1350)
@@ -85,7 +85,7 @@
</goal>
<goal id="goto_near_unvisited" ds="go to the near unvisited location inside the area of the group" type="maintenance"/>
<goal id="share_seen_cows" ds="share seen cows with other agents in the scheme" type="maintenance"/>
- <goal id="follow_leader" ds="follows the leader of the scheme/group" type="maintenance"/>
+ <goal id="follow_leader" ds="follow the leader of the scheme/group" type="maintenance"/>
</plan>
</goal>
@@ -105,11 +105,12 @@
<goal id="herd_cows" >
<plan operator="parallel">
<goal id="recruit" ds="recruit more herdboys depending on the size of the cows cluster" type="maintenance"/>
- <goal id="release_boys" ds="if the number of agents too much, release some boyd" type="maintenance"/>
+ <goal id="release_boys" ds="if the group has
+ too much boys, release some" type="maintenance"/>
<goal id="define_formation" ds="compute the ideal location of each member of the group and share this information with them" type="maintenance"/>
<goal id="be_in_formation" ds="go to the place allocated to the agent in the formation" type="maintenance"/>
<goal id="share_seen_cows" ds="share seen cows with other agents in the scheme" type="maintenance"/>
- <goal id="change_to_exploring" ds="verify if necessary to finish the herding group and create the exploring groups" type="maintenance"/>
+ <goal id="change_to_exploring" ds="verify if it is necessary to finish the herding group and create the exploring group" type="maintenance"/>
</plan>
</goal>
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-07-06 18:04:48 UTC (rev 1349)
+++ trunk/release-notes.txt 2008-07-10 15:52:25 UTC (rev 1350)
@@ -1,4 +1,18 @@
-------------
+version 1.1.3
+-------------
+
+New internal actions
+. .term2string: transform term into strings and vice-versa.
+
+
+New functions
+. .math.sum: sums a list of numbers
+. .math.average: returns the average of a list of numbers
+
+
+
+-------------
version 1.1.2
-------------
Modified: trunk/src/jason/asSyntax/directives/FunctionRegister.java
===================================================================
--- trunk/src/jason/asSyntax/directives/FunctionRegister.java 2008-07-06 18:04:48 UTC (rev 1349)
+++ trunk/src/jason/asSyntax/directives/FunctionRegister.java 2008-07-10 15:52:25 UTC (rev 1350)
@@ -6,12 +6,14 @@
import jason.asSyntax.Pred;
import jason.asSyntax.StringTerm;
import jason.functions.Abs;
+import jason.functions.Average;
import jason.functions.Length;
import jason.functions.Max;
import jason.functions.Min;
import jason.functions.Random;
import jason.functions.Round;
import jason.functions.Sqrt;
+import jason.functions.Sum;
import jason.functions.ceil;
import jason.functions.e;
import jason.functions.floor;
@@ -39,6 +41,8 @@
addFunction(Abs.class);
addFunction(Max.class);
addFunction(Min.class);
+ addFunction(Sum.class);
+ addFunction(Average.class);
addFunction(Length.class);
addFunction(Random.class);
addFunction(Round.class);
Added: trunk/src/jason/functions/Average.java
===================================================================
--- trunk/src/jason/functions/Average.java (rev 0)
+++ trunk/src/jason/functions/Average.java 2008-07-10 15:52:25 UTC (rev 1350)
@@ -0,0 +1,50 @@
+package jason.functions;
+
+import jason.JasonException;
+import jason.asSemantics.DefaultArithFunction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.NumberTerm;
+import jason.asSyntax.Term;
+
+/**
+<p>Function: <b><code>math.average(L)</code></b>: returns the average of all values of L.
+
+<p>Examples:<ul>
+<li> <code>math.average([1,3])</code>: returns 2.</li>
+<li> <code>math.average([])</code>: fail.</li>
+</ul>
+
+@author Jomi
+
+@see jason.functions.Min
+@see jason.functions.Max
+@see jason.functions.Sum
+
+*/
+public class Average extends DefaultArithFunction {
+
+ public String getName() {
+ return "math.average";
+ }
+
+ @Override
+ public double evaluate(TransitionSystem ts, Term[] args) throws Exception {
+ if (args[0].isList()) {
+ double sum = 0;
+ int n = 0;
+ for (Term t: (ListTerm)args[0])
+ if (t.isNumeric()) {
+ sum += ((NumberTerm)t).solve();
+ n++;
+ }
+ return sum / n;
+ }
+ throw new JasonException(getName()+" is not implemented for type '"+args[0]+"'.");
+ }
+
+ @Override
+ public boolean checkArity(int a) {
+ return a == 1;
+ }
+}
Added: trunk/src/jason/functions/Sum.java
===================================================================
--- trunk/src/jason/functions/Sum.java (rev 0)
+++ trunk/src/jason/functions/Sum.java 2008-07-10 15:52:25 UTC (rev 1350)
@@ -0,0 +1,48 @@
+package jason.functions;
+
+import jason.JasonException;
+import jason.asSemantics.DefaultArithFunction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.NumberTerm;
+import jason.asSyntax.Term;
+
+/**
+<p>Function: <b><code>math.sum(L)</code></b>: sums all values of L.
+
+<p>Examples:<ul>
+<li> <code>math.sum([1,3])</code>: returns 4.</li>
+<li> <code>math.sum([3,a,"s",5])</code>: returns 8.</li>
+<li> <code>math.sum([])</code>: returns 0.</li>
+</ul>
+
+@author Jomi
+
+@see jason.functions.Min
+@see jason.functions.Max
+@see jason.functions.Average
+
+*/
+public class Sum extends DefaultArithFunction {
+
+ public String getName() {
+ return "math.sum";
+ }
+
+ @Override
+ public double evaluate(TransitionSystem ts, Term[] args) throws Exception {
+ if (args[0].isList()) {
+ double sum = 0;
+ for (Term t: (ListTerm)args[0])
+ if (t.isNumeric())
+ sum += ((NumberTerm)t).solve();
+ return sum;
+ }
+ throw new JasonException(getName()+" is not implemented for type '"+args[0]+"'.");
+ }
+
+ @Override
+ public boolean checkArity(int a) {
+ return a == 1;
+ }
+}
Modified: trunk/src/jason/stdlib/package.html
===================================================================
--- trunk/src/jason/stdlib/package.html 2008-07-06 18:04:48 UTC (rev 1349)
+++ trunk/src/jason/stdlib/package.html 2008-07-10 15:52:25 UTC (rev 1350)
@@ -83,6 +83,7 @@
<li>{@link jason.stdlib.reverse}: reverse strings. </li>
<li>{@link jason.stdlib.substring}: test substrings of strings. </li>
<li>{@link jason.stdlib.string}: check whether an argument is a string.</li>
+ <li>{@link jason.stdlib.term2string}: convert terms to strings and vice-versa.</li>
</ul>
<h2>Execution control</h2>
Added: trunk/src/jason/stdlib/term2string.java
===================================================================
--- trunk/src/jason/stdlib/term2string.java (rev 0)
+++ trunk/src/jason/stdlib/term2string.java 2008-07-10 15:52:25 UTC (rev 1350)
@@ -0,0 +1,73 @@
+
+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.DefaultTerm;
+import jason.asSyntax.StringTerm;
+import jason.asSyntax.StringTermImpl;
+import jason.asSyntax.Term;
+
+/**
+ <p>Internal action: <b><code>.term2string(T,S)</code></b>.
+
+ <p>Description: converts the term T into a string S and vice-versa.
+
+ <p>Parameters:<ul>
+ <li>-/+ T (any term).<br/>
+ <li>-/+ S (a string).<br/>
+ </ul>
+
+ <p>Examples:<ul>
+ <li> <code>.substring(b,"b")</code>: true.
+ <li> <code>.substring(b,X)</code>: unifies X to "b".
+ <li> <code>.substring(X,"b")</code>: unified X to b.
+ </ul>
+
+ @see jason.stdlib.concat
+ @see jason.stdlib.delete
+ @see jason.stdlib.length
+ @see jason.stdlib.reverse
+
+*/
+public class term2string extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new term2string();
+ return singleton;
+ }
+
+ @Override
+ public Object execute(TransitionSystem ts, final Unifier un, final Term[] args) throws Exception {
+ try {
+ // case 1, no vars
+ if (!args[0].isVar() && args[1].isString()) {
+ return args[0].toString().equals( ((StringTerm)args[1]).getString() );
+ }
+
+ // case 2, second is var
+ if (!args[0].isVar() && args[1].isVar()) {
+ return un.unifies(new StringTermImpl(args[0].toString()), args[1]);
+ }
+
+ // case 3, first is var
+ if (args[0].isVar() && args[1].isString()) {
+ return un.unifies(args[0], DefaultTerm.parse( ((StringTerm)args[1]).getString() ));
+ }
+
+ throw new JasonException("invalid case of term2string");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new JasonException("The internal action 'term2string' has not received two arguments.");
+ } catch (JasonException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new JasonException("Error in internal action 'term2string': " + e, e);
+ }
+ }
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|