Development Guide

0 downloads 0 Views 1MB Size Report
through the Java environment. The MaSMT3 ..... The MaSMT agent is a Java thread consists of three sections on its life circle such as active, .... public static void main(String[] args) { .... public SalesAgent(String item,float unit_price, int quntity,.
MaSMT 3.0

Development Guide

B.Hettige, AS Karunananda, and G. Revisky

Version 3.0 (Update 08.08. 2017)

Abstract This document describes how to develop a multi-agent system with the MaSMT agent platform. MaSMT is a free, lightweight Multi-agent system development framework, design through the Java environment. The MaSMT3 framework provides three types of agents, namely ordinary agent and managing agent and root agent. The managing agent capable to handle set of ordinary agent and the root agent capable to handle set of manager agents. MaSMT3.0 includes few features than the previous versions. MaSMT 3.0 includes root agent to handle swam of agents, Environment handling features to dynamically store agent’s ontology, and notice board has been introducing to see required messages and events. In addition to these main features, agent status monitor has been introducing to view transporting messages.

1 |MaSMT3.0: Development Guide

Table of Contents Abstract ............................................................................................................................................ 1 Table of Contents .............................................................................................................................. 2 Introduction ...................................................................................................................................... 3 Infrastructure .................................................................................................................................... 3 Agent Model.................................................................................................................................. 4 MaSMTAbstractAgent ................................................................................................................... 4 MaSMT Agent ................................................................................................................................ 5 MaSMT Agent’s Life circle .............................................................................................................. 6 MaSMT Manager ........................................................................................................................... 7 MaSMT Root Agent ..................................................................................................................... 10 Example Multi agent System........................................................................................................ 11 Swarm of Agent in MaSMT .......................................................................................................... 11 MaSMT Messages............................................................................................................................ 12 MaSMT Messages ........................................................................................................................ 13 MasMT Settings............................................................................................................................... 14 MaSMT Message Parsing ................................................................................................................. 16 Send Messages ............................................................................................................................ 16 Read Messages ............................................................................................................................ 16 Message Header .......................................................................................................................... 16 Application of MaSMT ..................................................................................................................... 17 Examples ......................................................................................................................................... 17 Hello world Agent ........................................................................................................................ 18 Ping agents .................................................................................................................................. 19 Market Simulation System ........................................................................................................... 22 References ...................................................................................................................................... 26

2 |MaSMT3.0: Development Guide

Introduction Multi-agent technology is a modern software palindrome that capable of handling the complexity of a software system and providing intelligent solutions through the power of agent communication. A framework is a useful tool to develop a multi-agent system and it saves much programmer’s time and provides standards for the agent development. MaSMT (Multi-Agent System for Machine Translation) released as Open Source under the GNU General Public License (GPL). Hence, the license allows using the software to examine and modify the source code and to develop applications based on the platform. The framework has been completely developed through the Java and provides Cross-platform capabilities. There is no prerequisite on MaSMT agents. First Open source version of the MaSMT was released on 2nd March 2016 for to provide general infrastructure for the multi agent system development. The new version of the MaSMT includes some modification of the MaSMT to archive best performance. MaSMT3.0 includes few features than the previous version including root agent to handle swam of agents, Environment handling features to store agent’s action and mail transport agent to send and reserving messages as emails. In addition to these main features, activity monitor has been introducing to view transporting messages.

Infrastructure This section briefly describes the structure of the MaSMT agents. The MaSMT framework provides three types of agents, namely ordinary agent, manager agent and root agent. The regular agents are the action holding agents of the framework; precede relevant tasks according to the given messages. A manager agent consists of some ordinary agents within its control. The root agent is the top level agent in the system which is capable to handle set of manager agents. Through the root agent, it is much easy to manage a swarm of agents. Further, manager agents can directly communicate with other manager agents as well as its root agent. Each and every ordinary agent in the system assigns to a particular manager agent. and manager can assign to a particular root agent. A regular agent (ordinary agent) in a swarm can directly communicate only with the agents in its swarm and its manager. The framework primarily implements infrastructure of the agents, required actions to handle agent's environment,

3 |MaSMT3.0: Development Guide

message parsing activities to agent communication and action monitoring facilities to view an agent's action for implement multi-agent system easily.

Agent Model MaSMT agents consist of an abstract model of the agents. Each agent in the system consists of group, role, and agent id. According to the MaSMT architecture, any group consists of one-tomany roles and any role includes some MaSMT agents with independent agent id. Further, MaSMT agents are capable of changing their role or group at run-time. Therefore, an agent can appear in the different swam as it required. However, only one place at a time Figure 1 shows the abstract agent model of the MaSMT system. MaSMTAbstractAgent class is used to model the entire requirement of the abstract model.

Group

1

n

1

ROLE

n

Agent ID

Figure 1: an Abstract model of the MaSMT agent.

MaSMTAbstractAgent MaSMTAbstractAgent is an abstract model of the each agent in the MaSMT framework and which is used to identify each agent independently. The abstract agent consists of a group, a role, and an agent id. In another word, each agent of the MaSMT system has an id and assigns for the particular group and a role. For instance, an agent in a group ‘communicate’ and role is read_message and id is1 then complete agent name of the abstract agent is donated as; read_message.1@communicate More information for the MaSMT Abstract agent including its fields, methods and available constructors are described in the below.

4 |MaSMT3.0: Development Guide

MaSMT Agent MaSMTAgent is the ordinary agent in the framework, normally called as an action agent. MasMT agent consists of an abstract agent, two message queues (in-queue and out-queue), access rule, communication module, Environment controller, Status monitor and notice-board reader to handle the agent’s functionalities. Figure 2 shows the modular architecture of the MaSMT agent. In Queue

Out Queue

Agent Controllers

Communication Module Abstract Agent

Environment Controller

Core module Status Monitor

Notice-board Reader

Figure 2: Modular architecture of the MaSMT Agent 5 |MaSMT3.0: Development Guide

The abstract agent provides agent identification mechanism of the multi agent system through the group, role and agent id. The communication module handles all the communication requirement of the agent with a support of the message queues. The status monitor can be used to show the message transport status of the agents through the agent status monitor GUI. The Environment controller is used to changing the environment and update the agent ontology as required. In addition to the above notice-board viewer can be used to read messages and events available on the notice board. According to the MaSMT architecture MaSMT agent can only view the content available on the noticeboard.

MaSMT Agent’s Life circle The MaSMT agent is a Java thread consists of three sections on its life circle such as active, live and end. The active section starts when the agent is going to activate. After completing the active section, the agent moves to its live section. The agent is in the live section while its live property is true. That can be done through the method ‘setLive(false)’ The agent does it all the actions such as read messages reply for the messages are doing in the live section. In addition, a developer can change the delay of the agent’s live circle. The end section of the MaSMT agent appears when the agent is going to die. Figure 3 shows the life-circle of the MaSMT agent.

New Agent

Active Timed wait Live Wait for message End

Figure 3: Life circle of the MaSMT Agent More information for the MaSMT agent including constructors and available methods are given in the below. 6 |MaSMT3.0: Development Guide

MaSMT Manager The MasMT Manager is a controlling agent of the system with additional features than the MaSMT ordinary agents. According to the MaSMT architecture, The manager agent consists of an abstract agent, two message queues (in-queue and out-queue), access rule, 7 |MaSMT3.0: Development Guide

communication module, Environment controller, Status monitor, notice-board reader, network access agent and Message transport agent to archive managers functionalities. The MaSMT manager can fully control its client agent(s). The Manager agent in the MaSMT creates all its client-agent automatically (as required) at the initialization stage or whenever its use. The manager can directly access its client agents and send messages to them or control them as required. Further, manager agent can control the priority of the agents and the state of the agents. This facility removes the unnecessary workload from its client agents. The in-Queue of the managers is a queue used to store incoming messages. The manager adds messages for the out-queue, where the messages need to send to others group. In Addition to the above basic module, MaSMT manager agent consists of net access agent and message transport agent. The net access agent supports client-server communication for the system. This agent provides facilities to connect any managers on the net through the client-server networking. Message transport agent provides message transport facilities to the manager. Figure 4 shows the architecture of the MaSMT Manager. Compare with MaSMT agent, the manager agent has full control of the notice board. Therefore message transport agent capable to handle peer-to-peer broadcast and notice-board based agent communications.

In Queue

Out Queue

Agent Controller

Communication Module Abstract Agent

Environment Controller

Core module Status Monitor

Notice-board Reader

Net Access agent

Massage transport agent

Client Agents (MaSMT Agents)

Figure 4: Modular View of the MaSMT Manager

8 |MaSMT3.0: Development Guide

More information about MaSMT Manager Agent, including constructors and avilable methods are given in the below.

9 |MaSMT3.0: Development Guide

MaSMT Root Agent MasMT Root is a special type of Manager agent (MaSMT Manager) that capable to handles managers in the multi agent system. This MaSMT Root agent can fully control its client managers same as the manager handle its client agents. Further, the root agent can create, remove or control (handle agent priority) its client manager(s). The in-Queue of the root agent is a message queue that uses to store incoming messages (messages are coming from another machine). The Root agent also adds messages on out-queue where messages need to send to others machines. Same as MaSMT Managers The Root agent consists of Message transport agent and net access agent to handle messages. Theoretically, Root agent is the top level manager of MaSMT system. Therefore, only one root agent available for a multi agent system in a machine. However, the root agent able to communicate with another root agents through the Net access agent. A brief description of a MaSMT systems including a root agent, number of manager agents, and number of client agents provides in the below.

10 |MaSMT3.0: Development Guide

Example Multi agent System The system consists of 3 layers of agents namely Root , Manager and agent. Figure 5 shows the agent’s diagram of a MaSMT system.

MaSMT Root

MaSMT Manager

MasMT Agent

MaSMT Manager

MasMT Agent

MasMT Agent

MasMT Agent

MasMT Agent

MasMT Agent

MasMT Agent

Figure 5: Agent diagram of a MaSMT system According to the above agent diagram, root agent is the top level Manager, and other managers work under the root. Agents of the MaSMT categorized through agent’s rule and group. The communication between MaSMT agents (message parsing) based on the abstract model of the agents. Swarm of Agent in MaSMT MaSMT consists of set of functionalities to handle swarm of agents easily. This section briefly describe a way to build agent swarm with manage and number of client agents. The manager agent can hold any number of client agent up to 2000 with cluster then through the group or 11 |MaSMT3.0: Development Guide

role. MaSMT manage capable to handle all of the through the peer-to-peer, or according to the role or group. Figure 6 shows the functional architecture of the Agent swarm. In Queue

Out Queue

Agent Controller

Communication Module Abstract Agent

Environment Controller

Core module Status Monitor

Notice-board Reader

Net Access agent

Massage transport agent

Client Agents Client Agents Client Agents Client Agents Client Agents Client Agents

Ontology

Figure 6: Functional architecture of the swarm of Agents

MaSMT Messages Multi-agent systems are distributed systems that normally run concurrently. Communication among others is the hidden factor behind the success of the multi-agent systems. This agent commnication is done through the messages. Therefore number of stanaded avilable for the agect commnucation including FIFA-ACL. With considering all the above, MaSMT uses a message type named MaSMTMessages. MaSMTMessage is a type of agent’s communication message, uses to communicate with agents. The MaSMT Messages design by using FIPA-ACL message standards. MaSMT uses MaSMTMessage (a message) to communicate between MaSMT agents as well as another agent through the FIPA-ACL message standed. More information about MaSMT Messages including message fields and constructors and convertion methods are also provided here. The table 1 gives the MaSMTMessage Message parameters required to create a message.

12 |MaSMT3.0: Development Guide

Data Field

Type

Category

sender

MaSMTAbstractAgent

receiver

MaSMTAbstractAgent

replyTo

MaSMTAbstractAgent

message

String

content

String

Denotes the identity of the sender of the message Denotes the identity of the receiver of the message Conversation are to be directed to the agent Message should be subject of the message Original content of the message

ontology

String

Ontological information

type

String

Type of the message

data

String

Some data (image, URL etc)

header

String

language

String

Directive field of the message (MaSMT send message with considering it header Language and encoding type

conversationId String

Conversation id of the message

Table 1: MaSMTMessage parameters The following list shows the data fields available in the MaSMTMessages. MaSMT Messages

13 |MaSMT3.0: Development Guide

MasMT Settings MaSMT Settings class uses to handle (Set) Environment settings of the Multi-agent system. This configuration required enabling system agents as required. Details of the configuration settings of the MaSMTSettings class is given in the below.

14 |MaSMT3.0: Development Guide

The MaSMT Settings class fields provide as public static fields. Therefore, any system agent can easily access these configuration data as required. However, if you not set MaSMT settings before active a manager agent, the manager uses default MaSMT settings. Default configuration settings of the MasMT System is given below.

15 |MaSMT3.0: Development Guide

MaSMT Message Parsing This section briefly describes message parsing methods used in the MaSMT system. MaSMT support peer-to-peer, broadcast and noticeboard methods to message parsing. The following subsestion give brief description on each options. Send Messages 1. To enable message parsing call activeMessageParsing(); on the managers 2. Create message and call addMessage(MaSMTMessage) 3. To send messages for all clients, call broadCastToClients(MaSMTMessage)

Read Messages 1. getMessage(): get message from in-queue. If message queue is empty then return null 2. peekMessage(): get front message without changing front message 3. waitForMessage(): system waits until message read. Message Header Agents can easily redirect messages according to it message header. local: send a message to a particular client(s) who has given group and rule. localgroup: send a message to a particular client(s) who has a given group

16 |MaSMT3.0: Development Guide

localrule: send a message to a particular client(s) who has a given rule localruleorgroup: send a message to a particular client(s) who has a given rule or group broadcast: send a message to all clients broadcasttomanagers: send message to all other managers localmanager: send a message to a particular Manager(s) who has given group and rule. localmanagergroup: send message to a particular manager(s) who has a given group localmanagerrule: send message to a particular manager(s) who has a given rule localmanagerruleorgroup: send message to a particular manager(s) who has a given rule or group manager- send message directly to the manager

Application of MaSMT Using the framework number of the multi-agent system has been developed including Natural Language Processing applications such as English to Sinhala Agent-based Multi-agent system [2], Sinhala Ontology Generator [3] and Multi-agent based Morphological Analyzer [4]. In addition to the above Intelligent chatbot [5] and a communication platform for Agricultural domain [6], File sharing application through the distributed environment [7] has already developed through the MaSMT.

Examples The following section briefly gives some example to demonstrate how to use MaSMT framework for developing multi-agent systems. 1. 2. 3. 4.

Helloworld Agent Ping agents Market example with manager-client message parsing Market example with client-client message parsing

17 |MaSMT3.0: Development Guide

Hello world Agent The objective of this example is to demonstrate how agent follows it life-circle. The HelloWorldAgent executes active, live and end section continuously and going to die. In the live section agent print, a message on 10 times. public class HelloWorldAgent extends masmt3.agent.MaSMTAgent {

Create MaSMT Agnt

public HelloWorldAgent() { super(); } public static void main(String[] args) { // Create an agent HelloWorldAgent agent = new HelloWorldAgent(); agent.start(); }

Live section in the agent

public void live() { System.out.println("Agent in the live mode.."); for (int i = 10; i > 0; i--) { System.out.println("I am exit in " + i + " seconds"); wait(500);

Wait 500 ms

} setLive(false);

Exit from the live section

} public void active() {

Active Section

System.out.println("I am " + super.agent); } public void end() {

End Section (After the live section)

System.out.println("End."); } }

18 |MaSMT3.0: Development Guide

Ping agents This example demonstrates how agents communicate with each other. The example consists of three agents including a manager agent, and 2 ordinary agents namely PingAgentA and PingAgentB. These two agents communicate together through the message parsing. The manager agent creates two agents with the same group and 2 rule (“roleA”and “roleB”). The PingAgentA send a message to PingAgentB and PingAgentB read this message and reply to pingAgentA again. This reply message also read by the PingAgentA and reply again for the PingAgentB. The following diagram shows agent diagram for the example.

PingManager

PingAgentA

PingAgentB

public class PingManager extends masmt2.agent.MaSMTManager { MaSMTMessage tempmes; //A Temporry message public PingManager() { super(); } public static void main(String[] args) { // Create a Manager agent with 2clients PingManager pma = new PingManager(); pma.start(); } public void active() {

19 |MaSMT3.0: Development Guide

System.out.println("[Active] MANAGER

.... " + super.agent);

// SET Number of Client agents 2 setNumberofClients(2); Set Number of client agent is 2 agents[0] = new PingAgentA("group", "roleA", 1); agents[1] = new PingAgentB("group", "roleB", 2); activeAllClients();

Create 2 Ping Agents with same rule and rgoup

activeMessageParsing(); }

Active Message Parsing

public void live() {

}

public void end() {

} PingAgentA

} public class PingAgentA extends masmt2.agent.MaSMTAgent { MaSMTMessage tempmes; public PingAgentA() { super(); } public PingAgentA(String gp, String role, int id) { super(gp, role, id); } public void active() { System.out.println("[Active] .... " + super.agent); If(agent.id== 1){

Create a new reader

MaSMTAbstractAgent reader = new MaSMTAbstractAgent("goup", "roleB",2); MaSMTMessage m =new MaSMTMessage(agent, reader, agent, "ping", "AgentA","text", "local"); 20 |MaSMT3.0: Development Guide

sendMessage(m); Set Message header as local

}} public void live() {

System.out.println("[live] ...."+ super.agent); // Read new

Message

tempmes = waitForMessage(); MaSMTMessage newm =

Create Reply Message

Wait for a message

new MaSMTMessage(agent, tempmes.sender, agent, "ping",tempmes.content+"-agentA", "text","local"); System.out.println(super.agent +"[AgentA GET]" + tempmes); sendMessage(newm);

Get Message content

wait(1000); } public void end() {

}

} PingAgentB public class PingAgentB extends masmt2.agent.MaSMTAgent { MaSMTMessage tempmes; public PingAgentB() { super(); } public PingAgentB(String gp, String role, int id) { super(gp, role, id); }

21 |MaSMT3.0: Development Guide

public void active() { }

public void live() { System.out.println("[live] ...."+ super.agent); tempmes = waitForMessage(); MaSMTMessage newm = new MaSMTMessage(agent, tempmes.sender, agent, "ping",tempmes.content+"-agentB", "text","local"); System.out.println(super.agent +"[AgentA GET] " + tempmes); sendMessage(newm); wait(1000); } public void end() { } }

Market Simulation System This example simulates Market example including a number of the Sales agent and a customer agent. The MaketManager is the manager agent that create all the required agents. The customer agent is a request agent that make a request to get items from the market. The sales agents are a resource and with sales items. According to the customer agent request the resource agents are replied when they can sell items. After Agent communication customer agent is able to select suitable sales request. This example is also available on the MaSMT download location. URL: https://sourceforge.net/projects/masmt/ 22 |MaSMT3.0: Development Guide

MarketManag er SalesAgent4 Customer

SalesAgent1

SalesAgent2

SalesAgent3 SalesManager public class SalesManager extends masmt2.agent.MaSMTManager { MaSMTMessage tempmes; public SalesManager() { super(); } public static void main(String[] args) { // Create an agent to start SalesManager sma = new SalesManager(); sma.start(); } @Override public void active() { System.out.println("[Active] MANAGER setNumberofClients(5); agents[0] agents[1] agents[2] agents[3] agents[4]

= = = = =

new new new new new

.... " + super.agent);

CustomerAgent("masmt", "cus", 1); SalesAgent("Bread", 48.00f, 25, "masmt", "sale", 2); SalesAgent("Suger", 168.00f , 25, "masmt", "sale", 3); SalesAgent("Toffee",1.00f , 25, "masmt", "sale", 4); SalesAgent("Chocalate",35.00f, 25,"masmt", "sale", 5);

activeAllClients(); activeMessageParsing(); } public void live() { } public void end() { } 23 |MaSMT3.0: Development Guide

} Sales Agent

public class SalesAgent extends masmt2.agent.MaSMTAgent { //Sale agent data private String item; private int quntity; private float unit_price; private float value; // Temporary message MaSMTMessage tempmes; public SalesAgent() { super(); } public SalesAgent(String gp, String role, int id) { super(gp, role, id); } public SalesAgent(String item,float String gp, String role, int id) { super(gp, role, id); this.item = item; this.quntity = quntity; this.unit_price = unit_price; }

unit_price,

int

quntity,

@Override public void active() { System.out.println("[Active] .... " + super.agent); } @Override public void live() { //System wait until message read tempmes = waitForMessage(); if(tempmes.message.equals("get_sales")) { value = Float.parseFloat(tempmes.content); int qount = (int) (value/unit_price); if(qount>0) { String m =""+ agent +" SALE "+ qount + " " + item + "( " + unit_price + " per each)" ; 24 |MaSMT3.0: Development Guide

System.out.println(m); } } setLive(false); } public void end() {

}

}

Customer Agent

public class CustomerAgent extends masmt2.agent.MaSMTAgent { public float price; MaSMTMessage tempmes; public CustomerAgent() { super(); } public CustomerAgent(String gp, String role, int id) { super(gp, role, id); } public void active() { Scanner in = new Scanner(System.in); System.out.println("[Active] .... " + super.agent); System.out.println("Enter amount : (Customer's Amount) : "); price = in.nextFloat(); MaSMTAbstractAgent sender =new MaSMTAbstractAgent("masmt","sale",1); MaSMTAbstractAgent reader =new MaSMTAbstractAgent("masmt", "sale",2); MaSMTMessage m =new MaSMTMessage(sender, reader, sender, "get_sales", ""+price,"text", "broadcast");

sendMessage(m); //Customer send message to all } public void live() { tempmes = waitForMessage(); 25 |MaSMT3.0: Development Guide

System.out.println(""+ tempmes); } public void end() {

}

}

To get more details of the MaSMT project and it applications use MaSMT web site https://sourceforge.net/projects/masmt/ A video tutorial also avilable on the youtube https://www.youtube.com/playlist?list=PLvnvW9V3TaBQRiDoKzYUZ832ZSauhNyyq

References 1.

B. Hettige, A. S. Karunananda, G. Rzevski, ”MaSMT: A Multi-agent System Development Framework for English-Sinhala Machine Translation”, International Journal of Computational Linguistics and Natural Language Processing (IJCLNLP), Volume 2 Issue 7 July 2013.

2.

B. Hettige, A. S. Karunananda, G. Rzevski, "Multi-agent solution for managing complexity in English to Sinhala Machine Translation", International Journal of Design & Nature and Ecodynamics, Volume 11, Issue 2, 2016, 88 – 96.

3.

B. Hettige, A. S. Karunananda, "Octopus: A multi-agent chat-bot", Proceedings of 8th International Research Conference KDU 2015.

4.

B. Hettige, A. S. Karunananda, G. Rzevski, “Multi-agent System Technology for Morphological Analysis”, Proceedings of the 9th Annual Sessions of Sri Lanka Association for Artificial Intelligence (SLAAI), Colombo, 2012

5.

B. Hettige, A. S. Karunananda, G. Rzevski, "A Sinhala Ontology Generator for English to Sinhala Machine Translation", Proceedings of KDU International Research Symposium 2014

6.

HMHR Jayarathna, B Hettige, "AgriCom: A communication platform for agriculture sector", Proceedings of the 8th IEEE International Conference Industrial and Information Systems (ICIIS), 2013.

7.

L D S B Weerasinghe, B Hettige, R P S Kathriarachchi and A S Karunananda. Resource Sharing in Distributed Environment using Multi-agent Technology. International Journal of Computer Applications 167(5):28-32, June 2017.

26 |MaSMT3.0: Development Guide