repast-simphony

Repast Simphony: Scheduling a global behavior as Poisson process with random intervals


I have a functioning model where I want to force a random agent to change state on a varying interval, modeled as a Poisson arrival process. I have set up a global behavior per the FAQ, by including a block in Build() that looks like this (where a and b are externalized in parameters.xml):

ISchedule schedule = RunEnvironment.getInstance().getCurrentSchedule();
ScheduleParameters arrival = ScheduleParameters.createPoissonProbabilityRepeating(a, b, 1);
schedule.schedule(arrival , this, "arrivalEvent");

Then I have a context method that looks like this:

public void arrivalEvent() {
    // stuff
    double tick = RunEnvironment.getInstance().getCurrentSchedule().getTickCount();
    System.out.println("New arrival on tick: " + tick);
}

This appears to work, except that it appears from the debug text to use the same value for b on all repeats. Is there a way for each repeat to use a new random draw? Or is there another (better) way to achieve this?


Solution

  • If you want b to vary each time, one way to do this is to reschedule arrivalEvent in arrivalEvent itself. The most legible way to do this is by implementing arrivalEvent as a class that implements IAction.

    public class ArrivalEvent implements IAction {
        
        private Poisson poisson;
        
        public ArrivalEvent(Poisson poisson) {
            this.poisson = poisson;
        }
        
        public void execute() {
            // execute whatever the actual arrival event is
            
            
            // reschedule
            double next = poisson.nextDouble() + RunEnvironment.getInstance().getCurrentSchedule().getTickCount();
            RunEnvironment.getInstance().getCurrentSchedule().schedule(ScheduleParameters.createOneTime(next, 1), this);
        }
    }
    

    And schedule it for the first time with something like

    Poisson poisson = RandomHelper.getPoisson();
    double next = poisson.nextDouble();
    RunEnvironment.getInstance().getCurrentSchedule().schedule(ScheduleParameters.createOneTime(next, 1), new ArrivalEvent(poisson));
    

    Nick