在人口中寻找任何logic,并访问其变量之一

发布于 2025-02-04 21:43:27 字数 416 浏览 3 评论 0原文

我想找到我的经纪人对其人口的指数(名为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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慵挽 2025-02-11 21:43:27

您无需在代理中使用自定义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).

原谅过去的我 2025-02-11 21:43:27

我认为您可能已经在Main中,并且不需要添加main。
无论如何,我建议使用:

Dully d = findFirst( dullieses, d -> d.ID == counter );
d.variable = 10;

我使用变量和10个随机示例,但这应该给您这个想法。还将dully替换为代理类型名称。

I think you're probably already in main and don't need to add Main..
Anyway, I would recommend using:

Dully d = findFirst( dullieses, d -> d.ID == counter );
d.variable = 10;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文