ֲͲ ò ² Ͳֲ

[ 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 ]

 

//
else if (m.getAct().eqlsIgnoreCase(MAKE-CONTRACT))
{
String group = m.getContent().toString();
display(Received offer: +group);
if (hasGUI()) message.setBackground(Color.green);
/*
/ */
createGroup(te,travel,group,null,null);
requestRole(travel,group,service,null);
}
//
else if (m.getAct().eqlsIgnoreCase(VALIDATE)){
display(Validating contract OK);
if (hasGUI()) message.setBackground(Color.magenta);
sendMessage(m.getSender(),
new ACLMessage(ACCEPT-CONTRACT));
if (hasGUI()) {
pause(4000);
message.setBackground(Color.lightGray);
}
display(Ticket: +petence+ to +thepoint);
}
}
//
public void live()
{
//
while (te) {
Message m = waitNextMessage();
if (m instanceof ACLMessage)
handleMessage((ACLMessage)m);
}
}
}
5.3. -
/*
* Broker.java Travel, a simple demo application
*/
/* , :*/
import madkit.kernel.*;
import madkit.lib.graphics.*;
import madkit.lib.messages.ACLMessage;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
/* ; . */
class BidAnswer {
AgentAddress bidder;
int value;
BidAnswer(AgentAddress b, int v){bidder = b; value = v;}
int getValue(){return value;}
AgentAddress getBidder(){return bidder;}
}
/* , :*/
public class Broker extends Agent implements ActionListener
{
//
Vector bidders = new Vector();
BidAnswer[] answers;
int contract = 0;
String contractID=;
String kernelID=;
JButton b;
int cpt=0;
AgentAddress client;
boolean pause = false;
public void enterPause()
{
pause = te;
b.setBackground(Color.red);
b.repaint();
while (pause)
pause(200);
}
//
public void initGUI()
{
JPanel p = new JPanel(new BorderLayout());
OPanel o = new OPanel();
p.add(Center,o);
b = new JButton(Next step);
b.addActionListener(this);
p.add(South,b);
setGUIObject(p);
setOutputWriter(o.getOut());
}
public void actionPerformed(ActionEvent e)
{
pause=false;
b.setBackground(Color.gray);
}
//
public void activate()
{
println(Broker ready);
// 䒺
createGroup(te,travel,travel-providers,null,null);
createGroup(te,travel,travel-clients,null,null);
requestRole(travel,travel-providers, broker,null);
requestRole(travel,travel-clients, broker,null);
/* ( ) */
kernelID=new String(getAddress().getKernel().toString());
}
//
public void handleMessage(ACLMessage m)
{ String product=null;
// 볺
if (m.getAct().eqlsIgnoreCase(REQUEST)){
println(Receiving client request);
enterPause();
product = m.getContent().toString();
client = m.getSender();
// ³
AgentAddress[] bidders=getAgentsWithRole(travel,travel-providers, product+-provider);
/* ; 볺 . */
if (bidders.length==0){
println(Not found providers of + product);
sendMessage(client, new ACLMessage(NO-PROVIDERS));
return;
}
println (Found providers of +product);
cpt = bidders.length;
answers = new BidAnswer[cpt];
println (Transmitting requests...);
//
ACLMessage req=new ACLMessage(REQUEST-FOR-BID,
product);
// ³
broadcastMessage(travel,travel-providers, product+-provider,req);
println (Waiting for offers..);
}
//
else if (m.getAct().eqlsIgnoreCase(BID)){
receiveBid(m);
}
}

  1. //

public void live()
{
//
while (te)
{
Message m = waitNextMessage();
//
if (m instanceof ACLMessage)
handleMessage((ACLMessage)m);
else
System.err.println(ERROR: invalid message type: + m);
}
}
//
protected void receiveBid(ACLMessage m){
println(Received an offer of + m.getContent() + from + m.getSender());
cpt--;
answers[cpt]=new BidAnswer(m.getSender(),((Integer) new Integer
(m.getContent().toString())).intValue());
if (cpt <= 0)
bestContract();
}
// ( )
void bestContract()
{
AgentAddress best = null;
int bestoffer;
println(Selecting best offer from + answers.length + proposals);
enterPause();
bestoffer=answers[0].getValue();
best=answers[0].getBidder();
for (int i=0;i<answers.length;i++){
println(:: best: + bestoffer+, value: + answers[i].getValue());
if (answers[i].getValue() < bestoffer) {
best=answers[i].getBidder();
bestoffer=answers[i].getValue();
}
}
if (best != null)
{
println(Chosen provider:+best);
println( avec +bestoffer+ F);
//
contract++;
contractID= # +contract+ th Broker +new String(get
Address().getLocalID().toString())+ at +kernelID;
println(Contract+contractID);
println(Sending provider confirmation);
enterPause();
//
sendMessage(best,
new ACLMessage(MAKE-CONTRACT,contract-+contractID));
pause(100);
// 볺
println(Sending client confirmation);
enterPause();
sendMessage(client,
new ACLMessage(MAKE-CONTRACT,contract-+contractID));
}
}
}
5.4.
.java <Madkit>/tutorial/<MyAgents>. , .gif. Madkit , .jar. MS-DOS (.bat):
rem Java
javac -classpath..\..\libs\madkit\madkit.jar *.java
rem .jar
jar cf diftravelagents.jar *.class *.gif
rem Madkit
copy diftravelagents.jar..\..\autoload
5.5.
ϳ MadKit (. 6.5).

. 6.5. 볺
. 6.6 .
municator (Agents>municator) IP , (. 6.7). , , , municator.

. 6.6.

. 6.7.

travel , , (. 6.8).

. 6.8. ϳ
. 6.9 , 䒺 , , .

. 6.9.


6.4.

    • ?
    • .
    • ?
    • 㳿 ?
    • .
    • MadKit.
    • activate().
    • end().
    • Agent .
    • , ?

[ 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.