Repast Simphony:以随机间隔将全局行为安排为Poisson过程

问题描述

我有一个正常运行的模型,在该模型中,我想强制随机代理以可变的间隔更改状态,并以Poisson到达过程为模型。我在FAQ中设置了全局行为,方法是在Build()中添加一个如下所示的块(其中 a b 在parameter.xml中被外部化):

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

然后我有一个如下所示的上下文方法

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

这似乎可行,除了它在调试文本中显示为在所有重复上对 b 使用相同的值。有没有一种方法可以让每个重复使用新的随机抽奖?还是有另一种(更好)的方法来实现这一目标?

解决方法

如果您希望b每次都变化,那么做到这一点的一种方法是在到达事件本身中重新计划到达事件。最清晰的方法是通过将arrivalEvent实现为实现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);
    }
}

并使用类似的方式首次安排它

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

尼克