AnyLogic如何select通过网络中的另一个代理连接最近的代理?
How to select the nearest agent connected through another agent in a network in AnyLogic?
在一个模型中,我通过 'link to other agents' 个对象在网络中连接了不同的代理类型。我使用了一个函数来创建网络:
shopLink.connectTo(this.getNearestAgent(main.shops));
homeLink.connectTo(this.getNearestAgent(main.homes));
所以每个工厂代理只连接到最近的商店和家。此函数在 Factory-agent 类型中的 'at startup' 字段中调用。
假设红色代理类型是工厂,黄色代表商店,绿色代表家。还假设所有的 Factory-agents 都包含 Person-agents,我想将 Person-agents 发送到最近的 Shop-agent 连接到 Factory-agent。我需要使用什么 Java 代码才能 select 连接到工厂代理的最近的商店代理?
如果您的 Person 代理存在于 Factory 父代理中,并且您有如图所示的连接,那么这取决于您在 Factory 中设置连接的方式:
(a) 如果 Factory 的默认 connections
Link 到 Agents 对象包含 仅 商店代理连接,请使用
getNearestAgent(factory.getConnections())
(b) 如果 Factory 的商店连接在一个特殊的 Link 到 Agents 对象中(比如 shopConnections
)然后使用
getNearestAgent(factory.shopConnections.getConnections())
(c) 如果您在工厂的默认 connections
Link 中混合了与所有其他代理类型(商店、工厂等)的连接,则您必须过滤该列表首先只包括商店代理所以
(Shop) getNearestAgent(filter(factory.getConnections(), f -> f instanceof Shop))
(在案例 (c) 开始时需要 (Shop)
位的原因方面有 Java 微妙之处,这是一个 Java 转换,但 (a) 不需要t. 这与 getNearestAgent
和 getConnections
都是 generic methods, and type inference 正在使用的事实有关。)
在一个模型中,我通过 'link to other agents' 个对象在网络中连接了不同的代理类型。我使用了一个函数来创建网络:
shopLink.connectTo(this.getNearestAgent(main.shops));
homeLink.connectTo(this.getNearestAgent(main.homes));
所以每个工厂代理只连接到最近的商店和家。此函数在 Factory-agent 类型中的 'at startup' 字段中调用。
假设红色代理类型是工厂,黄色代表商店,绿色代表家。还假设所有的 Factory-agents 都包含 Person-agents,我想将 Person-agents 发送到最近的 Shop-agent 连接到 Factory-agent。我需要使用什么 Java 代码才能 select 连接到工厂代理的最近的商店代理?
如果您的 Person 代理存在于 Factory 父代理中,并且您有如图所示的连接,那么这取决于您在 Factory 中设置连接的方式:
(a) 如果 Factory 的默认 connections
Link 到 Agents 对象包含 仅 商店代理连接,请使用
getNearestAgent(factory.getConnections())
(b) 如果 Factory 的商店连接在一个特殊的 Link 到 Agents 对象中(比如 shopConnections
)然后使用
getNearestAgent(factory.shopConnections.getConnections())
(c) 如果您在工厂的默认 connections
Link 中混合了与所有其他代理类型(商店、工厂等)的连接,则您必须过滤该列表首先只包括商店代理所以
(Shop) getNearestAgent(filter(factory.getConnections(), f -> f instanceof Shop))
(在案例 (c) 开始时需要 (Shop)
位的原因方面有 Java 微妙之处,这是一个 Java 转换,但 (a) 不需要t. 这与 getNearestAgent
和 getConnections
都是 generic methods, and type inference 正在使用的事实有关。)