统计节点上的代理数量

huangapple go评论89阅读模式
英文:

Count number of agents at a node

问题

我已经设置了一个多边形节点(称为area_wait),一个单一类型的代理停留在该节点,同时在队列中。我正在尝试使用一个函数来查找节点上的代理数量。我不想计算队列中的代理,因为我为所有等待的代理设置了一个队列,这些代理可能在不同的节点。

我正在使用以下代码,但始终返回零。

int count_X = area_wait.agents().size();

实际上,当我用以下代码检查时,列表是空的:

List list_X = area_wait.agents();

我做错了什么?提前谢谢。

英文:

I have set up a polygonal node (called area_wait) that a single type of agent remain at whilst in a queue. I'm trying to find the number of agents at a node using a function. I don't want to count the agents in the queue as I have set up one queue for all waiting agents which might be at different nodes.

I'm using the following code which always returns zero.

int count_X = area_wait.agents().size();

In fact the list is empty when I check with:

List list_X = area_wait.agents();

What am I doing wrong? Thanks in advance.

答案1

得分: 1

我会给你与我在AnyLogic用户组中提供的相同答案,您可以在此处找到:https://www.linkedin.com/feed/update/urn:li:activity:6721800348408791040

所以您试图使用的这个函数是不起作用的... 除非节点内部的内容是一个传输器,并且只有在节点具有速度或访问限制时才可以... 这可能是一个错误,或者在文档中解释得不好,但我认为这听起来像是一个错误。

如果您想要知道节点中代理的数量,您可以使用另一种方法:count(myAgents, a -> a.getNetworkNode()!=null && a.getNetworkNode().equals(yourNode)),但是如果您在没有moveTo块或其他自然移动(例如在块的代理位置参数中定义您的节点)的情况下更改节点位置,则会失败... 所以... 那是另一个错误,但也许不适用于您。

所以总结... 就我所知,没有简单和安全的解决方案。

英文:

I will give you the same answer I gave in the anylogic users group which can be found here: https://www.linkedin.com/feed/update/urn:li:activity:6721800348408791040

so this function you are trying to use doesn't work... unless the thing that is inside the node is a transporter and only if the node has a speed or access restriction... this might either be a bug or something explained poorly on the documentation, but it sounds like a bug to me

If you want to know the number of agents in a node you can use the alternative method count(myAgents,a->a.getNetworkNode()!=null && a.getNetworkNode().equals(yourNode)) but this fails if you change the node position without a moveTo block or some other natural movement (such as defining your node in the agent location parameter of a block)... so.. that's another bug, but maybe it won't apply to you

So summary... no easy and safe solution as far as I know

huangapple
  • 本文由 发表于 2020年10月27日 08:58:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/64546957.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定