我在简单的上下文(地理包)中有一个简单的代理,它使用纬度和经度来表示空间。代理应该在模型的第 10 次迭代时死亡。然后将其从上下文中删除。在模拟的第 10 次迭代中,代理停止执行其他方法(例如四处移动),因此我假设它已成功从上下文中删除/死亡,但它不会从模拟显示中删除(只是坐在那里) )。
为什么它会保留在显示屏中?当它消失时如何将其从显示屏上删除?
更新:就餐显示代码中存在错误。您可以通过 repast-interest@lists.sourceforge.net 联系 Eric Tatara 获取修复文件,但所有错误都将在下一个发行版本中删除。
public class Agent {
public Geography<Object> geography;
public Context<Object> context;
public int id;
public Agent (Context<Object>context, Geography<Object>geography) {
this.geography= geography;
this.context=context;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@ScheduledMethod(start = 1, pick = 1, interval = 1)
public void otherMethods() {
}
@ScheduledMethod(start = 10, pick = 1, interval = 1)
public void die() {
Context context = ContextUtils.getContext(this);
context.remove(this);
}
}
最佳答案
您需要从die()
中的地理位置中删除您的代理。我认为是方法。
在 repast code that handles removing agents from the display ,删除是由 Projection
中的事件触发的与显示器关联的对象 - 在您的情况下为 Geography
。奇怪的是,Geography
接口(interface)未定义remove()
方法,但其中一个是在 DefaultGeography
中实现的类(class)。很可能您的Geography
实际上是一个DefaultGeography
具体对象,因此您可以尝试将以下内容添加到您的 die()
中方法:
@ScheduledMethod(start = 10, pick = 1, interval = 1)
public void die() {
Context context = ContextUtils.getContext(this);
context.remove(this);
((DefaultGeography) geography).remove(this);
}
注释
- 您正在
die()
中获取上下文方法,但是已经有了 当您构建Agent
时对它的引用,所以这是 几乎肯定是多余的。 - 您需要确保您的显示确实已安排更新。默认情况下它们是,但您应该双击 GUI 左侧导航器 Pane 中的显示并检查
Schedule Details
选项卡以确保显示定期更新(不是ONE_TIME
)
关于java - 对象从上下文中删除,但未从显示中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28620594/