Lecture 7: Reaching Agreements
Download
Report
Transcript Lecture 7: Reaching Agreements
Welcome to
CSE41MAS
MultiAgent Systems
LAB 4
1
Objectives
• Demonstration of how to implement
agents using JACK
2
Contents
• A brief introduction to JACK and how to
implement agents in JACK
• Examples
3
JACK
Java Agent Compiler & Kernel
4
JACK
• JACK is an environment for developing
agent-oriented systems.
• JACK is built on top of and fully integrated
with the Java programming language.
• JACK is a product of Agent Oriented
Software (AOS) Group.
• Download JACK for 60-day trial personal use:
http://www.aosgrp.com/products/jack/registration/regform.html
5
Components of JACK
• The JACK Agent Language
– Used to develop agent-oriented systems. It is a
‘super-set’ of Java, extending it with agent-oriented
constructs.
• The JACK Agent Compiler
– Debugs and converts JACK files into Java files.
• The JACK Agent Kernel
– Runtime engine for JACK based agents.
• The JACK Development Environment (JDE)
– A graphical development environment that can be
used to develop JACK based applications. (not
covered in this course)
6
Three basic files to constitute an
agent in JACK
• The .agent file (The file extension is ‘.agent’, e.g., VacuumAgent.agent)
– Specifies the agent’s name, the events the
agent can handle, and the plans the agent
uses to react to these events…
• The .event file (The file extension is ‘.event’, e.g., VacuumEvent.event)
– Declare events an agent can handle
• The .plan file (The file extension is ‘.plan’, e.g., VacuumPlan.plan)
– Describes a sequence of actions that an
agent can take when an event occurs
7
Event template
event SomeEvent extends Event
{
//Events are originators of all activity within JACK
int count;
//It is necessary to specify at least one posting method for the event
#posted as go(int cnt)
{
count = cnt;
}
}
8
Plan template
plan SomePlan extends Plan
{
//Plan describes a sequence of actions that
// an agent can take when an event occurs.
#handles event SomeEvent e;
//Each plan is capable of handling a single event.
body()
{
//Actual steps performed when plan is executed.
//… maybe do some actions here
if( /*some condition*/)
{
@post(/*post another event*/); //issue another event to keep the
//agent working if not finish its tasks
}
//… maybe do some actions here
}
}
9
Agent template
agent Robot extends Agent [implements SomeInterface]
{
//The agent handles events of SomeEvent
#handles event SomeEvent;
//The agent uses a plan of SomePlan
#uses plan SomePlan;
//The agent posts events of SomeEvent
#posts event SomeEvent ev;
public Robot(String name)
{
super(name);
postEvent( ev.go(99) );
}
//give a name for the agent
//issue an event to start the agent
}
10
Compilation
• In your current directory containing your
source code, use the command:
java aos.main.JackBuild
After successful compilation
Before compilation
..
Robot.agent
SomeEvent.event
SomePlan.plan
compile
..
Robot.agent
Robot.java
Robot.class
SomeEvent.event
SomeEvent.java
SomeEvent.class
SomePlan.plan
SomePlan.java
SomePlan.class
You need to correct your source code until so see [JackBuild Done]
on the screen after compiling
11
How to make use of an agent
• Two ways:
1. Create an agent which can run by itself
2. Instantiate an agent inside another java
class
12
Create a runnable agent
• Like a normal agent, but implementing the
method called ‘main’ inside the file .agent,
e.g.:
…
public static void main(String[] args) {
…
Robot robot = new Robot(“My Robot”);
…
}
…
13
Instantiate an agent inside
another class
• Create a java class, e.g., AgentSystem.java
• Implement the ‘main’ method inside this
class, e.g.:
…
public static void main(java.lang.String[] args){
…
Robot robot= new Robot(“My Robot”);
…
}
…
14
Examples
• Implement an agent which autonomously
counts integer numbers from 1 to 10
• Download this example from:
http://homepage.cs.latrobe.edu.au/ccvo/cse4mas10.html
15
CounterEvent.event file
event CounterEvent extends Event
{ public int someNumber;
#posted as doCount(int number)
{
someNumber = number;
System.out.println(“The event occurs…”);
}
}
16
CounterPlan.plan file
plan CounterPlan extends Plan
{
#handles event CounterEvent e;
body()
{
System.out.println(“Current number is ” + e.someNumber);
@waitFor(elapsed(2));
//delay for 2 seconds
if(e.someNumber == 10){
System.out.println(“Count to 10! The agent finished its job!”);
System.exit(0);
}else{
@post(e.doCount(e.someNumber + 1));
}
}
}
17
CounterAgent.agent file
agent CounterAgent extends Agent
{
#handles event CounterEvent;
#uses plan CounterPlan;
#posts event CounterEvent ev;
public CounterAgent(String name){
super(name);
//give a name for the agent
postEvent( ev.doCount(1) ); //fire an event for starting to count
}
public static void main(String[] args){
CounterAgent counterAgent = new CounterAgent(“My Counter Agent”);
}
}
18
Reading
• http://www.agent-software.com/shared/products/index.html
• http://www.agent-software.com/shared/products/tutorials.html
• JACKTM Intelligent Agents Agent Manual
(http://www.aosgrp.com/documentation/jack/Agent_Manual_WEB/in
dex.html)
19