我需要查看附近是否有任何代理可能与具有负关系值的呼叫代理的链接,现在我正在使用以下代码:
if any? out-link-neighbors with [member? myself [end2] of my-out-links with [Value-Of-The-Relationship < 0]]
[
Let Active_Agent self
let Target_Agent nobody
Let Witnesses []
let Met out-link-neighbors with [member? myself [end2] of my-out-links with [Value-Of-The-Relationship < 0]]
if any? Met in-radius 2 [
set Target_Agent one-of Met in-radius 2
if some conditions
[
set Witnesses other agents in-radius vision with [Belongs_to = [Belongs_to] of Active_Agent ]
if any? Witnesses
[
Let Penalty 4000 / count Witnesses
ask Witnesses
[Update_link_Values Target_Agent Penalty]
]
]]]
To Update_link_Values [Other_Agent Value]
ifelse out-link-neighbor? Other_Agent
[ ask out-link-to Other_Agent
[
set Value-Of-The-Relationship Value-Of-The-Relationship + Value
set Frequency Frequency + 1
]
] ;IF already has a link
[create-link-to Other_Agent
[
set Value-Of-The-Relationship Value-Of-The-Relationship + Value
set Frequency Frequency + 1
hide-link]
] ;If they meet for the first time
end
我已经总结了代码,让您了解我何时使用 ask 和 with ,有没有更好的方法来做到这一点?
所有这些代码都由另一个只有一个询问代理 [] 的过程调用,它完全符合我的需要,但我认为我可能有错误的方法。