Jade (3 h) Dott. Daniela Briola. Jade Agent JADE Agents are defined as subclasses of the predefined class Agent Their initial code (if any) must be placed.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Advertisements

Peer-to-peer and agent-based computing P2P Algorithms.
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
FIPA Interaction Protocol. Request Interaction Protocol Summary –Request Interaction Protocol allows one agent to request another to perform some action.
CSCC69: Operating Systems
Java Card Technology Ch07: Applet Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Computer Science & Engineering.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
Classes and Instances. Introduction Classes, Objects, Methods and Instance Variables Declaring a Class with a Method and Instantiating an Object of a.
06 - Exceptions. 2 ©S. Uchitel, 2004 A familiar sight? Bluescreen.scr.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Introduction to JADE presenter: Syuan-Hao Li
Programming Agents with JADE for Multi-Agent Systems
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Multi-Agent System for Online Auctions Jose Manuel Valladares Pernas CIS Master Project - Fall 2004 Advisor: Dr. Haiping Xu.
C++ fundamentals.
Java Agent Development Environment (JADE) Jade is a platform for running agents; it supports: –An asynchronous agent programming model –Communication between.
Starting Chapter 4 Starting. 1 Course Outline* Covered in first half until Dr. Li takes over. JAVA and OO: Review what is Object Oriented Programming.
Object Oriented Software Development
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
Workshop 9 in AOM & MAS Prof Kuldar Taveter, Tallinn University of Technology.
1 Introduction of Java Agent Development Environment (JADE) Presented by Po-Cheng Huang.
IDK5151 kohtumine kaugõppijatega
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
Spoken dialog for e-learning supported by domain ontologies Dario Bianchi, Monica Mordonini and Agostino Poggi Dipartimento di Ingegneria dell’Informazione.
PHP meets MySQL.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Software Agent Computing Agent Mobility. Agent mobility is the ability for an agent program to migrate or to make a copy (clone) itself across one or.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Data Structures and Java CS 105. L7: Java Slide 2 Data structure Data structure defined: A systematic way of organizing and accessing data Examples Dictionary:
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
IBM TSpaces Lab 1 Introduction. Summary TSpaces Overview Basic Definitions Basic primitive operations Reading/writing tuples in tuplespace HelloWorld.
Tutorial 1 Running JADE Under Eclipse Dr. Fuhua Lin School of Computing and Information Systems Athabasca University, Alberta, Canada Oct. 27, 2009.
JADE: agents insights Fabiano Dalpiaz Agent-Oriented Software Engineering (AOSE)
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Supporting FIPA Interoperability for Legacy Multi-Agent Systems Christos Georgousopoulos 1 Omer F. Rana 1 ( ) 2.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
IBM TSpaces Lab 3 Transactions Event Registration.
Java Thread and Memory Model
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
M1G Introduction to Programming 2 5. Completing the program.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
Tutorial 2 Agent Actions Specification --- Behavior Dr. Fuhua Lin School of Computing and Information Systems Athabasca University, Alberta, Canada Oct.
IBM TSpaces Lab 2 Customizing tuples and fields. Summary Blocking commands Tuple Expiration Extending Tuples (The SubclassableTuple) Reading/writing user.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
Agent Overview. Topics Agent and its characteristics Architectures Agent Management.
Exception-Handling Fundamentals  A Java exception is an object that describes an exceptional (that is, error) condition that has occurred in a piece of.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
1 Critical Section Problem CIS 450 Winter 2003 Professor Jinhua Guo.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
JADE Java Agent Development Environment Yunus Emre ÇAKMAZ Ahmet Cahit YAŞA 1.
Real-Time Systems Laboratory Seolyoung, Jeong JADE (Java Agent DEvelopment framework )
Multi-Agent System for Online Auctions Jose Manuel Valladares Pernas CIS Master Project - Fall 2004 Advisor: Dr. Haiping Xu.
Information and Computer Sciences University of Hawaii, Manoa
The need for Programming Languages
Developing Mobile Agent Systems
Msury Mahunnah, Tallinn University of Technology
Arrays in C.
Tutorial 6 Directory Facilitator
Compiler Design 18. Object Oriented Semantic Analysis (Symbol Tables, Type Checking) Kanat Bolazar March 30, 2010.
CS360 Client/Server Programming Using Java
Java Programming Language
Classes, Objects and Methods
CMSC 202 Exceptions.
Presentation transcript:

Jade (3 h) Dott. Daniela Briola

Jade Agent JADE Agents are defined as subclasses of the predefined class Agent Their initial code (if any) must be placed in a method called setup Agent actions are normally specified through Behaviour classes

Jade Agent The actions are described in the "action" method of these Behaviours There are 2 kinds of behaviour classes: primitive, like the Simple or Cyclic behaviours and composite ones which can combine both simple and composite behaviours to execute in sequence or in parallel.

Jade Agent Primitive Behaviours SimpleBehaviour: an basic class that you can extend in various ways and which often turns out to be the best solution when other promising Behaviours are found to have some hidden quirks CyclicBehaviour: This behaviour stays active as long as its agent is alive and will be called repeatedly after every event. Quite useful to handle message reception. TickerBehaviour: a cyclic behaviour which periodically executes some user-defined piece of code OneShotBehaviour: This executes ONCE and dies.... Not really that useful since the one shot may be triggered at the wrong time. WakerBehaviour: which executes some user code once at a specificied time ReceiverBehaviour: which triggers when a given type of message is received (or a timeout expires).

Jade Agent Primitive Behaviours Note: TickerBehaviour, WakerBehaviour and ReceiverBehaviour are conceptually subclasses of Cyclic and OneShot classes, but they are implemented as extentions of Simplebehaviour and Behaviour Composite Behaviours ParallelBehaviour: controls a set of children behaviours that execute in parallel. The important thing is the termination condition: we can specify that the group terminates when ALL children are done, N children are done or ANY child is done. SequentialBehaviour: this behaviour executes its children behaviours one after the other and terminates when the last child has ended.

Example 1: HelloWorld Agent import jade.core.Agent; import jade.core.behaviours.*; public class Simple0 extends Agent { protected void setup() { addBehaviour( new B1( this ) ); } } class B1 extends SimpleBehaviour { public B1(Agent a) { super(a); } public void action() { System.out.println( "Hello World! My name is "+ myAgent.getLocalName());} private boolean finished = false; public boolean done() { return finished; } } //End class B1

Example 1: HelloWorld Agent myAgent: is a local variable of all Behaviour objects which stores the agent reference passed as a parameter when the behaviour was created. The class B1 is specified outside the context of the Agent, but it can use myAgent to access its owner's attributes and methods. The mane of the agen is got with the myAgent.getLocalName()

Example 1: HelloWorld Agent Here are the commands required to compile and run our agent (type them from the directory where the code, Hello.java, is). % javac Hello.java % java jade.Boot fred:Hello Below there is the output of execution. But… that the agent loops and keeps on printing its message until we abort execution! % Hello World! My name is fred Hello World! My name is fred Hello World! My name is fred Hello World! My name is fred..... loops until stopped with CTRL-C.... ! The problem here is that we haven't explicitely indicated that the action was "done".

Example 1: HelloWorld Agent We add a local variable, "n", to the behaviour to terminate its operation after "action" has been called 3 times import jade.core.Agent; import jade.core.behaviours.*; public class Hello2 extends Agent { protected void setup() { addBehaviour( new SimpleBehaviour( this ) { int n=0; public void action() { System.out.println("HelloWorld!My name is "+myAgent.getLocalName()); n++; } public boolean done() { return n>=3; } } ); } // --- setup --- } // --- class Hello2

Example 2: Communication Here is a list of all attributes of a Jade ACL message. Jade provides get and set methods to access all the attributes. Performative - FIPA message type (INFORM, QUERY, PROPOSE,...) Addressing Receiver Sender (initialized automatically) Content - This is the main content of the message ConversationID - Used to link messages in same conversation

Example 2: Communication Language - Specifies which language is used in the content Ontology - Specifies which ontology is used in the content Protocol - Specifies the protocol ReplyWith - Another field to help distinguish answers InReplyTo - Sender uses to help distinguish answers ReplyBy - Used to set a time limit on an answer

Example 2: Communication When you create a message, you have to indicate its type (its ACL performative) and set the content. Example: ACLMessage msg = new ACLMessage(ACLMessage.INFORM ); msg.setContent(“My name is Spock" );

Example 2: Communication Common type of performative are: INFORM whereby one agent gives another some useful information QUERY to ask a question REQUEST to ask the other to do something PROPOSE to start bargaining AGREE or REFUSE

Example 2: Communication Then, assuming you want to send a message to the agent “Receiver”, sending a message is fairly easy AID dest =new AID( “Receiver", AID.ISLOCALNAME) ; msg.addReceiver( dest ); send(msg); Note: We use addReceiver because there is no setReceiver method.... One reason is that we can add several receivers to the message. AID.ISLOCALNAME is a constant

Example 2: Communication Messages are routed to wherever the destination agent resides and are placed in its message queue. There are 2 basic ways for the receiver to get its messages. blockingReceive(), the receiving agent suspends all its activities until a message arrives Receive(), which returns a message if there is one or null otherwise. This is the normal technique used when an agent is involved in parallel activities and has multiple active Behaviours.

Example 2: Communication Answering messages All messages have an attribute which contains the ID of the sender. We can answer a message as follows: ACLMessage msg = receive(); ACLMessage reply = new ACLMessage( ACLMessage.INFORM ); reply.setContent( "Pong" ); reply.addReceiver( msg.getSender() ); send(reply);

Example 2: Communication Answering messages To simplify answering, Jade provides a method createReply() which creates a new message with the sender and receiver attributes switched and all other attributes set correctly. Generally, only the content and performative have to be modified before sending it back.

Example 2: Communication Class Ping import jade.core.Agent; import jade.core.AID; import jade.core.behaviours.*; import jade.lang.acl.*; public class Ping extends Agent { protected void setup() { addBehaviour(new CyclicBehaviour(this) { public void action() { ACLMessage msg= receive(); if (msg!=null) System.out.println( "== Answer" + " <- " + msg.getContent() + " from " + msg.getSender().getName() ); block(); } }); ACLMessage msg = new ACLMessage(ACLMessage.INFORM); msg.setContent( "Ping" ); msg.addReceiver( new AID( “Pong", AID.ISLOCALNAME) ); send(msg); } // sends message to Pong

Example 2: Communication Class Pong import jade.core.Agent; import jade.core.behaviours.*; import jade.lang.acl.*; public class Pong extends Agent { protected void setup() { addBehaviour(new CyclicBehaviour(this) { public void action() { ACLMessage msg = receive(); if (msg!=null) { System.out.println( myAgent.getLocalName() + " received: " + msg.getContent() ); ACLMessage reply = msg.createReply(); reply.setPerformative( ACLMessage.INFORM ); reply.setContent(" Pong" ); send(reply); } block(); } }); }} To execute the example run % java jade.Boot main:Ping Pong:Pong

Example 3: Using DF Agent JADE implements a Directory Facilitator (DF) agent as specified by FIPA. The DF is often compared to the "Yellow Pages" phone book. Agents wishing to advertize their services register with the DF. Visiting agents can then ask (search) the DF looking for agents which provide the services they desire. The DF entries concentrate on listing the ontologies, protocols and languages which are supported by the agents.

Example 3: Using DF Agent DFAgentDescription Name: AID // Required for registration Protocols: set of Strings Ontologies: set of Strings Languages: set of Strings Services: set of { Name: String // Required for each service specified Type: String // Required Owner: String Protocols: set of Strings Ontologies: set of Strings Languages: set of Strings Properties: set of { Name: String, Value: String } }

Example 3: Using DF Agent import jade.core.Agent; import jade.core.behaviours.*; import jade.domain.DFService; import jade.domain.FIPAAgentManagement.*; import jade.domain.FIPAException; public class DF2 extends Agent { protected void setup() { ServiceDescription sd = new ServiceDescription(); sd.setType( "buyer" ); sd.setName( getLocalName() ); register( sd ); } void register( ServiceDescription sd) { DFAgentDescription dfd = new DFAgentDescription(); dfd.setName(getAID()); dfd.addServices(sd); try { DFService.register(this, dfd ); } catch (FIPAException fe) { fe.printStackTrace(); } } }

Example 3: Using DF Agent When an agent terminates, it is good practice to delete its entry in the DF Although agent entries are removed automatically from the AMS when an agent dies, the system does not remove them from the DF and it is up to the programmer to do it explicitely Each agent is allowed only ONE entry in the DF. Attempts to register an agent already in the DF gives an Exception.

Example 3: Using DF Agent To search the DF, you must create a DFD [with no AID] where the relevant fields are initialised to the properties you require The search returns an array of DFDs (with AIDs) whose attributes match your description and you can extract the ID of suitable agents from those entries Generally, you either want to find ONE agent with the services you need or ALL of them.

Example 3: Using DF Agent DFAgentDescription dfd = new DFAgentDescription(); ServiceDescription sd = new ServiceDescription(); sd.setType( “Ping" ); dfd.addServices(sd); DFAgentDescription[] result =DFService.search(this,dfd); System.out.println(result.length + " results" ); if (result.length>0) System.out.println(""+result[0].getName() );

Grazie a tutti! Testi delle slides tratti da gents/Jade/primer4.html Gli esempi sono in parte tratti dal tutorial sopra citato, ma modificati in parte, o creati ad hoc per questa esercitazione.