如何访问Netlogo中以前的海龟互动?

问题描述

我正在编写一个模型,在该模型中,代理之间相互交互,并且它们相互配合或存在缺陷。然后,他们根据与他们的互动来更新与合作伙伴的合作水平,而我设法做到了这一点:

to random-matching ; randomly match agents
  while [not matched?] [ ; check that I have not been matched yet
    set partner one-of agents with [not matched?] ; select one agent from those who have not been matched yet
    if (partner != nobody and [myID] of partner != myID) [ ; if there is still someone who has been matched and who is not myself
      set matched? true ; then record that I have been matched
      set color white
      set partner-ID [myID] of partner ; save the ID of my partner for the future
      ask partner [ ; and do the same for my partner
        set matched? true
        set color white
        set partner-ID [myID] of myself
        set partner myself
      ]
    ]
  ]
  
  
end

; access the cooperation level of the agent toward the partner
to-report coop-agent-partner
  let coop-agent table:get cooperation-matrix myID  
  let coop table:get coop-agent partner-ID
  report coop
end

; access the cooperation level of the partner toward the agent
to-report coop-partner-agent
  let coop-partner table:get cooperation-matrix partner-ID
  let coop table:get coop-partner myID
  report coop
end
  


to interact ; define whether the interaction is a cooperation or not
  ; check that I did not interact already with my partner
  if not interacted? [
    
  ; let's check what I do
    let j random-float 1 * 100
    let coop-% cooperation-level + coop-agent-partner
    ifelse (j <= coop-%) [
      set action-self "C"
      ask partner [set action-partner "C" ]
    ][
      set action-self "D"
      ask partner [set action-partner "D" ]
    ]
    
  ; and what my partner does
    let k random-float 1 * 100
    let coop-partner-% [cooperation-level] of partner + coop-partner-agent
    
    ifelse (j <= coop-partner-%) [
      ask partner [set action-self "C" ]
      set action-partner "C"
    ][
      ask partner [set action-self "D" ]
      set action-partner "D"
    ]
    
  ;save the outcome of the interaction
    ifelse (action-self = "C" and action-partner = "C")[
      set interaction-outcome "C"
      set current-goal (current-goal + 1)
    ]
    [
      set interaction-outcome "D"
    ]  
  ]
end

; update the agents cooperation according to the current interaction

to update-cooperation
  
  if not updated-coop? [
    ifelse (action-partner = "C")[ ; if the partner cooperated
      let coop-agent table:get cooperation-matrix myID  
      let coop-a-p table:get coop-agent partner-ID
      set coop-a-p (coop-a-p / 2) + update_cooperation_direct
      
      if debug-int? [print coop-a-p]
    ][
      let coop-agent table:get cooperation-matrix myID  
      let coop-a-p table:get coop-agent partner-ID
      set coop-a-p (coop-a-p / 2) - update_cooperation_direct
      
    ]
    ifelse (action-self = "C")[
      ask partner[ ; if the interaction was a cooperation
        let coop-agent table:get cooperation-matrix myID  
        let coop-a-p table:get coop-agent partner-ID
        set coop-a-p (coop-a-p / 2) + update_cooperation_direct
      
      ]
    ][
      ask partner [
        let coop-agent table:get cooperation-matrix myID  
        let coop-a-p table:get coop-agent partner-ID
        set coop-a-p (coop-a-p / 2) - update_cooperation_direct
        
      ]
    ]
    
    ; record that both the agent and the partner have updated their cooperation score
    
    set updated-coop? true
    ask partner [set updated-coop? true]
  
  ]

end

我现在需要座席将他们所拥有的互动及其合作伙伴ID存储在一个变量中,该变量可以跟踪发生的时间,因此我需要为每个座席存储互动发生的时间(滴答)(与之交互) (合作伙伴ID)以及合作伙伴的行为(行动合作伙伴)。 有一个简单的方法吗? 我想我已经使到目前为止编写的代码过于复杂了,我想寻求帮助。 我刚刚开始使用Netlogo进行编码,并且试图从Matlab转换我的代码,该代码以矩阵的形式实现,宽度等于交互发生的那一轮。

任何帮助将不胜感激,谢谢:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)