Netlogo:乌龟执行动作后停止动作循环

时间:2019-03-15 12:40:22

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

我之前描述的模型的延续,这是我的论文,并且基于信任游戏的文献。相对于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%。如果他们选择合作,则他们的属性[trust?]为true,如果他们避免,则为false。

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

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

我的问题是: 我希望遭受殴打的性工作者摆脱困境,停止执行决定,在他们做出选择后就予以合作或避免。我无法弄清楚如何更改我的代码,以删除那些在性骚扰总体申请程序中避免或配合的性工作者。

提交报告,进行合作/回避以及保护/逮捕人员的工作过程都很好。我只需要一种使选择了选择的选择退出的性工作者的方法,以便只有新攻击的性工作者才能选择。

非常感谢您!

这是我的代码:

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

1 个答案:

答案 0 :(得分:1)

如果他们在一次tick虫中受到攻击,那么在接下来的s虫和以后的tick虫中您想发生什么?他们在过去某个阶段受到袭击的事实是否会以任何方式影响他们未来的行为?

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