Discussion:
[jade-develop] Passing parameters from Behavior to Agent
christinne
2014-06-16 21:06:15 UTC
Permalink
Hi all,

I have a simple agent class AgentA and in the setup method I add a
BehaviourA that extends a OneShotBehaviour. In the behaviour class I have a
private variable int X=0, and a method (changeParam) that makes this
variable from 0 to 1. I would like to know if there is a way in witch I can
pass this parameter from this behaviour class into the setup method (from
where I add this behaviour).

This is a simplified logic of what I tried to do, but without success.
But I have noticed that in the setup method , after adding the behaviour and
getting the 'count' variable with value = 0 , somehow the behavior method is
executed but I didn't understand in which direction, what is the flow
between setup method and behaviour methods. Can someone please clarify also
this for me?

Thank you


public class Nucleus extends Agent {
public int count = 0;

protected void setup() {
// ..
LookForObjectives behavLookForObjective = new
LookForObjectives(this, count);
this.addBehaviour(behavLookForObjective);
this.count = behavLookForObjective.getObj(); // < --- what I
want is that in this point the variable this.count = to be equal to 1 but
is 0
// ...
}
}

public class LookForObjectives extends OneShotBehaviour {
private int obj = 0;
private int received_obj = 0;

public LookForObjectives(Nucleus param0, int param1) {
super(param0);
this.received_obj = param1;
}

public changeParam (int nr){
if (nr ==0) nr = 1;
return nr;
}

public void action() {
obj = changeParam(received_obj);
}

public int getObj(){
return this.obj;
}
}




--
View this message in context: http://jade.17737.x6.nabble.com/Passing-parameters-from-Behavior-to-Agent-tp5002613.html
Sent from the JADE - Dev mailing list archive at Nabble.com.
Caire Giovanni
2014-06-17 07:23:43 UTC
Permalink
Hi,

In general a behaviour can access agent variables since each behaviour holds a reference to the executing agent in the "myAgent" protected variable -->Your behaviour can easily set a variable in the agent with the value of its internal X parameter.
However take into account that behavior execution starts AFTER the setup() method completes --> There is no way a behavior can set an agent variable while the setup() method is in execution.

Bye,

Giovanni

-----Messaggio originale-----
Da: jade-develop-bounces at avalon.tilab.com [mailto:jade-develop-bounces at avalon.tilab.com] Per conto di christinne
Inviato: luned? 16 giugno 2014 23:06
A: jade-develop at avalon.tilab.com
Oggetto: [jade-develop] Passing parameters from Behavior to Agent

Hi all,

I have a simple agent class AgentA and in the setup method I add a BehaviourA that extends a OneShotBehaviour. In the behaviour class I have a private variable int X=0, and a method (changeParam) that makes this variable from 0 to 1. I would like to know if there is a way in witch I can pass this parameter from this behaviour class into the setup method (from where I add this behaviour).

This is a simplified logic of what I tried to do, but without success.
But I have noticed that in the setup method , after adding the behaviour and getting the 'count' variable with value = 0 , somehow the behavior method is executed but I didn't understand in which direction, what is the flow between setup method and behaviour methods. Can someone please clarify also this for me?

Thank you


public class Nucleus extends Agent {
public int count = 0;

protected void setup() {
// ..
LookForObjectives behavLookForObjective = new LookForObjectives(this, count);
this.addBehaviour(behavLookForObjective);
this.count = behavLookForObjective.getObj(); // < --- what I
want is that in this point the variable this.count = to be equal to 1 but is 0
// ...
}
}

public class LookForObjectives extends OneShotBehaviour {
private int obj = 0;
private int received_obj = 0;

public LookForObjectives(Nucleus param0, int param1) {
super(param0);
this.received_obj = param1;
}

public changeParam (int nr){
if (nr ==0) nr = 1;
return nr;
}

public void action() {
obj = changeParam(received_obj);
}

public int getObj(){
return this.obj;
}
}




--
View this message in context: http://jade.17737.x6.nabble.com/Passing-parameters-from-Behavior-to-Agent-tp5002613.html
Sent from the JADE - Dev mailing list archive at Nabble.com.
_______________________________________________
jade-develop mailing list
jade-develop at avalon.tilab.com
https://avalon.cselt.it/mailman/listinfo/jade-develop
UNSUBSCRIBE INSTRUCTIONS AT
http://jade.tilab.com/community-mailinglist.htm
christinne
2014-06-17 09:02:27 UTC
Permalink
Thank you for your quick response. So, then where I should add my behaviour
in order to change the agent's parameter? Is there another way , another
method in which I can do somethings like this?
From what I have read, I have seen that in all cases the behavior is added
in the setup method like below:

public class MyAgent extends Agent {
protected void setup() {
System.out.println(?Adding waker behaviour?);
addBehaviour(new WakerBehaviour(this, 10000) {
protected void handleElapsedTimeout() {
// perform operation X
}
} );
}
}




--
View this message in context: http://jade.17737.x6.nabble.com/Passing-parameters-from-Behavior-to-Agent-tp5002613p5002615.html
Sent from the JADE - Dev mailing list archive at Nabble.com.
Caire Giovanni
2014-06-18 07:40:40 UTC
Permalink
Hi,

As I said, the behaviour can change whatever variable of the agent. Just remember that behavior scheduling starts after the setup() method completes. Note that, as the name suggests, the setup() method is intended to perform agent initializations. All logics to be executed by the agent during its "normal" lifetime should be embedded into behaviours. As soon as behavior1 changes a variable of the agent, all other behaviours will get the new variable values.
Note also that, since all behaviours are executed in the agent thread, you don't have to care about synchronization issues when 2 or more behaviours access the same agent variable.

Bye,

Giovanni

-----Messaggio originale-----
Da: jade-develop-bounces at avalon.tilab.com [mailto:jade-develop-bounces at avalon.tilab.com] Per conto di christinne
Inviato: marted? 17 giugno 2014 11:02
A: jade-develop at avalon.tilab.com
Oggetto: Re: [jade-develop] R: Passing parameters from Behavior to Agent

Thank you for your quick response. So, then where I should add my behaviour in order to change the agent's parameter? Is there another way , another method in which I can do somethings like this?

From what I have read, I have seen that in all cases the behavior is added in the setup method like below:

public class MyAgent extends Agent {
protected void setup() {
System.out.println(?Adding waker behaviour?);
addBehaviour(new WakerBehaviour(this, 10000) {
protected void handleElapsedTimeout() {
// perform operation X
}
} );
}
}




--
View this message in context: http://jade.17737.x6.nabble.com/Passing-parameters-from-Behavior-to-Agent-tp5002613p5002615.html
Sent from the JADE - Dev mailing list archive at Nabble.com.
_______________________________________________
jade-develop mailing list
jade-develop at avalon.tilab.com
https://avalon.cselt.it/mailman/listinfo/jade-develop
UNSUBSCRIBE INSTRUCTIONS AT
http://jade.tilab.com/community-mailinglist.htm
christinne
2014-06-18 08:03:56 UTC
Permalink
Thank you. I actually understood how I can resolve my problem. :)



--
View this message in context: http://jade.17737.x6.nabble.com/Passing-parameters-from-Behavior-to-Agent-tp5002613p5002617.html
Sent from the JADE - Dev mailing list archive at Nabble.com.

Continue reading on narkive:
Loading...