Table of Contents
Evaluation
As to evaluate your work done during the tutorial, you have to send your source code (in an archive) at the end of the session to Gauthier Picard
Preliminary Concepts and Setup
Jason Environment
In the MAOP course you have already installed a Jason environment. In this tutorial, we will only use the core Jason functionalities (no Jade, Cartago, etc.), and will concentrate on the agent behaviours to solve a toy constraint satisfaction problem: the n-queens problem.
The goal of this tutorial is to implement the Asynchronous Backtracking 1 (ABT) algorithm presented in the course using the Jason language and environment.
We propose to develop ABT in an iterative way. Even if not specified in the exercises, you should test your development step-by-step, using the Jason console and debugger.
Asynchronous Backtracking (ABT)
ABT is the most famous multi-agent algorithm to asynchronously solve
distributed constraint satisfaction problems (DisCSP). For more
information, have a look at your lecture notes
.
As a reminder, here are the main procedures in ABT, excerpt from 1:

ABT Procedures
Therefore, the objective of the session is to develop Jason agents that implement these procedures and a multi-agent system that launches some ABT agents to solve a CSP (n-Queens Problem). Since agents will have the same code concerning the ABT implementation, you will create a simple abt.asl file that will be included by all the Jason agent files.
Initializing the project
To sum up, you will have to develop:
-
a
.mas2jfile describing the multi-agent system -
a
abt.aslfile containing the code of ABT procedures -
as many
.aslfile as agents in the system, including theabt.aslcode using the{ include("abt.asl") }pre-processing directive
To simplify the development, we will only consider for the moment the 4-queens problem.
Exercise 1
- Launch the Jason editor
-
Create a new project and save it as
4queens.mas2jin a dedicated directory -
Add 4 agents in the
4queens.mas2jfile, for instance:
MAS abt {
infrastructure: Centralised
agents:
q1; q2; q3; q4;
classpath: "/Applications/Jason-1.3.2/lib/jason.jar";
}
-
Create the
abt.aslfile and include it into each agent file
Now, your project is ready for development. You can run it and see agents talking to you.
Data structures
- Views and Nogoods representation in ABT
In the remainder of the session, we will consider assignment lists (views and nogoods) as being lists of pairs
[X,D]whereXis the name of an agent andDis a value. For instance, an agent view or a nogood can be represented as follows for simple integer values:[[X1,2],[X2,3]]
- Values and Domains in n-Queens Problem
Concerning the n-queens problem, we will represent possible values for agents as
[X,Y]pairs. So the domain for the agent1, in the 4-queens problem, should be:[[1,1],[1,2],[1,3],[1,4]]
- Some useful functions for manipulating structures
Even if shortly described using pseudo-code, ABT relies on prerequisite functions to manipulate the different data structures (views, nogoods, etc.) used during the solving process by each agent. In order to only focus on ABT and agent communication, we provide a set of useful functions in the
abt-utils.aslfile, that should be included in theabt.aslfile using the{ include("abt-utils.asl") }file.Here a short description of each of these functions:
-
remove(V,L,UL)is true ifULis equal toLwithoutV -
contains(L,X)is true ifLcontains at least oneX -
includes(L1,L2)is true if all elements ofL2are inL1 -
value_of(X,L,D)is true ifDis the value ofXin the assignment listL -
contains_entry(L,X)is true ifLis an assignment list andXis on entry in this list -
add_to_view([Xi,Di],L1,L2)is true ifL2is the same assignment list than the assignment listL1with a new valueDiforXi -
add_all_to_view(V,L1,L2)is true ifL2is the same list thanL1with all new values fromV -
add_to_nogoods(Ng,Ngs1,Ngs2)adds a nogoodNgin a nogood listNgs1, resulting inNgs2list, only if it is not already in (nogoods are equal if they are reciprocally compatible) -
get_agents_from_view(Agents,View)is true ifAgentsis the list of all agents inView -
lowest_priority_view_in_agent_view([Xj,Dj],View)is true ifXjis the lowest priority agent inViewwith the valueDj -
missing_values_from_links(Links,L,UL)is true ifULis the assignment list containing all assignments[Xi,Di]fromLwhereXiis not inLinks -
missing_values_from_view(Xi,View,U,UL)is true ifULis the assignment list containing all assignments[Xj,Dj]from L whereXjis not an entry inViewandXi≠Xj
-
Consistency checking
- Back to Yokoo's definition of consistency
In ABT, agents have to check consistency of some values wrt their current view and nogoods (in the procedure
check_agent_view). Let us look at the definition of consistency provided in Makoto Yokoo's book:(An) assignment is consistent with the agent_view if all constraints the agent evaluates are true under the value assignments described in the agent_view and (xi, current_value), and if all communicated nogoods are not compatible with the agent_view and (xi, current_value).
This means that an agent checks the consistency of a value by :
- (check 1) checking whether the value has no conflict with values from its view (to avoid conflicts with neighbours)
- (check 2) checking whether the value and view are not in the same nogood, in order to avoid past errors
Both checks have to success for a value to be consistent. The second check relies on the compatibility definition :
A nogood is compatible with the agent_view and (xi, current_value) if all variables in the nogood have the same value in the agent_view and (xi, current_value).
- Some useful functions for checking consistency
As for data structures, we provide some useful functions to check consistency in theabt-utils.aslfile:-
full_consistent(Agent,Value,View,Nogoods)is true ifValueis consistent withAgent'sViewand allNogoodsare not compatible with[Agent,Value]|View(definition of consistency, see above) -
consistent(D,L)is true isDhas no conflict with every value in assignment listL(check 1, see above) -
uncompatible(Nogoods,View)is true if allNogoodsare not compatible withView(check 2, see above) -
consistent_values(Values,Agent,Domain,View,Nogoods)is true ifValuesis the set of all consistent values inDomainwrt theView -
compatible(Nogood,View)is true if all variables inNogoodhave the same values in theView
-
- Constraints in n-Queens Problem
If you look at the
consistentrule inabt-utils.aslyou will see a call to a rule calledconflict. This rule represents the constraints. It is true if the two input values violate a constraint. These rule is not provided because it is problem dependent (conflictdiffers from a CSP to another).In the n-Queens Problem, two values are in conflict if they represent positions on a chessboard that are respectively attackable by queens.
Exercise 2
-
Save
abt-utils.aslinto your project directory - Read it carefully as to handle all the provided functions (data structures and consistency checking)
-
Include
abt-utils.aslintoabt.aslfile -
Create a file called
queen-conflict.asl, and implement theconflictrule for the n-queens problem. -
Include
queen-conflict.aslinto each agent file.
Adding Agent Initial Beliefs and Plans
Initial Beliefs
In ABT agents encapsulate several data they manipulate during the solving process:
Exercise 3
Add the five initial beliefs an agent begins with. Initially, an agent has empty agent_view and nogood_list, and outgoing links to agent with lower priority (lexicographical order). The current_value is the first value from the domain.
As a reminder, initial beliefs are facts that are add using the following syntax:
my_belief(<parameters>).
For instance, for agent q1, we will have :
current_value([1,1]).
ABT Message Handlers
- Reminder: Messages in Jason
In Jason message handlers are specified using beliefs under some conditions, by using the following syntax:
+my_message(<parameters>)[source(P)]: <conditions> <- <actions>
which means "the agent is able to receive messages called
my_messagewith someparametersfrom an agent calledP. Once the agent receives this message under the givenconditions, the agent will perform someactions.For instance, the following code:
+propose(Id,Offer)[source(A)] : all_proposals_received(Id) <- !contract(Id).
means the agent can receive proposals using
proposemessages. If all the proposals are received, the agent will sign a contract for this proposal.To send messages, we use the
.sendinternal action using the following syntax:.send(receiver,illocutionary_force,propositional_content)
In ABT, agents only communicate directly with other agents, so we will only consider the
tellillocutionary force. For instance:.send(r,tell,open(left_door));
means the agent sends a message
openwith the parameterleft_doorto the agentr.
- Messages in ABT
In ABT (see the figure), we consider three different kinds of messages (represented as beliefs):
-
ok(Xi,Xj,Dj)message:XibelievesXj's new value isDj -
nogood(Xi,Xj,Nogood)message:XibelievesXjdiscovered a new nogoodNogood -
add_link(Xi,Xj)message:Xibelieves it has to add a link toXj
-
Exercise 4
Add in the abt.asl file the new (empty) message handlers for the ABT
algorithm. For now, the agent does nothing when receiving these
messages. These handlers should be atomic2, which is obtained using the atomic annotation, e.g.:
@lmy_message01[atomic] +my_message(...)...
where lmy_message01 is a unique label.
Initial Plan and Goal
Commonly, we call !start the initial plan of an agent (e.g. look at the generated agent source files):
/* Initial goals */
!start.
/* Plans */
+!start : true <- .print("hello world.").
These means that the initial goal to achieve for the agent is !start. To do so, the agent will follow the plan declared using +!start…, which consist here in displaying a message in the console.
In ABT, the first action that agents do is to send their current_value to their outgoing links.
Exercise 5
-
Create a new
!startplan inabt.asl. It will be the starting point for agents. Remove the!startplan from all the agent files. -
Modify the
!startdeclaration in order to sendokmessages to all the outgoing links. You can implement first a plan to sendokmessages to outgoing links and then use it into the!startplan.
Deep into ABT
ok Message Handler
When receiving a ok message, an agent simply add/replace the new value in its view and check if its current value is still consistent. To check consistency we will implement the check_agent_view procedure.
Exercise 6
Implement the atomic ok message handler. You should add an empty !check_agent_view plan.
check_agent_view Plan
The check_agent_view procedure will be implemented using a plan. In this procedure, three cases are possible:
- the current value is consistent: the agent does nothing and rests.
-
there is another value in the domain that is consistent: the agent sets its current value to this consistent one, and informs all its outgoing link using
okmessages. -
there is no consistent value in the domain: the agent has to backtrack as to ask to its ingoing link to change its value. Backtrack will be implemented using a plan named
backtrack.
Exercise 7
Implement the atomic !check_agent_view plan for the three presented cases. You should add an empty !backtrack plan.
backtrack Plan
The backtrack procedure in ABT consists in sending nogoods to ingoing agents as soon as a consistency check fails in the check_agent_view plan for instance.
As to simplify the implementation and the computational cost of some checks, we will take a shortcut (proposed by Yokoo in his book). In fact, computing the set of all inconsistent subsets of the agent view requires a certain computation cost. So Yokoo proposes to only consider the current view as a nogood, even if not minimal.
Therefore, we propose to consider only one nogood V (see (iii-a) in the algorithm) which is the current view.
Exercise 8
Implement the atomic !backtrack plan wrt the proposed simplification.
nogood Message Handler
When receiving a nogood, an agent adds the nogood to its nogood list, adds unknown agents (and values) appearing in the nogood and asks for adding links, checks its view wrt the new nogoods, changes its value if necessary and then inform outgoing links of the new value.
Exercise 9
Implement the atomic nogood message handler. You should add an empty !add_link plan.
add_link Messages Handler
Sometimes, all the links are not specified at the beginning of the process, but agents can add links when receiving nogood messages fro mother agent. In short, agents enlarge their social network during the solving process.
Exercise 10
Implement the add_link message handler.
Testing and Debugging ABT
Now, all the procedures required for running ABT properly should be implemented. But does it really work?
Exercise 11
- Test and debug ABT on the 4-queens problem.
- Test and debug ABT on another n-queens problem.
Extra Developments
You have completed all the levels and you are not replete, lets have a look at the following exercises…
Exercise X1
Implement (in Java for instance) an MAS generator that produces a .mas2j, all the .asl agent files, given the size of the n-queens problem you consider.
Exercise X2
Add a termination procedure in ABT, because it does not terminate properly in Jason.
Exercise X3
Extend your ABT solver to implement AWCS (see the lecture notes).
Footnotes:
1 M. Yokoo. Distributed Constraint Satisfaction: Foundations of Cooperation in Multi-Agent Systems. Springer, 2001.
2 Atomic: if an instance of a plan with an atomic annotation is chosen for execution by the intention selection function, this intention will be selected for execution in the subsequent reasoning cycles until that plan is finished. In short, an atomic plan cannot be interrupted by another plan.