如何在NetLogo中使用2个条件编写IF命令?

问题描述 投票:0回答:1

我的海龟是公司,他们有海龟自己,这是一个从公司到公司,以及离岸外包的利润?并重新编写?这是真还是假。

代码有些不对劲。我很难组合IF和AND命令。如果标签的参数偏离了? reports = true并且这些公司的利润低于报告外包的公司的利润? =假,比他们应该移动。代码的移动部分工作正常。请找到我到目前为止的(错误报告)代码:

breed [ firms firm ]


firms-own [   
   profit
   offshored?   ;; reports either true or false
   reshored?   ;; reports either true or false
]

to setup
  ask firms [
    if offshored? true AND profit < [ profit ] of firms with [ offshored? = false ] [   ;; if the profit of an offshored firm is smaller than the lowest profit of firms at home, the decision to reshore is yes!
      ask one-of turtles [ move-to one-of patches with [ pcolor = 58 and not any? turtles-here ] ]  ;; the firm reshores
      AND set reshored? true ] ]   ;; the firm is now labelled as reshored
end
if-statement condition netlogo agent-based-modeling economics
1个回答
2
投票

上面的设置不会做任何事情,主要问题可能是您将公司的利润变量与列表([profit] of firms with [ offshored? = false ])进行比较。您不能以这种方式直接将单个值与值列表进行比较,因此您必须以不同的方式进行操作。例如,您可以使用min获得其他感兴趣公司的最低利润值:

breed [ firms firm ]

firms-own [ profit offshored? reshored? ]

to setup
  ca
  ask patches with [ pxcor < -10 ] [
    set pcolor red
  ]

  create-firms 100 [
    set color white
    set profit random 101
    set offshored? one-of [ true false ]
    set reshored? false
    while [ any? other turtles-here ] [
      move-to one-of neighbors with [ pcolor = black ]
    ]
  ]

  ask firms [
    if offshored? and profit < min [ profit ] of firms with [ not offshored? ] [
      move-to one-of patches with [ pcolor = red and not any? turtles-here ]
      set reshored? true
      set color yellow
      set size 2
    ]
  ]
  reset-ticks
end 

另外,你在ask one-of turtles声明中有ask firms - 我想你想省略那个在这个例子中做的事情,以便做评估的公司是移动的代理人 - ask one-of turtles将只选择任何品种的随机龟。

© www.soinside.com 2019 - 2024. All rights reserved.