在人口中寻找任何logic,并访问其变量之一
我想找到我的经纪人对其人口的指数(名为Dullieses),它生活在我的主体中。
我想通过其变量之一(dullyid)找到我的dellieses-gent之一,在此示例中,它应等于我的计数器变量。两者都是Int类型。
我已经尝试了以下内容:
int i = 0;
for ( i = 0; i < dullieses.size(); i++){
if (Main.dullieses(i).DullyID == counter){
traceln("I found myself! I have the index " + i);
break;
}
}
错误代码:无法静态引用MAIN类型的非静态方法Dullies(INT)。
我如何在人群中找到我的代理商并找到其指数?
I want to find the index my agent has in its population (named dullieses), which lives in my Main-agent.
I want to find one of my dullieses-agent via one of its variables (DullyID) which, in this example, shall be equal to my counter variable. Both are of type int.
I have tried the following to no avail:
int i = 0;
for ( i = 0; i < dullieses.size(); i++){
if (Main.dullieses(i).DullyID == counter){
traceln("I found myself! I have the index " + i);
break;
}
}
Error code: Cannot make a static reference to the non-static method dullies(int) from type Main.
How can I find my agent in my population and find its index?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无需在代理中使用自定义ID参数(至少不是在这里做的事情)。
人群中的所有代理都有
getIndex
功能,该功能返回人口中的索引。只要警惕,如果您将代理从人口中删除,他们的索引将会改变(例如,在这种情况下,您不能将其索引用作唯一的ID)。You don't need to use a custom ID parameter in your agents (at least not for what you're doing here).
All agents in a population have the
getIndex
function which returns their index in the population. Just be wary that, if you remove agents from a population, their indices will change (so you can't, for example, use their index as a unique ID for them in that case).我认为您可能已经在Main中,并且不需要添加
main。
。无论如何,我建议使用:
我使用变量和10个随机示例,但这应该给您这个想法。还将
dully
替换为代理类型名称。I think you're probably already in main and don't need to add
Main.
.Anyway, I would recommend using:
I used variable and 10 as random examples, but this should give you the idea. Also replace
Dully
with whatever your agent type name is.