Repast Simphony:网络投影引起的运行时NullPointerException

时间:2019-12-03 16:16:14

标签: java repast-simphony

我在网络投影方面遇到Repast Simphony的麻烦。我在ContinuousSpace上以环形排列了一系列代理,每个代理都使用网络投影连接到其后继。实际上,每个代理都有一个本身开始并指向其继任者的Edge,然后又由另一个Edge指向。 代理来来去去,并且在执行模拟器时,我具有以下堆栈跟踪:

repast.simphony.ui.GUIScheduleRunner - RunTimeException when running the schedule
Current tick (20.0)
java.lang.NullPointerException
    at saf.v3d.scene.VEdge2D.update(VEdge2D.java:90)
    at repast.simphony.visualizationOGL2D.NetworkLayerOGL2D.update(NetworkLayerOGL2D.java:96)
    at repast.simphony.visualizationOGL2D.DisplayOGL2D.update(DisplayOGL2D.java:410)
    at repast.simphony.visualization.engine.DisplayComponentControllerAction$DisplayUpdater.execute(DisplayComponentControllerAction.java:48)
    at repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38)
    at repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:205)
    at repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:238)
    at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352)
    at repast.simphony.ui.GUIScheduleRunner$ScheduleLoopRunnable.run(GUIScheduleRunner.java:52)
    at java.lang.Thread.run(Thread.java:745)

有趣的事实:如果我从显示器上卸下网络投影,一切都不会失败。

这是我初始化网络和构建器中连续空间的方法:

NetworkBuilder<Object> netBuilder = new NetworkBuilder<Object>(
                "chord network", context, true);
        netBuilder.buildNetwork();

        ContinuousSpaceFactory spaceFactory = ContinuousSpaceFactoryFinder
                .createContinuousSpaceFactory(null);
        ContinuousSpace<Object> space = spaceFactory.createContinuousSpace(
                "space", context, new RandomCartesianAdder<Object>(),
                new repast.simphony.space.continuous.WrapAroundBorders(), 50,
                50);

在代码中,我以这种方式访问​​网络

Network<Object> net = (Network<Object>)context.getProjection("chord network");

最后,在代理的代码中,我以这种方式更改了边缘:

// removing the edge
if (this.edge != null)
    net.removeEdge(this.edge);

// adding a new edge
net.addEdge(this, this.successor);

有什么想法吗?

编辑: 我要模拟的是Chord,一种分布式哈希表协议。我的代理称为 Nodes ,每个节点都有一个指向其前任和后继者的指针,并且它还处理将自身指向其后继者的边缘。

在任何时刻,都会选择并删除3个随机节点。此删除是为了自愿离开节点,因此,每个节点都通过以下方式通知其继承人和前任有关离开的信息:

if (this.edge != null)
        this.net.removeEdge(this.edge);
this.successor.predecessor = this.predecessor;
if (this.predecessor != null) {
    this.predecessor.successor = this.successor;
    this.predecessor.successors = this.successors;
    if (this.predecessor.edge != null)
        this.net.removeEdge(this.predecessor.edge);
    this.predecessor.edge = this.net.addEdge(this.predecessor, this.successor);
}

然后,从上下文中删除每个删除的节点。

以类似的方式,在每个刻度上创建3个新节点。选择一个随机位置后,将节点添加到上下文中,并以这种方式添加指向其后继节点的自身边缘

// this.edge is an attribute of Node, that is a pointer to the network
this.edge = this.net.addEdge(this, this.successor);

最后,每个节点都有一系列调度的方法,这些方法在每次迭代时执行。他们检查是否有新的后继者,在这种情况下,当前边将被删除,而新边将被添加

// in case a new successor is identified
if (this.edge != null)
    this.net.removeEdge(this.edge);
this.edge = this.net.addEdge(this, this.successor);

这些都是在网络上执行的所有操作。当然,协议是在稳态下进行仿真的,因此,构建器一开始会创建具有 N 个节点和所有已校正边缘的上下文。

错误发生的时间是不确定的:有时在150个滴答声之后,有时在第5个滴答声。

0 个答案:

没有答案
相关问题