1

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

    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 ,有没有更好的方法来做到这一点?

所有这些代码都由另一个只有一个询问代理 [] 的过程调用,它完全符合我的需要,但我认为我可能有错误的方法。

4

1 回答 1

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]
于 2013-11-12T03:00:20.937 回答