EEL 5937 The Bond Agent System (3) EEL 5937 Multi Agent Systems Lecture 17, March. 4, 2003 Lotzi...
-
Upload
martina-snow -
Category
Documents
-
view
219 -
download
0
Transcript of EEL 5937 The Bond Agent System (3) EEL 5937 Multi Agent Systems Lecture 17, March. 4, 2003 Lotzi...
EEL 5937
The Bond Agent System(3)
EEL 5937 Multi Agent Systems
Lecture 17, March. 4, 2003
Lotzi Bölöni
EEL 5937
Review of the homework
• Generally, speaking, those who submitted, solved the problem.
• Let’s see a typical solution. • Both the judge and the prisoner needs one
active strategy. You might want to add extra states (e.g. for waiting, error handling etc.).
EEL 5937
Blueprint for the Judge
createPlane("JudgePlane")
import homework
s = homework.JudgeStrategy(agent)
addFirstState(s, "Judge")
s = bond.strategydb.WaitAndTransitionStrategy(agent, 5000, SUCCESS)
addState(s, "Wait")
addTransition('Judge', 'Wait‘, SUCCESS)
addTransition('Wait', 'Judge', SUCCESS)
EEL 5937
Blueprint for the prisoner Prisoner.py
import homework
createPlane(“PrisonerPlane")
s = homework.PrisonerStrategy(agent, 0)
addFirstState(s, "Prisoner")
s = bond.strategydb.WaitAndTransitionStrategy(agent, 5000, SUCCESS)
addState(s, "Wait")
addTransition('Prisoner', 'Wait',SUCCESS)
addTransition('Wait', 'Prisoner', SUCCESS)
EEL 5937
Judge strategypackage homework;
import bond.agent.BondAgent;
import bond.agent.strategy.Strategy;
import bond.util.fsm.FSM;
import bond.util.fsm.FSMException;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import jade.core.AID;
public class JudgeStrategy extends Strategy {
private FSM judgeFSM;
private String[] prisoners; // list of prisoners
private String[] responses; // list of responses by prisoners
private String[] judgement; //judgement for prisoners
private final String QUESTION =
"Do you confess for this crime?";
private final String CONFESS = "Confess";
private final String NOT_CONFESS = "Not Confess";
EEL 5937
Judge strategypublic JudgeStrategy(BondAgent a) {
super(a);
String states[] = {
"AskPrisoners",
"GetResponseFromPrisoners",
"makeJudgement",
"sendVerdict",
};
judgeFSM = new FSM("Judge",states);
judgeFSM.addTransition("AskPrisoners",
"GetResponseFromPrisoners");
judgeFSM.addTransition("GetResponseFromPrisoners",
"makeJudgement");
judgeFSM.addTransition("makeJudgement","sendVerdict");
}
EEL 5937
Judge strategypublic void action() {
if (judgeFSM.stateIs("AskPrisoners")) {
askPrisoners(); // Send questions to prisoners
}
if (judgeFSM.stateIs("GetResponseFromPrisoners")) {
getResponseFromPrisoners();
// Wait for response from prisoners
}
if (judgeFSM.stateIs("makeJudgement")) {
makeJudgement(); // Given the responses, make a judgement
}
if (judgeFSM.stateIs("sendVerdict")) {
sendVerdict(); // Send verdict to respective prisoners
}
}
EEL 5937
Judge strategy – asking the prisoners
private void askPrisoners() throws FSMException {
ACLMessage question = new ACLMessage(ACLMessage.REQUEST);
question.setSender(theAgent.getAID());
question.addReceiver(new AID(prisoners[0],false));
question.addReceiver(new AID(prisoners[1],false));
question.setContent(QUESTION);
theAgent.send(question);
judgeFSM.setState("GetResponseFromPrisoners");
}
EEL 5937
Judge strategy – wait for responses
private void getResponseFromPrisoners() throws FSMException {
MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.AGREE);
mt = MessageTemplate.or(MessageTemplate.MatchPerformative(ACLMessage.REFUSE), mt);
ACLMessage response = theAgent.receive(mt);
if (response == null) { block(500); return; }
for (int i=0; i<prisoners.length; i++) {
if (response.getSender().getLocalName().equalsIgnoreCase(prisoners[i])) {
if (response.getPerformative() == ACLMessage.AGREE) {
responses[i] = CONFESS;
} else if (response.getPerformative() == ACLMessage.REFUSE) {
responses[i] = NOT_CONFESS;
}
break;
} // end if
} // end for
} // end if (mt == null) ... else
if (responses[0] != null && responses[1] != null) {
judgeFSM.setState("makeJudgement");
}
} // end getResponseFromPrisoners
EEL 5937
Judge strategy – making the judgement
private void makeJudgement() throws FSMException { judgement = new String[2]; if (responses[0].equalsIgnoreCase(CONFESS) &&
responses[1].equalsIgnoreCase(CONFESS)) { judgement[0] = "You have been jailed for 2 years"; judgement[1] = "You have been jailed for 2 years"; } else if (responses[0].equalsIgnoreCase(NOT_CONFESS) &&
responses[1].equalsIgnoreCase(NOT_CONFESS)) { judgement[0] = "You have been jailed for 1 year"; judgement[1] = "You have been jailed for 1 year"; } else { if (responses[0].equalsIgnoreCase(CONFESS)) { judgement[0] = "You are free !!!"; judgement[1] = "You are jailed for 3 years. Bad Luck!!!"; } else { judgement[1] = "You are free !!!"; judgement[0] = "You are jailed for 3 years. Bad Luck!!!"; } } judgeFSM.setState("sendVerdict"); }
EEL 5937
Judge strategy – sending the verdict
private void sendVerdict() throws FSMException {
for (int i=0; i<prisoners.length;i++) {
ACLMessage inform = new ACLMessage(ACLMessage.INFORM);
inform.setSender(theAgent.getAID());
inform.addReceiver(new AID(prisoners[i],false));
inform.setContent(judgement[i]);
theAgent.send(inform);
}
judgeFSM.setState("ReceiveCase");
}
EEL 5937
Handling user interfaces
• There are two choices here• (A) Integrate the GUI with the strategy.
Create an external class with the user interface, inherit it from JFrame, and directly point to it from the strategy.– Advantage: simple, you have direct access– Disadvantage: difficult – Example: bond/applications/prisoners_dilemma/simple
• (B) Create a separate user interface, as a separate strategy.– Advantage: separation of UI and functionality. Agents
can be assembled, modified. – Disadvantage: more complex interaction, through the
agent state.– Example:
bond/applications/prisoners_dilemma/separateui
EEL 5937
Bootstrapping a multi-agent system
EEL 5937
Bootstrapping multi-agent systems
• Creating a set of agents which will act in a coalition.– In practical deployments, only agents working on behalf
a single user are started like this.
• All the projects can be seen as examples of this.– Even if some of the agents in the projects are in
adversarial relations.
• It can be done:– By hand using the Jade Remote Agent Manager.– By a bootstrapping agent.
EEL 5937
Bootstrapping agent.
• A bootstrap agent– Bootstrap.py (see example in the prisoners dilemma
directory)– Takes a bootstrap file as input. – Starts the agents described (potentially on multiple
machines)– Terminates.
• The format of the bootstrap file:<host> <blueprint file> <agent name>
• Example bootstrap file:
localhost bond\applications\prisoners_dilemma\simple\Judge.py Judge
localhost bond\applications\prisoners_dilemma\simple\Prisoner1.py Prisoner1
localhost bond\applications\prisoners_dilemma\simple\Prisoner1.py Prisoner2
EEL 5937
Basic strategies.Strategy database
EEL 5937
Strategy Database
• Contains a collection of general purpose strategies.
• Promotes code reuse.
• Utility strategies – Running applications
• System strategies– Running applications, running scripts– Transfering files (FTP etc)– Mail, Http
• Agent manipulation– Remotely starting, stopping agents, etc.
• Agent protocol implementation– Question/Reply– Contract net, auctions, etc.
EEL 5937
Utility strategies: WaitAndTransitionStrateg
y• Usage:
– addState(WaitAndTransitionStrategy())– addState(WaitAndTransitionStrategy(5000, SUCCESS))
• Functionality:– Waits for the specified number of milliseconds than
performs the transition specified.
• Transition:– The transition specified (SUCCESS by default)
EEL 5937
Utility strategies: DummyStrategy
• Usage:– addState(DummyStrategy())
• Functionality:– Blocks indefinitely. (Used for debugging)
• Transition:– None.
EEL 5937
Utility strategies:ShowMessageStrategy,
ShowErrorStrategy• Usage:
– addState(ShowMessageStrategy(“Message”))– addState(ShowMessageStrategy(“ErrorMessage”))
• Functionality:– Shows a message / error message in a dialog box.
Transitions when the user clicks on the button.
• Transition:– SUCCESS
EEL 5937
Utility strategies: ChoiceStrategy
• Usage:– addState(ChoiceStrategy(“Proceed?”))
• Functionality:– Shows a dialog with the message with two buttons.
• Transition:– SUCCESS if the Yes button is pressed.– FAILURE if the No button is pressed.
EEL 5937
Utility strategies: ExitAgentStrategy
• Usage:– addState(ExitAgentStrategy())
• Functionality:– Terminates the agent by calling doDelete().
• Transition:– None (the agent will be terminated).