2

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?

jlamb
  • 23
  • 3

1 Answers1

2

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

Nick Collier
  • 1,786
  • 9
  • 10
  • Thanks, Nick! I was wondering about something like this as an alternative, I'll try out an implementation like this. Is the observed behavior intended, in that the draw is – jlamb Aug 18 '20 at 22:49
  • Apologies--hit enter too early. What I meant to clarify out of curiosity: is the observed behavior of createPoissonProbabilityRepeating() intended? Does this fulfill a different purpose than createRepeating() with a random draw from a poisson passed in as an interval parameter? – jlamb Aug 18 '20 at 22:55
  • Yes. Its the intended behavior. I think this was implemented for a simulation with many agents where each agent would have its own repeating schedule that was drawn from its own poisson distribution. As you say you could implement this behavior with createRepeating as well. – Nick Collier Aug 20 '20 at 13:04