ֲͲ ò ² Ͳֲ

[ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ 14 ] [ 15 ]
[ 16 ] [ 17 ] [ 18 ] [ 19 ] [ 20 ] [ 21 ] [ 22 ] [ 23 ] [ 24 ] [ 25 ] [ 26 ] [ 27 ] [ 28 ] [ 29 ] [ 30 ] [ 31 ] [ 32 ]
[ 33 ] [ 34 ] [ 35 ] [ 36 ] [ 37 ] [ 38 ] [ 39 ] [ 40 ] [ 41 ] [ 42 ] [ 43 ] [ 44 ] [ 45 ] [ 46 ] [ 47 ] [ 48 ] [ 49 ] [ 50 ]

 


( ), , .
, GUI . , , Java RAD-.
г
, :
getAdress() Agent
Adress;
setName() getName() . . , , AgentAdress;
getAgentInformation() (, ,...).
. println() . , GUI, . setOutputWriter(). debug(), , . ֳ setDebug(). setDebugWriter().
ϳ Agent
Agent AbstractAgent. . .
life(), . , Agent , , , life().
waitNextMessage(). , ( FIFO). .
pause(), .
, :
protected void live()
{
while(te)
{
Message e = waitNextMessage();
if (e instanceof StringMessage)
handleMessage((StringMessage)e);
else if (e instanceof KQMLMessage)
handleMessage((KQMLMessage)e);
else if (e instanceof Message)
handleMessage(e);
}
}
, MadKit (< MadKit>\doc\devguide\devguide.html) HTPP://.madkit.org.
4), 5)
5.1. -볺
/*
* Client.java Travel, a simple demo application
*/
/* , :*/
import madkit.kernel.Agent;
import madkit.kernel.Message;
import madkit.kernel.AgentAddress;
import madkit.kernel.AbstractAgent;
import java.util.*;
import madkit.lib.messages.ACLMessage;
/* 볺, :*/
public class Client extends Agent
{
AgentAddress broker = null;
//
String transport, destination, reqstr;
//
public void activate()
{
createGroup(te,travel,travel-clients,null,null);
requestRole(travel,travel-clients, client,null);
//
if (Math.random() > 0.5)
{
transport = train;
if (Math.random() > 0.5)
destination = Moscow;
else
destination = Warsaw;
}
else
{
transport = plane;
if (Math.random() > 0.5)
destination = Paris;
else
destination = New York;
}
println (Looking for a +transport+ ticket to +destination);
//
while (broker == null)
{
broker = getAgentWithRole(travel,travel-clients,broker);
pause(500);
}
println (Found a broker:+broker);
}
//
public void live()
{
reqstr=transport+ to +destination;
println (Sending ticket request: +reqstr);
//
sendMessage(broker,new ACLMessage(REQUEST,reqstr));
println (Waiting for an offer...);
//
while (te)
{
Message m = waitNextMessage();
if (m instanceof ACLMessage)
handleMessage((ACLMessage)m);
else
System.err.println(ERROR: invalid message type: + m);
}
}
//
protected void handleMessage(ACLMessage m)
{
try {
println(Receiving broker answer);
//
if (m.getAct().eqlsIgnoreCase(MAKE-CONTRACT)) {
//
String contractId = m.getContent().toString();
//
createGroup(te,travel,contractId,null,null);
requestRole(travel,contractId,client,null);
println(Preparing contract: +contractId);
AgentAddress provider = null;
while (provider == null)
{
// ,
provider = getAgentWithRole(travel,contractId,service);
pause(100);
}
println(Asking confirmation);
pause(2000);
//
sendMessage(provider,new ACLMessage(VALIDATE));
}
//
else if (m.getAct().eqlsIgnoreCase(ACCEPT-CONTRACT))
{
println(Contract OK.);
println(Thanks. Bye.);
pause(3000);
killAgent(this);
}
//
else if (m.getAct().eqlsIgnoreCase(NO-PROVIDERS)) {
println(No providers? I see.);
println(Pardon. Bye.);
pause(3000);
killAgent(this);
}
}
//
catch (Exception msge) {
System.err.println(msge.toString());
}
}
}
5.2. -
/*
* Provider.java Travel, a simple demo application
*/
/* , :*/
import java.awt.*;
import java.net.*;
import java.io.*;
import madkit.kernel.*;
import java.util.*;
import javax.swing.*;
import madkit.lib.messages.ACLMessage;
/* , :*/
public class Provider extends Agent
{
int prix = 0;
String petence, thepoint, propstr;
JLabel message;
//
public Provider()
{
if (Math.random() > 0.5)
{
petence = train;
if (Math.random() > 0.5)
thepoint= Moscow;
else
thepoint= Warsaw;
}
else
{
petence = plane;
if (Math.random() > 0.5)
thepoint= Paris;
else
thepoint= New York;
}
if (prix == 0)
prix = (int)(Math.random() * 500 )+100;
if (petence.eqls(plane))
prix=prix*2;
}
//
public void initGUI()
{
ImageIcon ii = null;
String fileName = ;
if ((petence.eqls(train)) & (thepoint.eqls(Moscow)))
fileName = ssia.gif;
if ((petence.eqls(train)) & (thepoint.eqls(Warsaw)))
fileName = poland.gif;
if ((petence.eqls(plane)) & (thepoint.eqls(Paris)))
fileName = france.gif;
if ((petence.eqls(plane)) & (thepoint.eqls(New York)))
fileName = usa.gif;
try
{
URL url;
url = this.getClass().getResource(fileName);
ii = new ImageIcon(url);
} catch (Exception e) { e.printStackTrace(); }
JPanel p= new JPanel();
p.setLayout(new BoxLayout(p,BoxLayout.Y_AXIS));
p.add( new JLabel(Price: +prix));
if (ii!=null)
p.add( new JLabel(ii));
p.add(message = new JLabel( ));
message.setOpaque(te);
p.setSize(170,100);
message.setBackground(Color.lightGray);
setGUIObject(p);
}
//
public void activate()
{
createGroup(te,travel,travel-providers,null,null);
propstr=petence+ to +thepoint;
requestRole(travel,travel-providers,propstr+-provider,null);
display(Ticket: +propstr);
}
//
public void display(String s)
{
if (hasGUI())
message.setText(s);
else
println(s);
}
//
protected void handleMessage(ACLMessage m)
{
Color bkg=null;
if (hasGUI())
bkg=message.getBackground();
//
if (m.getAct().eqlsIgnoreCase(REQUEST-FOR-BID))
{
debug(s+m.getSender());
debug(r+m.getReceiver());
display(Sending bid);
if (hasGUI()) message.setBackground(Color.yellow);
sendMessage(m.getSender(),
new ACLMessage(BID,String.valueOf(prix)));
display(Bid sent);
if (hasGUI()) {
pause(4000);
message.setBackground(Color.lightGray);
}
display(Ticket: +petence+ to +thepoint);
}

[ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ 14 ] [ 15 ]
[ 16 ] [ 17 ] [ 18 ] [ 19 ] [ 20 ] [ 21 ] [ 22 ] [ 23 ] [ 24 ] [ 25 ] [ 26 ] [ 27 ] [ 28 ] [ 29 ] [ 30 ] [ 31 ] [ 32 ]
[ 33 ] [ 34 ] [ 35 ] [ 36 ] [ 37 ] [ 38 ] [ 39 ] [ 40 ] [ 41 ] [ 42 ] [ 43 ] [ 44 ] [ 45 ] [ 46 ] [ 47 ] [ 48 ] [ 49 ] [ 50 ]


! , . . . / , .
© 2007-2019 BPK Group.