这就是问题:
我有两个智能体群体:“蓝色矩形”和“红色矩形”。这两个代理进入同一队列。然而,很难知道在任意时间T队列中有多少红色和蓝色矩形。
有没有一些函数/技术来获取它?
例如,我想在控制台中打印:“队列中有N个蓝色矩形和M个红色矩形。”
发布于 2021-07-02 02:47:02
当然,您可以遍历队列中的所有代理,并根据其代理类型检查每个代理(假设蓝色和红色代理实际上是不同的代理类型):
for (int i=0; i<myQueue.size(); i++) {
if (myQueue.get(i) instanceof AgentTypeBlue) {
// do whatever you want to count blue agents
} else if (myQueue.get(i) instanceof AgentTypeRed) {
// do whatever you want to count red agents
}
}或者直接使用Queues "on enter" and "on exit" code boxes to count whenever a blue or red agent enters & leaves (using a variable countRed/countBlue`),如下所示:

https://stackoverflow.com/questions/68212382
复制相似问题