|
From: <jom...@us...> - 2013-09-02 18:57:22
|
Revision: 1746
http://sourceforge.net/p/jason/svn/1746
Author: jomifred
Date: 2013-09-02 18:57:16 +0000 (Mon, 02 Sep 2013)
Log Message:
-----------
add st claus example
Modified Paths:
--------------
trunk/pom.xml
trunk/release-notes.txt
Added Paths:
-----------
trunk/examples/st-claus/
trunk/examples/st-claus/jason_stclaus.mas2j
trunk/examples/st-claus/santa.asl
trunk/examples/st-claus/secretary.asl
trunk/examples/st-claus/worker.asl
Added: trunk/examples/st-claus/jason_stclaus.mas2j
===================================================================
--- trunk/examples/st-claus/jason_stclaus.mas2j (rev 0)
+++ trunk/examples/st-claus/jason_stclaus.mas2j 2013-09-02 18:57:16 UTC (rev 1746)
@@ -0,0 +1,40 @@
+/*
+
+ See description at http://www.cs.otago.ac.nz/staffpriv/ok/santa/
+
+ This is a Jason solution to "The Santa Claus problem",
+ as discussed by Simon Peyton Jones (with a Haskell solution using
+ Software Transactional Memory) in "Beautiful code".
+ He quotes J.A.Trono "A new exercise in concurrency", SIGCSE 26:8-10, 1994.
+
+ Santa repeatedly sleeps until wakened by either all of his
+ nine reindeer, back from their holidays, or by a group of three
+ of his ten elves. If awakened by the reindeer, he harnesses
+ each of them to his sleight, delivers toys with them, and finally
+ unharnesses them (allowing them to go off on holiday). If
+ awakened by a group of elves, he shows each of the group into
+ his study, consults with them on toy R&D, and finally shows them
+ each out (allowing them to go back to work). Santa should give
+ priority to the reindeer in the case that there is both a group
+ of elves and a group of reindeer waiting.
+
+ Inspired by an old example of Dijkstra's, Richard solve this problem by
+ introducing two secretaries: Robin and Edna. The reindeer ask Robin
+ for appointments. As soon as she has nine waiting reindeer she sends
+ them as a group to Santa. The elves as Edna for appointments. As
+ soon as she has three waiting elves she sends them as a group to Santa.
+*/
+
+
+MAS jason_stclaus {
+
+ infrastructure: Centralised
+
+ agents:
+ santa;
+ edna secretary.asl [beliefs="group_size(3,elf)"];
+ robin secretary.asl [beliefs="group_size(9,reindeer)"];
+ elf worker.asl [beliefs="kind(elf), secretary(edna)"] #10;
+ reindeer worker.asl [beliefs="kind(reindeer), secretary(robin)"] #9;
+
+}
\ No newline at end of file
Added: trunk/examples/st-claus/santa.asl
===================================================================
--- trunk/examples/st-claus/santa.asl (rev 0)
+++ trunk/examples/st-claus/santa.asl 2013-09-02 18:57:16 UTC (rev 1746)
@@ -0,0 +1,26 @@
+round(0).
+
+// some group has been formed (message from a secretary)
++!group(Kind,G) : .desire(work(_,_)) // but I am already busy
+ <- .print("waiting to proceed with ",G);
+ .suspend; // this goal will be resumed after !work (see_waiting_groups)
+ !!group(Kind,G). // try again
+
+@lg[atomic] // N.B. must be atomic, otherwise st claus may handle another event +!group (from resume) before executing !!work
++!group(Kind,G) // I am not working, so start working with this group G
+ <- !!work(Kind,G).
+
+// I have to work with group G
++!work(Kind,G) : round(N) & N < 20 // just a stop condition
+ <- .print("Working with ",Kind,"s: ",G," (",N,")");
+ -+round(N+1);
+ .abolish(done);
+ .send(G,achieve,proceed);
+ .wait(.count(done[source(_)],.length(G))); // suspends this intention until |G| dones are received
+ .print("Group ",G," of ",Kind,"s has finished");
+ !!see_waiting_groups. // and resume them (the resume needs to be in another intention, otherwise st claus will be working while checking new groups)
++!work(_,_) <- .print("It is better to stop for now...").
+
++!see_waiting_groups <-
+ .resume(group(reindeer,_)); // resume reindeers first (they have priority)
+ .resume(group(_,_)).
Added: trunk/examples/st-claus/secretary.asl
===================================================================
--- trunk/examples/st-claus/secretary.asl (rev 0)
+++ trunk/examples/st-claus/secretary.asl 2013-09-02 18:57:16 UTC (rev 1746)
@@ -0,0 +1,12 @@
+group([]).
+
+// handle messages from workers and form groups
+@liam1[atomic]
++!iamhere[source(A)] : group_size(S,Kind) & group(Group) & .length(Group,S-1)
+ <- -+group([]);
+ .send(santa,achieve,group(Kind,[A|Group])).
+
+@liam2[atomic]
++!iamhere[source(A)] : group(Group)
+ <- -+group([A|Group]).
+
\ No newline at end of file
Added: trunk/examples/st-claus/worker.asl
===================================================================
--- trunk/examples/st-claus/worker.asl (rev 0)
+++ trunk/examples/st-claus/worker.asl 2013-09-02 18:57:16 UTC (rev 1746)
@@ -0,0 +1,12 @@
+msg("Ho, ho, ho! Let's meet in the study!") :- kind(elf).
+msg("Ho, ho, ho! Let's deliver toys!") :- kind(reindeer).
+
+!start. // initial goal, notify my secretary that I am ready
++!start : secretary(S) <- .send(S,achieve,iamhere).
+
+// do the job asked by St Claus
++!proceed[source(A)] : msg(M)
+ <- .print(M);
+ .send(A,tell,done);
+ .wait( math.random(20)+10 );
+ !!start.
\ No newline at end of file
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-08-30 11:43:23 UTC (rev 1745)
+++ trunk/pom.xml 2013-09-02 18:57:16 UTC (rev 1746)
@@ -4,7 +4,7 @@
<artifactId>jason</artifactId>
<packaging>jar</packaging>
<name>Jason</name>
- <version>1.3.9</version>
+ <version>1.3.10</version>
<description>Jason is a fully-fledged interpreter for an extended version of AgentSpeak, a BDI agent-oriented logic programming language, and is implemented in Java. Using JADE a multi-agent system can be distributed over a network effortlessly.</description>
<url>http://jason.sf.net</url>
<licenses>
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2013-08-30 11:43:23 UTC (rev 1745)
+++ trunk/release-notes.txt 2013-09-02 18:57:16 UTC (rev 1746)
@@ -1,7 +1,7 @@
---------------------------
version 1.3.10
-revision XXX on SVN
+revision 1745 on SVN
---------------------------
New features
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|