|
From: <jom...@us...> - 2015-05-24 22:32:10
|
Revision: 1837
http://sourceforge.net/p/jason/svn/1837
Author: jomifred
Date: 2015-05-24 22:32:07 +0000 (Sun, 24 May 2015)
Log Message:
-----------
add new tutorial (BDI hello world)
Modified Paths:
--------------
trunk/doc/index.html
trunk/examples/cleaning-robots/logging.properties
trunk/src/jason/runtime/MASConsoleColorGUI.java
trunk/src/jason/runtime/MASConsoleGUI.java
Added Paths:
-----------
trunk/doc/mini-tutorial/src/hello-bdi/
trunk/doc/mini-tutorial/src/hello-bdi/Makefile
trunk/doc/mini-tutorial/src/hello-bdi/code/
trunk/doc/mini-tutorial/src/hello-bdi/code/Calendar.java
trunk/doc/mini-tutorial/src/hello-bdi/code/alice.asl
trunk/doc/mini-tutorial/src/hello-bdi/code/bdi_hw.mas2j
trunk/doc/mini-tutorial/src/hello-bdi/code/bob.asl
trunk/doc/mini-tutorial/src/hello-bdi/index.html
trunk/doc/mini-tutorial/src/hello-bdi/index.org
trunk/doc/mini-tutorial/src/hello-bdi/jcm.css
trunk/doc/mini-tutorial/src/hello-bdi/screens/
trunk/doc/mini-tutorial/src/hello-bdi/screens/mind-1.png
trunk/doc/mini-tutorial/src/hello-bdi/screens/mind-2.png
Modified: trunk/doc/index.html
===================================================================
--- trunk/doc/index.html 2015-05-19 16:58:56 UTC (rev 1836)
+++ trunk/doc/index.html 2015-05-24 22:32:07 UTC (rev 1837)
@@ -12,7 +12,8 @@
<li><a href="Jason.pdf">First Manual</a> (pdf)</li><br/>
<li><a href="mini-tutorial/getting-started/index.html">Getting Started with <b><i>Jason</i></b></a> (html)</li>
-<li><a href="mini-tutorial/jason-jade/index.html">Interoperating <b><i>Jason</i></b> and JADE</a> (mini-tutorial -- html)</li><br>
+<li><a href="mini-tutorial/jason-jade/index.html">Interoperating <b><i>Jason</i></b> and JADE</a> (mini-tutorial -- html)</li>
+<li><a href="mini-tutorial/hello-bdi/index.html">BDI concepts in <b><i>Jason</i></b></a> (html)</li><br>
<li><a href="faq.html">FAQ</a> (html)</li><br/>
Added: trunk/doc/mini-tutorial/src/hello-bdi/Makefile
===================================================================
--- trunk/doc/mini-tutorial/src/hello-bdi/Makefile (rev 0)
+++ trunk/doc/mini-tutorial/src/hello-bdi/Makefile 2015-05-24 22:32:07 UTC (rev 1837)
@@ -0,0 +1,13 @@
+#
+# by Jomi
+#
+
+all:
+ cp index.html ../../hello-bdi
+ cp jcm.css ../../hello-bdi
+ cp -R screens ../../hello-bdi
+
+publish:
+ scp index.html jomifred,ja...@we...:/home/groups/j/ja/jason/htdocs/mini-tutorial/hello-bdi
+ scp jcm.css jomifred,ja...@we...:/home/groups/j/ja/jason/htdocs/mini-tutorial/hello-bdi
+ scp -r screens jomifred,ja...@we...:/home/groups/j/ja/jason/htdocs/mini-tutorial/hello-bdi
Property changes on: trunk/doc/mini-tutorial/src/hello-bdi/Makefile
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: trunk/doc/mini-tutorial/src/hello-bdi/code/Calendar.java
===================================================================
--- trunk/doc/mini-tutorial/src/hello-bdi/code/Calendar.java (rev 0)
+++ trunk/doc/mini-tutorial/src/hello-bdi/code/Calendar.java 2015-05-24 22:32:07 UTC (rev 1837)
@@ -0,0 +1,68 @@
+import jason.asSyntax.ASSyntax;
+import jason.asSyntax.Term;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JSlider;
+import javax.swing.event.ChangeEvent;
+
+import cartago.INTERNAL_OPERATION;
+import cartago.ObsProperty;
+import cartago.tools.GUIArtifact;
+
+public class Calendar extends GUIArtifact {
+ Term[] days = {
+ ASSyntax.createAtom("sunday"),
+ ASSyntax.createAtom("monday"),
+ ASSyntax.createAtom("tuesday"),
+ ASSyntax.createAtom("wednesday"),
+ ASSyntax.createAtom("thursday"),
+ ASSyntax.createAtom("friday"),
+ ASSyntax.createAtom("saturday")
+ };
+
+
+ public void setup() {
+ defineObsProperty("today", days[0]);
+ initGUI();
+ }
+
+ JSlider s = new JSlider();
+
+ void initGUI() {
+ JFrame f = new JFrame("Calendar");
+
+ s.setMinimum(0);
+ s.setMaximum(6);
+ s.setPaintTicks(true);
+ s.setPaintLabels(true);
+ s.setValue(0);
+ Dictionary<Integer, JLabel> lbs = new Hashtable<Integer, JLabel>();
+ lbs.put(0, new JLabel("S"));
+ lbs.put(1, new JLabel("M"));
+ lbs.put(2, new JLabel("T"));
+ lbs.put(3, new JLabel("W"));
+ lbs.put(4, new JLabel("T"));
+ lbs.put(5, new JLabel("F"));
+ lbs.put(6, new JLabel("S"));
+ s.setLabelTable(lbs);
+ linkChangeEventToOp(s, "updateDay");
+
+ f.add(s);
+ f.pack();
+ f.setVisible(true);
+ }
+
+ @INTERNAL_OPERATION void updateDay(ChangeEvent ev) {
+ try {
+ ObsProperty prop = getObsProperty("today");
+ prop.updateValue(days[ (int)s.getValue() ]);
+ } catch (Exception e2) {
+ e2.printStackTrace();
+ }
+ }
+}
+
Added: trunk/doc/mini-tutorial/src/hello-bdi/code/alice.asl
===================================================================
--- trunk/doc/mini-tutorial/src/hello-bdi/code/alice.asl (rev 0)
+++ trunk/doc/mini-tutorial/src/hello-bdi/code/alice.asl 2015-05-24 22:32:07 UTC (rev 1837)
@@ -0,0 +1,20 @@
+!start.
+
++!start
+ <- .send(bob,tell,happy(bob));
+ .send(bob,tell,happy(alice1));
+ .send(bob,tell,happy(alice2));
+ .send(bob,tell,happy(alice3));
+ .send(bob,tell,happy(alice4));
+ .wait(1000);
+ .send(bob,tell,happy(morgana));
+ .wait(1000);
+ /*.send(bob,tell,today(wednesday));
+ .wait(3000);
+ .send(bob,tell,today(friday));
+ .wait(3000);
+ .send(bob,tell,today(saturday));
+ */
+ //.send(bob,untell,happy(bob));
+ .wait(1000);
+ .send(bob,untell,happy(alice)).
Property changes on: trunk/doc/mini-tutorial/src/hello-bdi/code/alice.asl
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: trunk/doc/mini-tutorial/src/hello-bdi/code/bdi_hw.mas2j
===================================================================
--- trunk/doc/mini-tutorial/src/hello-bdi/code/bdi_hw.mas2j (rev 0)
+++ trunk/doc/mini-tutorial/src/hello-bdi/code/bdi_hw.mas2j 2015-05-24 22:32:07 UTC (rev 1837)
@@ -0,0 +1,11 @@
+/* Jason Project */
+
+MAS bdi_hw {
+ infrastructure: JaCaMo
+
+ agents:
+ bob;
+ alice;
+
+}
+
Property changes on: trunk/doc/mini-tutorial/src/hello-bdi/code/bdi_hw.mas2j
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: trunk/doc/mini-tutorial/src/hello-bdi/code/bob.asl
===================================================================
--- trunk/doc/mini-tutorial/src/hello-bdi/code/bob.asl (rev 0)
+++ trunk/doc/mini-tutorial/src/hello-bdi/code/bob.asl 2015-05-24 22:32:07 UTC (rev 1837)
@@ -0,0 +1,33 @@
+sincere(alice).
+
+!create_calendar.
++!create_calendar <- makeArtifact("c","Calendar",[],AId); focus(AId).
+
++happy(H)[source(A)] : sincere(A)[source(self)] & .my_name(H) <- !say(hello(A)).
++happy(H) : not .my_name(H) <- !say(i_envy(H)).
+
+-happy(H)[source(A)]
+ <- .drop_intention(say(hello(A)));
+ .drop_intention(say(i_envy(H))).
+
++!say(X) : today(friday) <- .print(X,"!!!!!"); .wait(500); !say(X).
++!say(X) : not today(monday) <- .print(X); .wait(math.random(400)+100); !say(X).
+
++today(wednesday) <- .print("**** Let's slow down.... **** (only 2 intentions)"); !enter_lazy_mode.
++today(friday) <- .print("**** Let's finish the work!"); !resume_all.
++today(saturday) <- .print("**** weekend!"); .drop_all_intentions.
+
++!enter_lazy_mode
+ : .findall(A, .intend(say(A)), [_,_|L]) // the agent has two say intentions
+ <- for ( .member(I,L) ) {
+ .suspend(say(I));
+ }.
++!enter_lazy_mode.
+
+
++!resume_all
+ : .count( .intend(A) & .suspended(A,R) & .substring("suspended",R), I) & I > 0
+ <- .resume(say(_));
+ !resume_all.
++!resume_all.
+
Property changes on: trunk/doc/mini-tutorial/src/hello-bdi/code/bob.asl
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: trunk/doc/mini-tutorial/src/hello-bdi/index.html
===================================================================
(Binary files differ)
Index: trunk/doc/mini-tutorial/src/hello-bdi/index.html
===================================================================
--- trunk/doc/mini-tutorial/src/hello-bdi/index.html 2015-05-19 16:58:56 UTC (rev 1836)
+++ trunk/doc/mini-tutorial/src/hello-bdi/index.html 2015-05-24 22:32:07 UTC (rev 1837)
Property changes on: trunk/doc/mini-tutorial/src/hello-bdi/index.html
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/xml
\ No newline at end of property
Added: trunk/doc/mini-tutorial/src/hello-bdi/index.org
===================================================================
--- trunk/doc/mini-tutorial/src/hello-bdi/index.org (rev 0)
+++ trunk/doc/mini-tutorial/src/hello-bdi/index.org 2015-05-24 22:32:07 UTC (rev 1837)
@@ -0,0 +1,300 @@
+#+TITLE: (BDI) Hello World
+#+AUTHOR: Jomi F. Hubner (with Rafael H. Bordini assistance)
+#+EMAIL: jom...@gm...
+#+DATE: 2015
+
+#+DESCRIPTION:
+#+KEYWORDS:
+#+LANGUAGE: pt
+#+OPTIONS: email:t H:2 toc:2 num:nil author:t \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
+#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:t pri:nil tags:nil
+#+STYLE: <link rel="stylesheet" type="text/css" href="./jcm.css" />
+
+* Introduction
+
+This programming (mini) tutorial will illustrate how the BDI model is used in the [[http://jason.sf.net][Jason]] agent-oriented programming language. We start by a very simple agent code and progress exploring the BDI features of Jason.
+
+We assume that the reader knows the basic concepts of the BDI model (an introduction and further references are found at the [[http://en.wikipedia.org/wiki/Belief–desire–intention_software_model][Wikipedia]]). It is important to know these concepts to be a good Jason programmer, in the same way that knowing the concepts of and objects and classes is important for a Java programmer. Very briefly, in the BDI model the agent has /beliefs/ (based on what it perceives and communicates with other agents) that can produce /desires/ (states of the world that the agent wants to achieve). The agent /deliberates/ on its desires and decides to /commit/ to some (desires to which the agent is committed become /intentions/). The satisfy its intentions, the agent executes plans that lead to action. The behaviour of the agent (i.e., its actions) is thus explained/caused by what it intends (i.e., the desires it decided to pursue). An important feature of the model is that the agent should /react/ to changes in its environment as soon as possible while keeping its /pro-active/ (i.e., desires-oriented) behaviour. (Do not worry about all these high-level anthropomorphic concepts (in italics), we will try to keep the simplicity of usual hello world programs.)
+
+* Bob (the mentalist)
+
+** the agent program
+
+The Jason program for our agent is the following (since BDI is inspired in folk psychology, we can name this agent Bob):
+
+#+begin_src prolog
+happy(bob).
+
+!say(hello).
+
++!say(X) : happy(bob) <- .print(X).
+#+end_src
+
+As we can see, the syntax is far from the usual C, Java, or Python programs we are used to. For those (rare) guys who have had some contact with Prolog, maybe it looks a bit familiar. The syntax is indeed inspired by Prolog, but the objective is different (the output is not knowledge and the underlying engine is not based on resolution). Let's read this program:
+
+1. The agent has one (initial) belief: =happy(bob)=, included by the programmer (rather than by perceiving the state of the environment). This belief can be read as ``the domain element named =bob= has the property (or predicate) =happy=".
+2. The agent has one (initial) desire: =!say(hello)=, also included by the programmer. What follows the symbol =!= describes the desire and is also represented as a Prolog literal.
+3. The agent has one plan to achieve the desire =say(hello)=. We can read this plan as ``whenever the agent has the desire to =say(X)= and believes that =happy(bob)=, by executing the action =.print(X)= the desire is achieved, for any =X= (which is a variable since it starts with an uppercase letter, as in Prolog).
+
+The /deliberation/ process of the BDI model is highly related to plans. The plan states /whether/ a desire can become an intention by means of its /event/ and /context/. In the Bob's plan, the event is =+!say(X)= (what is written before =:=) and it means the event of having a new desire to say something. The context is =happy(bob)= (the part of the code that goes between =:= and =<-=) which is a logical formula evaluated in regards to the current believes of the agent.
+
+The plan also states /how/ to achieve the desire (i.e. the /means-end/ reasoning part of the BDI model). If the sequence of actions (after =<-=) is successfully executed, the desire is (hopefully) achieved. An intention in Jason is an instantiated plan that the agent is executing in order to achieve a desire (also called goal).
+
+This program is interpreted by Jason as follows:
+
+1. The initial belief is added in the agent belief base (BB).
+2. From the initial desire, the event =+!say(hello)= is added in the queue of events to be handled by the agent.
+3. The plan is included in the plan library (PL) of the agent.
+4. A reasoning cycle loop is executed:
+ - The event =+!say(hello)= is selected from the queue.
+ - The above plan is selected (it matches the selected event when the variable =X= is bound to =hello=).
+ - The context of the plan is evaluated as true since it follows from be BB (i.e. the agent believes =happy(bob)=).
+ - A new intention is created based on this plan and the =X= value. The agent has thus committed itself to the desire to =say(hello)=.
+ - One action of the intention is executed (the =.print(hello)= command in this case).
+ - Since the intention has executed all actions, it finishes.
+5. The agent keeps waiting for new events to react to.
+
+
+** execution
+
+- Create a new Jason project (you can use either [[http://jason.sourceforge.net/mini-tutorial/getting-started/][jEdit]] or [[http://jason.sourceforge.net/mini-tutorial/eclipse-plugin/][Eclipse]] plugins).
+
+- Create agent Bob with the source code above. The .mas2j project should look like:
+
+: MAS bdi_hw {
+:
+: agents: bob;
+:
+: }
+
+- Run the project.
+
+* Bob (the believer)
+
+The second version of agent Bob has neither initial beliefs nor desires:
+
+#+begin_src prolog
++happy(bob) <- !say(hello).
++!say(X) : not today(monday) <- .print(X); .wait(500); !say(X).
+#+end_src
+
+The first plan has a different kind of event: the agent has started to believe something (the belief that follows =+=). So when the agent starts believing that Bob is happy, the desire to say hello (=!say(hello)=) is created. In this case, the desire is the result of changes in the agent's beliefs. The agent starts believing something when, for instance, it perceives the state of the environment or receives a message from another agent.
+
+The second plan has also changed: (i) the agent will decide to pursue the desire to say something on days other than Monday; (ii) after printing the message, the desire is keept, producing a loop that will end on the next Monday. In other words, the intention to achieve =!say= does not finish because that intention itself creates a new desire =!say= (here also conveniently called sub-goal). Only when this sub-goal is achieved, the intention finishes (which never happens in the above plan).
+
+If you run this program, nothing happens! Different from other languages where the programmer defines a sequence of operations, in Jason the programmer /declares/ plans and the order of execution depends on the order of the events that take place on a particular environment.
+
+To interact with Bob, we will create another agent at runtime and inform them about some facts.
+
+1. Run the project.
+2. In the MAS Console, click on the button "New REPL agent" and fill "alice" as the name of the new agent.
+3. In the Alice interface, enter =.send(bob,tell,happy(bob))=.
+4. You will notice that Bob starts saying hello.
+
+The /tell/ message that Alice sent to Bob is automatically interpreted by Jason. The default interpretation, since it is a "tell" message, is to include the content of the message (=happy(bob)=) in the Bob's belief base. When that belief is added in the belief base, the event =+happy(bob)= is included in the queue of events. Bob then reacts to this event creating an intention. You can access the [[http://localhost:3272][Jason Mind Inspector]] to see the Bob's mental state (or use the Debug button in the MAS Console):
+
+#+ATTR_HTML: width=500 style="center;margin:0px 20px 20px 20px;"
+[[./screens/mind-1.png]]
+
+As we can see, the belief is not exactly =happy(bob)= but =happy(bob)[source(alice)]=. The part enclosed by =[= and =]= are annotations. All beliefs in Jason have annotations for their sources. This information can be used, for instance, if an agent needs to consider only those beliefs that come from trustable sources:
+
+#+begin_src prolog
+sincere(alice).
+
++happy(bob)[source(A)] : sincere(A) <- !say(hello).
+
++!say(X) : not today(monday) <- .print(X); .wait(500); !say(X).
+#+end_src
+
+This program has a problem, however. Another malicious agent can tell Bob that it is sincere just before telling him =happy(bob)=! The source of the =sincere= belief should be Bob itself (and not another agent):
+
+#+begin_src prolog
+sincere(alice).
+
++happy(bob)[source(A)] : sincere(A)[source(self)] <- !say(hello).
+
++!say(X) : not today(monday) <- .print(X); .wait(500); !say(X).
+#+end_src
+
+** perception
+
+Besides messages from other agents, another source for beliefs is perception. We will place a calendar in the environment so that Bob can be aware of the current day. It is not the focus of this tutorial to develop the environment, so we will simply copy & paste some code:
+
+- change the .mas2j to:
+
+#+begin_src masj2
+MAS bdi_hw {
+ infrastructure: JaCaMo
+
+ agents: bob;
+}
+#+end_src
+
+- Download [[./code/Calendar.java][this]] file and place it in the directory of the project.
+
+- In the beginning of Bob's program, add the following lines that create the Calendar in the environment:
+#+begin_src prolog
+!create_calendar.
++!create_calendar <- makeArtifact("c","Calendar",[],AId); focus(AId).
+#+end_src
+
+- Run the project and interactively change the current day observing Bob's belief base and intentions. For example, if you change the day to Monday, the intention will finish. In this case, the intention finishes with failure, since the agent has a desire without a suitable plan.
+
+* Bob (the vigilant)
+
+The following program for Bob includes alternative plans for the events =+happy(H)= and =+!say(X)=.
+
+#+begin_src prolog
+sincere(alice).
+
+!create_calendar.
++!create_calendar <- makeArtifact("c","Calendar",[],AId); focus(AId).
+
++happy(H)[source(A)] : sincere(A)[source(self)] & .my_name(H) <- !say(hello(A)).
++happy(H) : not .my_name(H) <- !say(i_envy(H)).
+
++!say(X) : today(friday) <- .print(X,"!!!!!"); .wait(math.random(400)+100); !say(X).
++!say(X) : not today(monday) <- .print(X); .wait(math.random(400)+100); !say(X).
+#+end_src
+
+For each event, *one* plan is selected according to the context: the
+first plan with a context that holds is selected to create the
+intention to react to the event.
+
+The first plan for =+happy(H)= is used when =H= is =bob= and the
+source of =happy(H)= is sincere ([[http://jason.sourceforge.net/api/jason/stdlib/my_name.html][=.my\_name=]] is true if the value of
+=H= is the name of the agent executing that internal action). The
+second plan is used otherwise. The first plan for =+!say(X)= is used
+in days other than Monday and the second on Fridays. (Notice that
+there are no plans for Mondays!)
+
+Instead of using REPL, we will add a new agent, called Alice, to run
+this system:
+#+begin_src prolog
+!start.
+
++!start
+ <- .send(bob,tell,happy(bob));
+ .send(bob,tell,happy(alice));
+ .wait(2000);
+ .send(bob,tell,happy(morgana)).
+#+end_src
+
+It is important to notice how many intentions Bob has:
+
+#+ATTR_HTML: width=500 style="center;margin:0px 20px 20px 20px;"
+[[./screens/mind-2.png]]
+
+Bob is concurrently executing three intentions: one for each
+event. More importantly, even with 3 intentions (or 100 intentions)
+Bob promptly reacts to new events. This /reactivity/ is indeed one of
+the nicer features of the BDI model. You can test it by creating a new
+REPL agent that sends tell messages to Bob and see how fast it
+reacts.
+
+To really stress Bob, we can change Alice's program as follows:
+#+begin_src prolog
+!start.
+
++!start
+ <- .send(bob,tell,happy(bob));
+ .send(bob,tell,happy(alice));
+ .wait(2000);
+ .send(bob,tell,happy(morgana));
+ for (.range(I,1,100)) {
+ .send(bob,tell,happy(I));
+ }.
+#+end_src
+
+At this point of the tutorial, you could try to imagine how to program
+this application using conventional languages like Java and C. Even
+actor-based langages, which are also oriented to events and great
+tools for concurrency, will not be so reactive as Jason.
+
+* Bob (the revisionist)
+
+Another important feature of the BDI model is that agents are able to
+revise their own intentions. The following plan reacts to the event of
+stop believing that someone is happy. The reaction is to drop the
+corresponding intention.
+
+#+begin_src prolog
+// new plan in Bob's program:
+
+-happy(H)[source(A)]
+ <- .drop_intention(say(hello(A)));
+ .drop_intention(say(i_envy(H))).
+#+end_src
+
+We can test this with the following program for Alice:
+
+#+begin_src prolog
+!start.
+
++!start
+ <- .send(bob,tell,happy(bob));
+ .send(bob,tell,happy(alice)); .wait(2000);
+ .send(bob,tell,happy(morgana)); .wait(2000);
+ .send(bob,untell,happy(bob)); .wait(1000);
+ .send(bob,untell,happy(alice)).
+#+end_src
+
+The =untell= message removes the corresponding belief in the receiver
+(only for the belief with that same source, of course).
+
+* Bob (the lazy -- finally)
+
+This last code for Bob implements the following:
+
+1. On Wednesdays, Bob keeps only two =say= intentions, the others will
+ be suspended.
+2. On Fridays, suspended intentions are resumed.
+3. On Saturdays, all intentions are dropped.
+
+
+#+begin_src prolog
+sincere(alice).
+
+!create_calendar.
++!create_calendar <- makeArtifact("c","Calendar",[],AId); focus(AId).
+
++happy(H)[source(A)] : sincere(A)[source(self)] & .my_name(H) <- !say(hello(A)).
++happy(H) : not .my_name(H) <- !say(i_envy(H)).
+
+-happy(H)[source(A)]
+ <- .drop_intention(say(hello(A)));
+ .drop_intention(say(i_envy(H))).
+
++!say(X) : today(friday) <- .print(X,"!!!!!"); .wait(500); !say(X).
++!say(X) : not today(monday) <- .print(X); .wait(math.random(400)+100); !say(X).
+
+/**** the following is NEW ****/
+
++today(wednesday) <- .print("**** Let's slow down.... ****"); !enter_lazy_mode.
++today(friday) <- .print("**** Let's finish the work!"); !resume_all.
++today(saturday) <- .print("**** weekend!"); .drop_all_intentions.
+
++!enter_lazy_mode
+ : .findall(A, .intend(say(A)), [_,_|L]) // the agent has two say intentions
+ <- for ( .member(I,L) ) {
+ .suspend(say(I));
+ }.
++!enter_lazy_mode.
+
++!resume_all
+ : .count( .intend(A) & .suspended(A,R) & .substring("suspended",R), I) & I > 0
+ <- .resume(say(_));
+ !resume_all.
++!resume_all.
+#+end_src
+
+(You can refer to the [[http://jason.sourceforge.net/api/jason/stdlib/package-summary.html#package.description][Jason API]] for explanations about all the commands used in this example.)
+
+This tutorial showed how some of the (great) BDI concepts become
+concrete and practical in Jason, particularly long-term intentions and
+reactivity.
+
+------
+
+
+
Added: trunk/doc/mini-tutorial/src/hello-bdi/jcm.css
===================================================================
--- trunk/doc/mini-tutorial/src/hello-bdi/jcm.css (rev 0)
+++ trunk/doc/mini-tutorial/src/hello-bdi/jcm.css 2015-05-24 22:32:07 UTC (rev 1837)
@@ -0,0 +1,93 @@
+/* Century Schoolbook font is very similar to Computer Modern Math: cmmi */
+.MATH { font-family: "Century Schoolbook", serif; }
+.MATH I { font-family: "Century Schoolbook", serif; font-shape: italic }
+.BOLDMATH { font-family: "Century Schoolbook", serif; font-weight: bold }
+
+/* implement both fixed-size and relative sizes */
+SMALL.XTINY { font-size : xx-small }
+SMALL.TINY { font-size : x-small }
+SMALL.SCRIPTSIZE { font-size : smaller }
+SMALL.FOOTNOTESIZE { font-size : small }
+SMALL.SMALL { }
+BIG.LARGE { }
+BIG.XLARGE { font-size : large }
+BIG.XXLARGE { font-size : x-large }
+BIG.HUGE { font-size : larger }
+BIG.XHUGE { font-size : xx-large }
+
+a {
+ text-decoration: none;
+}
+
+/* Page background color */
+body { background-color: white; font-family: "Optima", "Georgia", "Times", arial, helvetica, sanserif; font-weight: 200; }
+/* mathematics styles */
+DIV.displaymath { } /* math displays */
+TD.eqno { } /* equation-number cells */
+
+
+.title {
+ color:#48005E;
+ font-size: 200%; font-weight:200;
+ font-family: "Helvetica Neue Light", Optima, Garamond, Times;
+ text-align: center;
+ /*display: block;
+ border-top: 1px solid black;
+ border-bottom: 1px solid black;*/
+
+ /*margin-left: -1em;*/
+ padding-top: 20px;
+ padding-bottom: 20px;
+ padding-right: 10px;
+}
+
+H1 {
+ color:#48005E;
+ font-size: 150%; font-weight:200;
+ display: block;
+ text-align: left;
+
+ padding-top: 10px;
+ padding-bottom: 0px;
+ /*padding-left: 10px; */
+ padding-right: 10px;
+ /*margin-left: -1em;*/
+ /*border-bottom: 1px solid black;*/
+}
+
+H2 {
+ color:#48005E;
+ font-size: 140%; font-weight:200;
+ display: block;
+ text-align: left;
+
+ padding-top: 5px;
+ padding-bottom: 0px;
+ /*padding-left: 10px; */
+ padding-right: 10px;
+ /*margin-left: -1em;*/
+}
+
+H3 {
+ color:#48005E;
+ font-size: 120%; font-weight:200;
+ display: block;
+ text-align: left;
+
+ padding-top: 5px;
+ padding-bottom: 0px;
+ /*padding-left: 10px; */
+ padding-right: 10px;
+ /*margin-left: -1em;*/
+}
+
+HR { width: 100%; height: 1px;}
+
+PRE
+{
+ padding: 1em;
+ white-space: pre;
+ background-color:#f2f2f2;
+ /*border: 1px solid black;*/
+ font-family: Courier, fixed, serif;
+}
Property changes on: trunk/doc/mini-tutorial/src/hello-bdi/jcm.css
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: trunk/doc/mini-tutorial/src/hello-bdi/screens/mind-1.png
===================================================================
(Binary files differ)
Index: trunk/doc/mini-tutorial/src/hello-bdi/screens/mind-1.png
===================================================================
--- trunk/doc/mini-tutorial/src/hello-bdi/screens/mind-1.png 2015-05-19 16:58:56 UTC (rev 1836)
+++ trunk/doc/mini-tutorial/src/hello-bdi/screens/mind-1.png 2015-05-24 22:32:07 UTC (rev 1837)
Property changes on: trunk/doc/mini-tutorial/src/hello-bdi/screens/mind-1.png
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+image/png
\ No newline at end of property
Added: trunk/doc/mini-tutorial/src/hello-bdi/screens/mind-2.png
===================================================================
(Binary files differ)
Index: trunk/doc/mini-tutorial/src/hello-bdi/screens/mind-2.png
===================================================================
--- trunk/doc/mini-tutorial/src/hello-bdi/screens/mind-2.png 2015-05-19 16:58:56 UTC (rev 1836)
+++ trunk/doc/mini-tutorial/src/hello-bdi/screens/mind-2.png 2015-05-24 22:32:07 UTC (rev 1837)
Property changes on: trunk/doc/mini-tutorial/src/hello-bdi/screens/mind-2.png
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+image/png
\ No newline at end of property
Modified: trunk/examples/cleaning-robots/logging.properties
===================================================================
--- trunk/examples/cleaning-robots/logging.properties 2015-05-19 16:58:56 UTC (rev 1836)
+++ trunk/examples/cleaning-robots/logging.properties 2015-05-24 22:32:07 UTC (rev 1837)
@@ -28,6 +28,7 @@
jason.runtime.MASConsoleLogHandler.level = ALL
jason.runtime.MASConsoleLogHandler.formatter = jason.runtime.MASConsoleLogFormatter
jason.runtime.MASConsoleLogHandler.tabbed = false
+jason.runtime.MASConsoleLogHandler.colors = true
# default file output is in project's directory.
java.util.logging.FileHandler.pattern = mas-%u.log
Modified: trunk/src/jason/runtime/MASConsoleColorGUI.java
===================================================================
--- trunk/src/jason/runtime/MASConsoleColorGUI.java 2015-05-19 16:58:56 UTC (rev 1836)
+++ trunk/src/jason/runtime/MASConsoleColorGUI.java 2015-05-24 22:32:07 UTC (rev 1837)
@@ -2,8 +2,11 @@
import java.awt.BorderLayout;
import java.awt.Color;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
import java.util.HashMap;
-import java.util.Hashtable;
import java.util.Map;
import javax.swing.JScrollPane;
@@ -22,7 +25,7 @@
*/
public class MASConsoleColorGUI extends MASConsoleGUI {
private Map<String, MASColorTextPane> agsTextArea = new HashMap<String, MASColorTextPane>();
- private Hashtable<String, Color> agsColours = new Hashtable<String, Color>();
+ private Map<String, Color> agsColours = new HashMap<String, Color>();
private MASColorTextPane output;
private MASConsoleColorGUI(String title) {
@@ -65,7 +68,6 @@
agsColours.put(agName, c);
}
}
-
if (!frame.isVisible()) {
frame.setVisible(true);
}
@@ -99,21 +101,25 @@
}
// print in output
- int l = output.getDocument().getLength();
- if (l > 60000) {
- cleanConsole();
- l = 0;
- }
synchronized (this) {
+ int l = output.getDocument().getLength();
+ if (l > 60000) {
+ cleanConsole();
+ l = 0;
+ }
output.append(c, s);
try {
output.setCaretPosition(l);
} catch (IllegalArgumentException e) {}
}
} catch (Exception e) {
- //close();
- System.out.println(e);
- e.printStackTrace();
+ try {
+ PrintWriter out = new PrintWriter(new FileWriter("e_r_r_o_r.txt"));
+ out.write("Error that can not be printed in the MAS Console!\n"+e.toString()+"\n");
+ e.printStackTrace(out);
+ out.close();
+ } catch (IOException e1) {
+ }
}
}
Modified: trunk/src/jason/runtime/MASConsoleGUI.java
===================================================================
--- trunk/src/jason/runtime/MASConsoleGUI.java 2015-05-19 16:58:56 UTC (rev 1836)
+++ trunk/src/jason/runtime/MASConsoleGUI.java 2015-05-24 22:32:07 UTC (rev 1837)
@@ -31,7 +31,10 @@
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.io.BufferedWriter;
import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.LogManager;
@@ -215,8 +218,13 @@
} catch (java.lang.IllegalArgumentException e) {}
}
} catch (Exception e) {
- //close();
- System.out.println(e);
+ try {
+ PrintWriter out = new PrintWriter(new FileWriter("e_r_r_o_r.txt"));
+ out.write("Error that can not be printed in the MAS Console!\n"+e.toString()+"\n");
+ e.printStackTrace(out);
+ out.close();
+ } catch (IOException e1) {
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|