Quantcast

Question about terminating a simulation model JZombies

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Question about terminating a simulation model JZombies

Carlos Bahamonde Reyes
Dear all,

I would like to ask a question about how to make the JZombies model a terminating simulation. I have followed the guide "RepastBatchRunsGettingStarted" and in it is pointed out that in order to reach this goal the following line codes should be written:

if (context.getObjects(Human.class).size() == 0) {
RunEnvironment.getInstance().endRun();

The guide also point out "Something like this could be scheduled to execute once every tick either manually or via a scheduled method on the context builder."

But I really don't know how to do this last. I have tried to put the aforementioned lines just above the "return context", like this:

@ScheduledMethod (start = 1 , interval = 1,  priority = 0)
public void stop{
if (context.getObjects(Human.class).size() == 0) {
        RunEnvironment.getInstance().endRun();         
}
}
return context;

But I got the error "void is an invalid type for the variable stop". So I haven't had success in my tries. Could you please give me some hint about this please?

Thank you in advance,

Kind regards,

--
Carlos R. Bahamonde Reyes
Ingeniero Civil Electrónico
Universidad de Concepción

------------------------------------------------------------------------------

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about terminating a simulation model JZombies

Tatara, Eric R.
Carlos,

The error you report is due to syntax problems in the stop method.  Please use a stop method like this:

@ScheduledMethod(start=1, interval=1, pick=1, priority=ScheduleParameters.LAST_PRIORITY)
    public void stop(){
        Context c = ContextUtils.getContext(this);
   
        if (c.getObjects(Human.class).size() == 0){
            RunEnvironment.getInstance().endRun();
        }
       
    }

Additionally, you will need to place the stop method in an agent class, not the ContextBuilder since the @ScheduleMethod annotations are only valid in agent classes.

There are a few modeling considerations around the execution of the stop method.  First, I also provided a "pick=1" argument which limits the execution to only a single agent which will reduce unnecessary calculations, since the result would be the same if only a single agent does the check.  Second, you will need to place this stop method in the Zombie class because once all the Humans are killed in the simulation, there will be no more Humans left to perform the check.  If you are adapting this behavior for another model, the stop condition check should be in a simulation agent that you know will always exist in the context.   A common approach is to use a single "observer" agent in your model to performs checks or set model conditions based on population attributes.


Eric Tatara, PhD, PE
Software Engineer
Global Security Sciences Division
Argonne National Laboratory

From: Carlos Bahamonde Reyes [[hidden email]]
Sent: Monday, August 01, 2016 5:40 AM
To: [hidden email]
Subject: [Repast-interest] Question about terminating a simulation model JZombies

Dear all,

I would like to ask a question about how to make the JZombies model a terminating simulation. I have followed the guide "RepastBatchRunsGettingStarted" and in it is pointed out that in order to reach this goal the following line codes should be written:

if (context.getObjects(Human.class).size() == 0) {
RunEnvironment.getInstance().endRun();

The guide also point out "Something like this could be scheduled to execute once every tick either manually or via a scheduled method on the context builder."

But I really don't know how to do this last. I have tried to put the aforementioned lines just above the "return context", like this:

@ScheduledMethod (start = 1 , interval = 1,  priority = 0)
public void stop{
if (context.getObjects(Human.class).size() == 0) {
        RunEnvironment.getInstance().endRun();         
}
}
return context;

But I got the error "void is an invalid type for the variable stop". So I haven't had success in my tries. Could you please give me some hint about this please?

Thank you in advance,

Kind regards,

--
Carlos R. Bahamonde Reyes
Ingeniero Civil Electrónico
Universidad de Concepción

------------------------------------------------------------------------------

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Loading...