Discussion:
[jade-develop] Executing big tasks in a agent with ContractNet
Gustavo
2014-09-17 18:36:22 UTC
Permalink
Hi all, I'm new in Jade world and I'm trying to do simple things at time to
learn how to use this incredible tool, but information on the Internet are
scarce.

My problem is how to execute a relative big task without locking the agent.

I started using as reference the examples from Jade:
ContractNetInitiatorAgent.java and ContractNetResponderAgent.java.
In that examples, everything works well even with my code, but, when I put a
real task in the method performAction() of the Responder, the agent gets
frozen during the execution of this task.

In my code, the Initiator searches the service in the DF, after that send a
CFP to the specific Responder, gets a propose and accept, the Responder
executes the task (in 20 seconds because this is the task) and send a
Inform. Perfect, except for the second Initiator also wants the same
service.
When the second Initiator send a CFP and the Responder is busy, there is no
communication. The Responder does not respond.

What I'm trying to do, without success, is transform the method
performAction() in a TickerBehaviour, so, the communication is not blocked
and after the action is performed, the Responder sends the final Inform with
task concluded.
In my code I got the task finished (the handleAcceptProposal calls the
Ticker action) but I can not send the final Inform, because after the
ContractNet executes the handleAcceptProposal I can't execute it again. I
tried to force the handleAcceptProposal execution inside performAction()
using forceTransitionTo and setExecutionState.

This is a good approach? What is wrong?
Or the best way is to allow the performAction() to get the Responder agent
stucked for the needed time?
There is other way(s) to not lock the agent, i.e., even the Responder is
working it can reply other messages?

Thanks in advance



--
View this message in context: http://jade.17737.x6.nabble.com/Executing-big-tasks-in-a-agent-with-ContractNet-tp5002729.html
Sent from the JADE - Dev mailing list archive at Nabble.com.
Gustavo
2014-10-07 18:10:18 UTC
Permalink
Hi there,
The way I found to solve the problem of agent blocked inside performAction()
is to create a new behaviour (TickerBehaviour) and break the action in many
parts.
So, the ContracNet communication is used ONLY to search and firm a contract
between the Initiator and Responder. After the "agreement" the proccess of
ContractNet is ended, and inside performAction() the work is executaded in
many parts as nedded and after that a message with a special code (DONE) is
sent. During the execution of the action, the Responder doesn't get blocked
anymore and it responds a CFP with REFUSE.
This approach is working well.

Regards



--
View this message in context: http://jade.17737.x6.nabble.com/Executing-big-tasks-in-a-agent-with-ContractNet-tp5002729p5002741.html
Sent from the JADE - Dev mailing list archive at Nabble.com.
Caire Giovanni
2014-10-09 15:51:14 UTC
Permalink
Hi,

Another (possibly simpler) option is to exploit a single-session (SS) responder in combination with threaded behaviours as below

Bye,

Giovanni


private ThreadedBehaviourFactory tbf = new ThreadedBehaviourFactory();
private boolean busy = false;
...
public void setup() {
...
MessageTemplate tpl = create a suitable MessageTemplate to receive CFP messages
addBehaviour(new SSResponderDispatcher(this, tpl) {
public Behaviour createResponder(ACLMessage cfp) {
if (busy) {
// I'm busy --> send back a REFUSE
ACLMessage refuse = cfp.createReply();
refuse.setPerformative(ACLMessage.REFUSE);
myAgent.send(refuse);
return null;
}
else {
// I'm not busy --> Start a single-session contract-net responder
// as a Threaded behavior to execute the long task in a dedicated thread
busy = true;
return tbf.wrap(createSSContractNetResponder(cfp));
}
}
});
....
}

private SSContractNetResponder(ACLMessage cfp) {
return new SSContractNetResponder(cfp) {
protected ACLMessage handleCfp(ACLMessage cfp) throws RefuseException, FailureException, NotUnderstoodException {
...
}
protected ACLMessage handleAcceptProposal(ACLMessage cfp, ACLMessage propose, ACLMessage accept) throws FailureException {
...
}

public int onEnd() {
// When done, reset the busy flag
busy = false;
}
};
}


-----Messaggio originale-----
Da: jade-develop [mailto:jade-develop-bounces at avalon.tilab.com] Per conto di Gustavo
Inviato: martedì 7 ottobre 2014 20:10
A: jade-develop at avalon.tilab.com
Oggetto: Re: [jade-develop] Executing big tasks in a agent with ContractNet

Hi there,
The way I found to solve the problem of agent blocked inside performAction() is to create a new behaviour (TickerBehaviour) and break the action in many parts.
So, the ContracNet communication is used ONLY to search and firm a contract between the Initiator and Responder. After the "agreement" the proccess of ContractNet is ended, and inside performAction() the work is executaded in many parts as nedded and after that a message with a special code (DONE) is sent. During the execution of the action, the Responder doesn't get blocked anymore and it responds a CFP with REFUSE.
This approach is working well.

Regards



--
View this message in context: http://jade.17737.x6.nabble.com/Executing-big-tasks-in-a-agent-with-ContractNet-tp5002729p5002741.html
Sent from the JADE - Dev mailing list archive at Nabble.com.
_______________________________________________
jade-develop mailing list
jade-develop at avalon.tilab.com
http://jade.tilab.com/mailman/listinfo/jade-develop
UNSUBSCRIBE INSTRUCTIONS AT
http://jade.tilab.com/community-mailinglist.htm

Loading...