【问题标题】:Netlogo: Stop loop of actions after turtles carry out actionNetlogo:海龟执行动作后停止动作循环
【发布时间】:2019-03-15 12:40:21
【问题描述】:

我之前描述的模型的延续,它用于我的论文并基于信任游戏文献。对 Netlogo 来说相对较新,我敢肯定我在这里遗漏了一些重要的东西。

我的世界有两种类型的代理人,性工作者和官员。每个都有特定的属性:

sexworkers-own
[ assault?       ;; is assaulted?
  trust?         ;; trusts/avoids police to report assault?
  protection?    ;; was protected/arrested by police after report?
  prob-report ]  ;; overall probability to report based on the 
three factors before

officers-own
[ arrest?     ]  ;; arrests or protects assault victims?

在模拟开始时,性工作者随机分布在袭击受害者中[袭击? = true] 与否的概率为 0.1%(受害)。官员被随机分配为逮捕性工作者[逮捕? = true] 有 90% 的逮捕概率。

在模拟运行时,被殴打的性工作者面临着提交报告的选项。他们要么选择合作,要么避免这种情况,概率为 50%。如果他们选择合作,他们的属性[信任?]为真,如果他们避免,则为假。

一旦性工作者选择合作,警察就会跟进举报。根据[逮捕?],他们要么逮捕,要么提供保护。这会导致性工作者属性[保护?]。

这些选项中的每一个都会导致不同的总体报告概率(prob-report),这在以后很重要。

我的问题是:我希望被殴打的性工作者能够跳出圈子,在他们做出一次选择时停止执行合作或回避的决定.我不知道如何更改我的代码,以拒绝性工作者,这些性工作者要么回避了,要么配合了性工作者的整体备案程序。

提交报告、合作/避免以及官员保护/逮捕的过程运作良好。我只需要一种方法来让选择退出的被殴打的性工作者,这样只有新被殴打的性工作者才会面临选择。

非常感谢!

这是我的代码:

to go
  ;; asks sex workers to act depending on whether they have been assaulted
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;PROBLEM: THIS SHOULD NOT BE LOOPED;;;;;;;;;;;;;;;;;;
  ;IF ASSAULT? THE ACTION SHOULD BE CARRIED OUT ONLY ONCE;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ask sexworkers with [ not assault? ] [victimize ]
  ask sexworkers with [ assault? ] [ file ]
end

; determines probability of sex workers being assaulted (1%)
; sets the probability value to file reports to 0.5 
; if sex workers haven't previously been assaulted
to victimize
    ifelse random-float 100 <= 0.1
    [ set assault? true ]
    [ set assault? false ]
  if assault? = false [ set prob-report 0.5 ]
end

; determines probability of sex workers reporting violence (50%)
to file
   ifelse random-float 1 <= 0.5
  [ set trust? true ]
  [ set trust? false ]
  if assault? = true and trust? = false 
  [ avoid ]
  if assault? = true and trust? = true
  [ cooperate ] 
end

; if assaulted sex workers report, the follow-up procedure is started
to cooperate
   follow-up 
end

; this sets the probability value to file reports to 0 
; if sex workers have been assaulted, but didn't report
to avoid
   if assault? = true and trust? = false  
   [ set prob-report 0 ]
end

; asks officers who arrest to arrest and the others to protect
to follow-up
  ask officers with [ arrest? = false] [ protect ]
  ask officers with [ arrest? = true ] [ arrest ]
end

; if officers protect, reporting sex workers' protection? attribute is true
; sets the probability value to file reports to 1
; if sex workers have been assaulted, reported, and protected
; and officers' arrest? attribute is false
to protect
  ask sexworkers-here with [ trust? = true ] [ set protection? true ]
  ask sexworkers [
  if assault? = true and trust? = true and protection? = true 
    [ set prob-report 1 ]
  ]    
end

; if officers arrest, reporting sex workers' protection? attribute is false
; sets the probability value to file reports to -1
; if sex workers have been assaulted, reported, and arrested
; and officers' arrest? attribute is true
to arrest
  ask sexworkers-here with [ trust? = true ] [  set protection? false ]
  ask sexworkers [
    if assault? = true and trust? = true and protection? = false 
    [ set prob-report -1 ]
  ]
end

【问题讨论】:

  • 攻击、举报等是一次性行动吗?所以它们发生在tick 期间,然后它们就结束了?如果是这样,您不需要一个属性来存储它们是否为真。您只需要从一个刻度到下一个刻度需要记住的变量的属性。
  • 他们需要被记住到下一个刻度,这是整个想法,他们被记住了。现在,可以这么说,它们还没有被记住“足够”,而是随着循环而改变(除了攻击?基于我设置它的方式,这很好用)。

标签: loops netlogo probability repeat agent-based-modeling


【解决方案1】:

如果他们在一刻受到攻击,你希望在接下来的刻和以后的刻发生什么?他们在过去的某个阶段受到攻击这一事实是否会以任何方式影响他们未来的行为?

您让他们永远记住,因为您将攻击变量设置为 true 并且没有机会将其更改回来。如果您需要他们永远记住这一点,那么您需要一个额外的属性来跟踪他们没有做出决定的攻击这一事实。然后,一旦他们做出决定,您就可以更改该属性的状态。你不能用同一个变量保留两条不同的信息(曾经被攻击过,并且有一次未决定的攻击)。

【讨论】:

  • 感谢您的回复!我要暴击?尽管如此,他们应该永远记住他们是否被殴打过。然而我的问题是他们不记得他们之后做了什么,也就是说,他们永远在基于被攻击的策略之间循环选择。所以我希望他们以后也记得他们是否选择了信任?然后还有那个选择的后果是什么(逮捕?/保护?)。
  • 如果你想让他们记住一些东西,你需要一个变量。
  • 非常感谢您,这真的很有帮助。我现在对我可以做些什么来让它按我想要的方式工作有一个更好的想法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多