Discussion:
[jade-develop] Simplebehaviour for checking time lived of agent
Merrick Bengis
2014-06-23 10:11:25 UTC
Permalink
Hi Giovanni,

I don't know whether you received my previous email as i received no
response, so i am sending it again bellow:

thank you, i was unsure whether the onEnd would work the same for the
Tickerbehaviour as with the other behaviours.

I have now created my FSMBehaviour with a Parallelbehaviour as the first
state. The parallelbehaviour has 2 sub behaviours, namely: a
tickerbehaviour to do a comparison every X ms, and a simple behaviour that
i am using to keep track of the time lived for the agent (how many ms have
passed since it was created). The point of the simple behaviour is to check
for when an agent has "lived" for a certain amount of time without getting
a useful result out of the tickerbehaviours comparison. Once the agent has
been alive for too long the fsmbehaviour should transition to another state
which will spawn a replacement agent and then terminate the current one.

I am having problems in that it appears that the simplebehaviour only runs
the time lived check once even though it cannot possible have met the
done() methods requirements yet. Is there any reason why this is happening?
As far as i understand a simple behaviour can be used to perform a task
until a result specified in the done() method is reached and returns.

my simplebehaviour looks like this:

public class LivedChecker extends SimpleBehaviour{
public long startTime;
public long estimatedTime;
String AgentString;

public LivedChecker(DetectorAgent agent)
{
AgentString = agent.DetectorString;
startTime = System.nanoTime();
}

public LivedChecker(KillerAgent agent)
{
AgentString = agent.KillerString;
startTime = System.nanoTime();
}

@Override
public void action()
{
System.out.println("In Lived Checking!!! Agent: " + AgentString);
estimatedTime = System.nanoTime() - startTime;
}

@Override
public boolean done()
{
return estimatedTime >= 30000;
}
}

once the agent has been alive for 30 seconds i want it to return so that
the fsmbehaviour can transition state.

Regards,
Merrick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://avalon.cselt.it/pipermail/jade-develop/attachments/20140623/7154fc2c/attachment.html>
Loading...