multiagent systems a practical approach to MAS construction

  • Slides: 38
Download presentation
multiagent systems a practical approach to MAS construction in Java (using Boris) Simon Lynch

multiagent systems a practical approach to MAS construction in Java (using Boris) Simon Lynch s. c. lynch@tees. ac. uk

software architecture • distributed • mixed language • concurrent

software architecture • distributed • mixed language • concurrent

MMD for multiple users • dynamic structure

MMD for multiple users • dynamic structure

agents - why? Multi. Agent Systems. . . • advanced s/w architectures (dynamic, distributed.

agents - why? Multi. Agent Systems. . . • advanced s/w architectures (dynamic, distributed. . . ) • mobility, platform independence • design-time autonomy • reuse agents can also simplify. . . • concurrency • interfacing s/w units

agents – what? • independent software(? ) entities – send & receive messages like

agents – what? • independent software(? ) entities – send & receive messages like objects but. . . – distributed – autonomous at design & execution – have their own process thread – tighter encapsulation & interfaces – task oriented

agents – what types? various types. . . • web based, brokered • small

agents – what types? various types. . . • web based, brokered • small & mobile • larger scale / intelligent. . . etc. . .

agents - how? in Java with Boris analogy. . . • agents & GUI

agents - how? in Java with Boris analogy. . . • agents & GUI components • GUI events & message events

Boris example Panel p = new Panel(); Button b = new Button( text );

Boris example Panel p = new Panel(); Button b = new Button( text ); b. add. Action. Listener( new Action. Listener() { public void action. Performed( Action. Event event ) {. . . code body. . . } }); p. add( b ); Portal p = new Portal( portal-name ); Agent a = new Agent( agent-name ); a. add. Message. Listener(new Message. Listener() { public void message. Received(String from, String to, String msg, Msg. Id id) {. . . code body. . . } }); p. add. Agent( a );

Sending messages Portal p = new Portal( portal-name ); Agent sue = new Agent(

Sending messages Portal p = new Portal( portal-name ); Agent sue = new Agent( "sue" ); sue. add. Message. Listener(new Message. Listener() { public void message. Received(String from, String to, String msg, Msg. Id id) {. . . code body. . . } }); p. add. Agent( sue ); Agent sam = new Agent( "sam" ); p. add. Agent( sam ); . . . sam. send. Message( "sue", "hello sue" ); . . .

Virtual Networks normally, agents are distributed across • multiple VMs • multi-language VMs •

Virtual Networks normally, agents are distributed across • multiple VMs • multi-language VMs • multiple machines Boris uses network concept based on. . . • Portals • Routers

agents, portals, routers & VMs MAS design. . . a collection of communicating agents

agents, portals, routers & VMs MAS design. . . a collection of communicating agents

agents, portals & routers • agents communicate via portals • portals communicate via router(s)

agents, portals & routers • agents communicate via portals • portals communicate via router(s)

agents, portals & routers • agents who share a portal communicate directly • routers

agents, portals & routers • agents who share a portal communicate directly • routers not necessary for single-portal MASs

agents, portals & routers • cross-portal communication requires a router even if portals share

agents, portals & routers • cross-portal communication requires a router even if portals share a VM

connecting portals to routers portal methods • void connect. To. Grid( Inet. Address host,

connecting portals to routers portal methods • void connect. To. Grid( Inet. Address host, int port. No ) • void connect. To. Grid( Inet. Address host ) • void connect. To. Grid( ) NB: • connection in separate thread • may take few seconds over internet

using the console

using the console

loading agents import boris. kernel. *; . . . public class My. Class {

loading agents import boris. kernel. *; . . . public class My. Class { public My. Class( Portal portal, String cmd. Line ) { //--- set up agent ---final Agent agent = new Agent( name ); portal. add. Agent( agent ); . . . }

tracking activity

tracking activity

multiagent systems clones, replies & sessions Simon Lynch s. c. lynch@tees. ac. uk

multiagent systems clones, replies & sessions Simon Lynch s. c. lynch@tees. ac. uk

clones - what • non-clones have single instances for all message processing • clones

clones - what • non-clones have single instances for all message processing • clones run multiple instances • NB: – timers always run independently – Java agents are cloneable by default

clones - how new Agent( name, Agent. NON_CLONEABLE ); new Agent( name, Agent. CLONEABLE

clones - how new Agent( name, Agent. NON_CLONEABLE ); new Agent( name, Agent. CLONEABLE ); new Agent( name );

sending replies Portal p = new Portal( portal-name ); Agent sue = new Agent(

sending replies Portal p = new Portal( portal-name ); Agent sue = new Agent( "sue" ); sue. add. Message. Listener(new Message. Listener() { public void message. Received(String from, String to, String msg, Msg. Id id) {. . . sue. send. Reply( id, "hello" + from ); . . . } }); p. add. Agent( sue ); Agent sam = new Agent( "sam" ); p. add. Agent( sam ); . . . sam. send. Message( "sue", "hello sue" ); . . .

Msg. Id NB: mostly Msg. Ids handle themselves, but these methods are supported. .

Msg. Id NB: mostly Msg. Ids handle themselves, but these methods are supported. . . Msg. Id public String get. Sender() public String get. Session. Id() public boolean expects. Reply()

receiving replies - 1 Wait. Reply send. And. Wait( String to, String message )

receiving replies - 1 Wait. Reply send. And. Wait( String to, String message ) Wait. Reply public String get. From() public String get. Reply() public Msg. Id get. Mfor() public Msg. Id get. Id() String reply = sam. send. And. Wait( "sue", "hello" ). get. Reply();

receiving replies - 2 sam. add. Message. Listener(new Message. Listener() { public void message.

receiving replies - 2 sam. add. Message. Listener(new Message. Listener() { public void message. Received(String from, String to, String msg, Msg. Id id) {. . . sam. send. Reply( id, message 2 ); . . . } }); Reply. Listener rl = new Reply. Listener() { public void reply. Received( String from, Msg. Id mfor, String reply, Msg. Id id ) {. . . } }; Msg. Id mid = sue. send. Message( "sam", message 1 , rl );

boris - additional timers, scope & brokering Simon Lynch s. c. lynch@tees. ac. uk

boris - additional timers, scope & brokering Simon Lynch s. c. lynch@tees. ac. uk

timers why, what & how? 1. agent timers 2. countdown timers 3. alarm timers

timers why, what & how? 1. agent timers 2. countdown timers 3. alarm timers

agent timers Agent a = new Agent( name ); a. add. Agent. Timer. Listener(

agent timers Agent a = new Agent( name ); a. add. Agent. Timer. Listener( new Agent. Timer. Listener() { public void timer. Elapsed( Agent a ) {. . . code body. . . } }); a. set. Delay( delay ); . . . a. start(); . . . a. stop(); . . .

the ball example Agent a = new Agent( "anon" ); a. add. Agent. Timer.

the ball example Agent a = new Agent( "anon" ); a. add. Agent. Timer. Listener( new Agent. Timer. Listener() { public void timer. Elapsed( Agent a ) { erase(); x = (x+dx) % bounds; y = (y+dy) % bounds; display(); } }); a. set. Delay( delay ); display(); a. start(); }

a countdown timer Agent a = new Agent( name ); a. add. Agent. Timer.

a countdown timer Agent a = new Agent( name ); a. add. Agent. Timer. Listener( new Agent. Timer. Listener() { public void timer. Elapsed( Agent a ) { if( coundown-elapsed ) { a. stop(); switch. Off(); } else {. . . code body. . . } } }); a. set. Delay( delay ); switch. On(); a. start();

alarm timer given: Calendar alarm. Time. . . Agent a = new Agent( name

alarm timer given: Calendar alarm. Time. . . Agent a = new Agent( name ); a. add. Agent. Timer. Listener( new Agent. Timer. Listener() { public void timer. Elapsed( Agent a ) { a. stop(); alarm. On(); } }); long alarm. MS = alarm. Time. get. Time(); long now. MS = new Date(). get. Time(); a. set. Delay( alarm. MS – now. MS ); if (delay > 0 ) a. start(); else alarm. On();

scope why, what & how? • • MAS partitions holons reduced complexity tailored partitions

scope why, what & how? • • MAS partitions holons reduced complexity tailored partitions • enhanced security (eg: localised brokers)

scope in Boris why, what & how? • • • internal local global -

scope in Boris why, what & how? • • • internal local global - behind portal - behind router - the default

scope

scope

scope in Boris why, what & how? portal. add. Agent( agent ) portal. add.

scope in Boris why, what & how? portal. add. Agent( agent ) portal. add. Agent( agent, Portal. INTERNAL ) portal. add. Agent( agent, Portal. LOCAL )

Brokers yellow pages agents • some are localised (in holons, etc) • some keep

Brokers yellow pages agents • some are localised (in holons, etc) • some keep record of providers • need for central service? in boris / java • map agents to services • services to agents • etc

starting a router

starting a router