Netlogo编码-IF码

时间:2018-11-28 22:29:52

标签: netlogo agent-based-modeling

这是我在Netlogo中面临的问题。我想让一只乌龟检查自己的变量之一,并检查另一只乌龟(不同品种)的另一个变量。基于这两个两个值,我想为乌龟设置奖励。假设我有“学生”和“老师”两个品种。学生可能会“作弊”(二进制),而老师可能会“二进制”捕获-因此,基于他们是否作弊和被抓住,适当的奖励就会随之而来。我正在尝试通过以下代码将其合并

if comply? = 1
[ 
ask students [ set gain reward1 ] 
] 

if comply? = 0 and caught? < random-float 1
[
ask students [set gain reward2 ] 
] 

if comply? = 0 and caught? > random-float 1 
[ 
ask suppliers [set gain reward3 ] 
] 
end 

增益是学生自己的变量并被捕获?是老师自己的变量,代表老师抓住学生的机会。

当我运行模型时,出现错误“在运行Student1并运行Caught时,学生品种不具有变量CAUGHT?错误?

我想知道是否有人可以分享一些见解? 谢谢 黛比

1 个答案:

答案 0 :(得分:1)

学生品种不拥有CAUGHT吗? :洞察力

通常,当出现所有权错误时,问题是乌龟或本例中的学生引用了一个不属于其品种的变量。下面是一个示例,说明如何为您的代码初始化模型,以及一个失败的示例。

breed [ students student]
breed [ teachers teacher]

students-own [ gain comply?]
teachers-own [ caught? ]

... ; initialize
to go
  ask students [ set gain 3 ]    ; this passes
  ask students [ set caught? 3 ] ; this fails
end

上下文的重要性

您的问题很可能与在学生程序中添加有冲突的变量有关。 (下面的示例)

to listen-in-class ; student procedure
  if comply? = 0 [ set gain 7 ]
  ; the comply? variable assumes a student is calling the procedure

  if gain = 3 [ set gain 4 ] 
  ; The gain variable assumes a student is calling the procedure

  if caught? = 0 [ set gain 2 ] 
  ; The caught? variable assumes a teacher is calling the procedure
end

由于过程可以调用其他过程,因此每个过程都从变量/过程中假设其环境(上下文)。

to starting-class ; should be a student procedure
   ask student [ listen-in-class ]
   ; "ask student" assumes listen-in-class only takes global or student only variables
end

最有可能的是,为过程添加了错误的变量集。询问往往会根据品种限制变量的范围。