NetLogo链接:通过链接变量的值过滤附近海龟的好方法是什么

时间:2013-11-11 04:45:48

标签: netlogo

我需要查看附近是否有任何代理可能链接到具有负关系值的调用者代理,现在我使用以下代码:

    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,有没有更好的方法呢?

所有这些代码都是由另一个只有一个ask agents []的程序调用的,它确实完成了我需要它做的事情,但我认为我可能有一个错误的方法。

1 个答案:

答案 0 :(得分:1)

我认为以下内容将在检查其end2之前过滤一组初始邻居,因此是一种更快速的方法来过滤目标候选者(它也更准确)

let met  out-link-neighbors in-cone 2 180 with [member? myself [end2] of my-out-links with [Value-Of-The-Relationship < 0]] 

        if any? Met
    [] 

另一个主要变化是限制目击者,因为现在所有活跃代理人的半径5中的代理人都将被视为证人,但我认为最好检查一下活动代理人是否在他们的视锥内,我仍然在寻找找到一种有效的方法来检查目击者的视力,看他们是否可以观察代理人。

set Witnesses other (agents in-radius vision with [Belongs_to = [Belongs_to] of Active_Agent and member? myself people in-cone vision  75 ])

**更新:更好的答案**

    let met out-link-neighbors in-cone 2 120 with 
    [
[Value-Of-The-Relationship] of in-link-from myself < 0]