NetLogo 消费者行为模型

问题描述

我将简要介绍一下我的模型:

乌龟可以是红色或绿色,分别是杂食性和素食性

两个市场(蓝色方块):肉类和替代品(可以代替肉类消费的产品)市场

当我运行模型时,我希望海龟开始购买肉或替代品(仅当它们在两个市场之一并基于它们所在的市场时),如果它们是素食主义者并且购买肉变红而如果他们停止购买肉类而只购买替代品,它们就会变绿(经过一定数量的蜱虫,我还没有决定,它们可以被视为素食主义者)。

to go
  move-turtles
  market
  tick
end

to market
  ask turtles
  [ ifelse pcolor = blue
    [buy]
    [right random 360 forward 1]
  ]
end

to buy
    if market-patches [set money money - Meat-Price]
    if market-patches1  [set money money - Substitutes-Price]  
    if money = 0 [stop]
end

我不明白为什么当我尝试运行模型时,它会返回此错误,并且我确定该错误包含在最后 3 个 ifs 语句中:

IF 预期输入为 TRUE/FALSE 但得到了补丁(补丁 12 11)。

另外,如果您能帮助我构建 go 程序,我将永远感激不尽。

这是模型的概述:

model

解决方法

好的,这些是您的关键程序:

to go
  move-turtles
  market
  tick
end

to market
  ask turtles
  [ ifelse pcolor = blue
    [buy]
    [right random 360 forward 1]
  ]
end

to buy
    if market-patches [set money money - Meat-Price]
    if market-patches1  [set money money - Substitutes-Price]  
    if money = 0 [stop]
end

go 过程的逻辑是它调用市场过程,市场过程让每只海龟查看它所站立的补丁的颜色 - 如果颜色是蓝色,则海龟跳转到购买过程。购买过程中会发生什么?海龟必须检查是否if market-patches。你真正想让乌龟在这里做的检查是什么?我认为您的意思是“如果我站在名为 market-patches 的补丁集中的补丁上”。但是 NetLogo 错误消息告诉您您没有正确定义您希望海龟检查的内容。

因此,要询问海龟所在的这个补丁是否在市场补丁补丁集中,您需要使用 member? 关键字。海龟可以用 patch-here 识别它所在的补丁。这未经测试,但我认为它应该可以解决您的问题:

to buy
    if member? patch-here market-patches [set money money - Meat-Price]
    if member? patch-here market-patches1  [set money money - Substitutes-Price]  
    if money = 0 [stop]
end