|
From: <jom...@us...> - 2009-02-09 10:31:52
|
Revision: 1433
http://jason.svn.sourceforge.net/jason/?rev=1433&view=rev
Author: jomifred
Date: 2009-02-09 10:31:47 +0000 (Mon, 09 Feb 2009)
Log Message:
-----------
improve getting started exercise and comment solutions
Modified Paths:
--------------
trunk/applications/jason-moise/build.xml
trunk/applications/jason-moise/lib/moise.jar
trunk/doc/mini-tutorial/src/getting-started/VacuumCleaning-1/VCWorld.java
trunk/doc/mini-tutorial/src/getting-started/VacuumCleaning-1/vc.asl
trunk/src/jason/asSyntax/Literal.java
Added Paths:
-----------
trunk/doc/mini-tutorial/src/getting-started/exercise-answers.txt
Modified: trunk/applications/jason-moise/build.xml
===================================================================
--- trunk/applications/jason-moise/build.xml 2009-02-08 18:03:39 UTC (rev 1432)
+++ trunk/applications/jason-moise/build.xml 2009-02-09 10:31:47 UTC (rev 1433)
@@ -8,8 +8,8 @@
<property environment="env"/>
<property name="version" value="1"/>
- <property name="release" value="1.2"/>
- <property name="moiseDir" value="${env.HOME}/Moise/svn-moise" />
+ <property name="release" value="2"/>
+ <property name="moiseDir" value="${env.HOME}/svn-moise" />
<property name="distDir" value="${env.HOME}/tmp/jmoise-${version}.${release}" />
<property name="distFile" value="${env.HOME}/jason-moise-${version}.${release}" />
<property name="doc-src-dir" value="${env.HOME}/programming/Moise-doc" />
@@ -90,6 +90,7 @@
<fileset dir="${basedir}" includes="doc/api/**/*" />
<fileset dir="${basedir}" includes="lib/**/*" />
<fileset dir="${basedir}" includes="example/writePaper/**/*" />
+ <fileset dir="${basedir}" includes="example/moise-tutorial/**/*" />
<fileset dir="${basedir}" includes="example/auction/**/*" excludes="**/nbproject/**,**/profile-build.xml"/>
<fileset dir="${basedir}" includes="src/**/*" />
</copy>
Modified: trunk/applications/jason-moise/lib/moise.jar
===================================================================
(Binary files differ)
Modified: trunk/doc/mini-tutorial/src/getting-started/VacuumCleaning-1/VCWorld.java
===================================================================
--- trunk/doc/mini-tutorial/src/getting-started/VacuumCleaning-1/VCWorld.java 2009-02-08 18:03:39 UTC (rev 1432)
+++ trunk/doc/mini-tutorial/src/getting-started/VacuumCleaning-1/VCWorld.java 2009-02-09 10:31:47 UTC (rev 1433)
@@ -21,12 +21,19 @@
private int vcx = 0; // the vacuum cleaner location
private int vcy = 0;
- private boolean running = true;
-
+ /** general delegations */
private HouseGUI gui = new HouseGUI();
+ private Logger logger = Logger.getLogger("env."+VCWorld.class.getName());
+ private Random r = new Random();
- private Logger logger = Logger.getLogger("env."+VCWorld.class.getName());
-
+ /** constant terms used for perception */
+ private static final Literal lPos1 = ASSyntax.createLiteral("pos", ASSyntax.createNumber(1));
+ private static final Literal lPos2 = ASSyntax.createLiteral("pos", ASSyntax.createNumber(2));
+ private static final Literal lPos3 = ASSyntax.createLiteral("pos", ASSyntax.createNumber(3));
+ private static final Literal lPos4 = ASSyntax.createLiteral("pos", ASSyntax.createNumber(4));
+ private static final Literal lDirty = ASSyntax.createLiteral("dirty");
+ private static final Literal lClean = ASSyntax.createLiteral("clean");
+
public VCWorld() {
createPercept();
gui.paint();
@@ -35,7 +42,7 @@
new Thread() {
public void run() {
try {
- while (running) {
+ while (isRunning()) {
// add ramdom dirty
if (r.nextInt(100) < 20) {
dirty[r.nextInt(2)][r.nextInt(2)] = true;
@@ -49,27 +56,25 @@
}.start();
}
- Random r = new Random();
-
/** create the agents perceptions based on the world model */
private void createPercept() {
// remove previous perception
clearPercepts();
if (vcx == 0 && vcy == 0) {
- addPercept(Literal.parseLiteral("pos(1)"));
+ addPercept(lPos1);
} else if (vcx == 1 && vcy == 0) {
- addPercept(Literal.parseLiteral("pos(2)"));
+ addPercept(lPos2);
} else if (vcx == 0 && vcy == 1) {
- addPercept(Literal.parseLiteral("pos(3)"));
+ addPercept(lPos3);
} else if (vcx == 1 && vcy == 1) {
- addPercept(Literal.parseLiteral("pos(4)"));
+ addPercept(lPos4);
}
if (dirty[vcx][vcy]) {
- addPercept(Literal.parseLiteral("dirty"));
+ addPercept(lDirty);
} else {
- addPercept(Literal.parseLiteral("clean"));
+ addPercept(lClean);
}
}
@@ -115,7 +120,6 @@
@Override
public void stop() {
- running = false;
super.stop();
gui.setVisible(false);
}
Modified: trunk/doc/mini-tutorial/src/getting-started/VacuumCleaning-1/vc.asl
===================================================================
--- trunk/doc/mini-tutorial/src/getting-started/VacuumCleaning-1/vc.asl 2009-02-08 18:03:39 UTC (rev 1432)
+++ trunk/doc/mini-tutorial/src/getting-started/VacuumCleaning-1/vc.asl 2009-02-09 10:31:47 UTC (rev 1433)
@@ -15,4 +15,5 @@
// TODO: the code of the agent
-+dirty <- suck.
+
+
Added: trunk/doc/mini-tutorial/src/getting-started/exercise-answers.txt
===================================================================
--- trunk/doc/mini-tutorial/src/getting-started/exercise-answers.txt (rev 0)
+++ trunk/doc/mini-tutorial/src/getting-started/exercise-answers.txt 2009-02-09 10:31:47 UTC (rev 1433)
@@ -0,0 +1,104 @@
+There are several solutions for the vacuum cleaner. Here we present and
+comment some of them. We start from a very reactive solution and finish
+by a goal-oriented version.
+
+
+
+1. First solution
+
+----------------------------------------
++dirty <- suck.
+
++pos(1) <- right.
++pos(2) <- down.
++pos(3) <- up.
++pos(4) <- left.
+----------------------------------------
+
+* comments
+- reactive agent
+- selection of plans do not use context (beliefs),
+ but only events
+
+* problems
+- may leave dirty behind, you will get messages like
+ [VCWorld] suck in a clean location!
+- reason: the selection of the intention to move ("+pos(...)" plans) are
+ selected before the plan to clean the location
+
+
+2. Second solution
+
+----------------------------------------
++pos(1) : clean <- right.
++pos(2) : clean <- down.
++pos(3) : clean <- up.
++pos(4) : clean <- left.
+
++pos(1) : dirty <- suck; right.
++pos(2) : dirty <- suck; down.
++pos(3) : dirty <- suck; up.
++pos(4) : dirty <- suck; left.
+----------------------------------------
+
+* comments
+- reactive agent
+- selection of plans based on context (perceptual beliefs)
+- solve the problem of first solution
+
+* problems
+- the moving strategy is code in two sets of plans, so to change
+ the strategy we need to recode twice.
+
+
+3. Third solution
+
+----------------------------------------
++pos(_) : clean <- !move.
++pos(_) : dirty <- suck; !move.
+
++!move : pos(1) <- right.
++!move : pos(2) <- down.
++!move : pos(3) <- up.
++!move : pos(4) <- left.
+----------------------------------------
+
+* comments
+- the moving strategy is re-factored in a goal (the goal !move)
+- this agent is still a reactive one (it reacts to the perception of its
+ location), but the reaction creates a new goal (to move)
+- the change the moving strategy we only need to change the
+ way the goal "move" is achieved
+
+* problem
+- suppose that the actions may fail, in this case, to perform 'up', for
+ example, may leave the agent in the same place, so no new location is
+ perceived and the agent will stop moving.
+ (it is an hypothetical case since the environment was not code to
+ simulate action failures)
+
+
+4. Fourth solution
+
+----------------------------------------
+!clean. // initial goal
+
++!clean : clean <- !move; !!clean.
++!clean : dirty <- suck; !move; !!clean.
+-!clean <- !!clean.
+
++!move : pos(1) <- right.
++!move : pos(2) <- down.
++!move : pos(3) <- up.
++!move : pos(4) <- left.
+----------------------------------------
+
+* comments
+- this agent is not reactive anymore, it has a persistent goal (!clean).
+- this goal is implemented by a kind of 'loop', all plans to achieve
+ 'clean' finish by adding 'clean' as a new goal.
+- if something fails to achieve 'clean', the failure handling plan
+ (-!clean) reintroduces the goal again.
+- !! is used instead of ! to avoid big stacks of sub-goals, see
+ http://jason.sourceforge.net/faq/faq.html#SECTION00075000000000000000
+- this agent is thus more 'robust' against action failures
Modified: trunk/src/jason/asSyntax/Literal.java
===================================================================
--- trunk/src/jason/asSyntax/Literal.java 2009-02-08 18:03:39 UTC (rev 1432)
+++ trunk/src/jason/asSyntax/Literal.java 2009-02-09 10:31:47 UTC (rev 1433)
@@ -37,14 +37,17 @@
import java.util.logging.Logger;
/**
- This class represents an abstract literal (an Atom, Structure, Predicate, etc), is is mainly
+ This class represents an abstract literal (an Atom, Structure, Predicate, etc), it is mainly
the interface of a literal.
- To create a Literal, one of the following classes may be used:
- Atom -- the most simple literal, is composed by a functor (no term, no annots);
- Structure -- has functor and terms;
- Pred -- has functor, terms, and annotations;
- LiteralImpl -- Pred + negation. This latter class supports all the operations of
+ To create a new Literal, one of the following concrete classes may be used:
+ <ul>
+ <li> Atom -- the most simple literal, is composed by only a functor (no term, no annots);
+ <li> Structure -- has functor and terms;
+ <li> Pred -- has functor, terms, and annotations;
+ <li> LiteralImpl -- Pred + negation.
+ </ul>
+ The latter class supports all the operations of
the Literal interface.
<p>There are useful static methods in class {@link ASSyntax} to create Literals.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|