ALTISSIMO School - EOP Lab
Notes about the work-in-lab session related to Environment-Oriented Programming in ALTISSIMO. JaCaMo is used as concrete platform to run the examples. In these examples, only the JaCa (Jason+CArtAgO) part is exploited.
- download the altissimo.zip file at http://goo.gl/zFn7Lh
- unpack the zip file: it is an Eclipse workspace, storing the projects that are referred in the following
- switch your Eclipse (already configured with JaCaMo plug-in) to that workspace
- be sure to have configured JaCaMo on the system
Joining workspaces and using Artifacts
The MAS is composed by two CArtAgO (JaCaMo) nodes :
- server node (deployed by server.jcm), where:
- alfred - a majordomo agent - creates a new workspaced called altissimo, and an altissimo.Env artifact inside, called env
- the artifact has a single printMsg operation
- users node (deployed by users.jcm), where:
- a guest agent joins the remote workspace and leaves a message by using the printMsg operation
- Add an action in the plan of guest agent leaves a message consisting of your name.
- you can use the internal action ".my_name(Name)" to get the name of the agent, the internal action ".concat(str1,str2,Result)" to concat str1 to str2 in Result.
- A further server node (server2.jcm) is spawn on a remote node, in which a majordomo2 agent is setting up a slightly extended environment, displaying the messages on a GUI (class altissimo.EnvWithGUI).
- modify the guest agent code to join the new remote workspace
- in this case we have multiple guest agents that concurrently access and use the same environment
- how to create (a workspace and) an artifact
- how to do actions on artifact
- how to join a (remote) workspace
- definition of a basic artifact exposing some operations
- concurrent use of an artifact by multiple agents
- mutual exclusive access, no race conditions
To simplify the deployment, we go on with a single node (run by main.cfg). In this step:
- the artifact env has been enriched with an observable property numMsg showing the number of messages left so far.
- a couple of guest agents repeatedly place messages on env
- An observer agent has been added, observing the env artifact and reacting to changes related to the numMsg observable property
- Look at the code of the code of a guest agent: it joins the workspace and leaves a message for ever.
- Look at the code of the observer agent aiming at observing the env artifact.
- the observer agent joins the workspace, lookups for the artifact env, focuses on this artifact and gets the value of the numMsg observable property of this artifact.
- adapt this agent so that it prints a message only when number of message is included in the range 10..40
- how to lookup or discover an artifact
- how to observe an artifact
- definition of an artifact including observable properties
- concurrent use and observation
Computing with Artifacts
- The artifact env has been enriched with a computePi(NumDigit,Output) action that computes a string representation of the PI number (Output) up to NumDigit digits,
- Write your first Jason agent YOURNAME_agent with code for joining the workspace, using the computePi action to compute PI up to 500 digits and then print the value using the action printMsg
- remember to modify the main config file for launching this new agent
- Now we want to use a shared artifact - so modify your agent so that it joins a remote workspace
- defining actions with feedbacks (output parameters)
- sequentialization of operations on the same artifact
With the previous implementation, we had a monolithic env artifact. This is not a good design: we decompose it into multiple artifacts (types and instances), each encapsulating some functionality:
- MsgBoard artifact
- Calculator artifact
On the agent side:
- the majordomo creates one instance of each artifact, a msg_board and a calc artifact
- a user agent is locating and using both msg_board and calc
- an observer is locating and observing only the msg_board artifact
- improving extensibility, reusability
Interacting with the external world by means of artifacts
Artifacts can be used to represent (and interact with) external resource, services, functionalities. In this step we add two artifacts:
- a Twitter artifact, that allows for interacting with Twitter, in particular posting tweets and reading the timeline of a Twitter account
- a GUI artifact, that allows a human user to interact with the MAS
The MAS is composed by
- a couple of user agents using the msg_board and observing a shared StopButton GUI artifact
- an observer agent is observing the number of messages printed on the message board
- a twitter agent is observing as well the number of messages and posting tweets
- analyse and understand agent behaviors
- reusing off-the-shelf API and libraries inside artifacts
Coordination with the help of the artifact
A typical use of artifacts is for coordination. In this step three user agents share and concurrently use the message board, however they want to print some sequence of messages in a critical section, without interleaving the messages of other agents.
To that purpose, a Token artifact - similar to locks in concurrent programming - is provided, with acquire and release operations
- acquire can be used to acquire the token, and the action succeeds only when the token has been acquired
- release is used to release the token, once acquired
- if you run the program now, the agents are interleaving their messages. Modify the source code of the agents then to exploit a token artifact to coordinate themselves so that each user agent can print the sequence of three messages without interleaving.
- who has to create the token?
- which actions user agent have to do and when?
- defining and using artifacts for basic coordination problems - mutual exclusion
Coordination again by the way of artifact
Besides mutual exclusion, synchronization of actions is the kind of coordination that we can obtain using artifacts.
In this step three user agents want to synchronize after printing a first sequence of message, and before printing a further sequence of action.
To that purpose, a Barrier artifact - similar to barriers in concurrent programming - is provided, with a sync operations
- the barrier is created (instantiated) by specifying the number N of agents that are meant to use it
- the sync action succeeds only when all the N agents have requested it
- if you run the program now, the agents are not synchronizing. Modify then the source code of the agents to exploit a barrier artifact (which - in this case - has already been created by the majordomo) to coordinate so that they synchronize after printing the first sequence and before printing the second
- defining and using artifacts for basic coordination problems - synchronization.