最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Can I dynamically add a static agent to Anylogic model in Java? - Stack Overflow

programmeradmin0浏览0评论

The question is in title. I need to automatically create Agent when model starts, and I need this Agent became static. If this type of Agent was a standart Java class I'll make it's static and create it with standart Java code:

MyClass myClass = new MyClass();

But I need to do this things with Anylogic agent.

The question is in title. I need to automatically create Agent when model starts, and I need this Agent became static. If this type of Agent was a standart Java class I'll make it's static and create it with standart Java code:

MyClass myClass = new MyClass();

But I need to do this things with Anylogic agent.

Share Improve this question edited Mar 3 at 18:21 Benjamin 12.8k4 gold badges19 silver badges33 bronze badges asked Mar 3 at 13:51 YuraYura 292 bronze badges 1
  • pls only use the anylogic tag, else you confuse 1000s of SOF users :) – Benjamin Commented Mar 3 at 18:22
Add a comment  | 

1 Answer 1

Reset to default 1

You cannot instantiate anything static, that is the definition of static in Java.

Your example code also does not instantiate a static MyClass (but a non-static instance of MyClass).

In order to create agent objects dynamically (instantiate them), you can simple create an event at time 0 to MyAgent newAgent = new MyAgent();

The better approach is to add the agent directly into an existing population using myPop.add_MyAgent();

PS: If you truly want to use static elements, you may need to brush up some OOP and Java first :) But I think you did not mean that, you want to instantiate an agent dynamically at runtime, right?

发布评论

评论列表(0)

  1. 暂无评论