如何让代理在两个值之间选择最高值?

时间:2016-04-01 17:01:43

标签: max netlogo

人。我在NetLogo中为我的代理商(农民)创建了这个程序:

to calculate-deforestation

 ask farmers [
  set net-family-labor ( family-labor - ( ag-size * cell-labor-ag-keep ) ) 
  set net-family-money ( family-money - ( ag-size * cell-cost-ag-keep ) )
  ifelse  net-family-labor < 0 or net-family-money < 0
    [ set n-aband-cell-labor ( family-labor / cell-labor-ag-keep )
      set n-aband-cell-money ( family-money / cell-cost-ag-keep ) 

      set n-aband with-max [ n-aband-cell-labor n-aband-cell-money ]

      ]      

    [ set n-def-cell-labor ( net-family-labor / cell-labor-deforest )
      set n-def-cell-money ( net-family-money / cell-cost-deforest ) 

      set n-def with-min [ n-def-cell-labor n-def-cell-money ]

      ]
]
end

对于&#34; n-aband &#34;,我想获得&#34; n-aband-cell-labor &#34;和&#34; n-aband-cell-money &#34; (一个或另一个;同样适用于&#34; n-def&#34;)。我知道有限数量的NetLogo原语,但是我能找到的原语并不适用于我的情况,例如,&#34; with-max&#34;,&#34; max-n-of&# 34;,&#34; max-one-of&#34; 。我确信必须有一个可以工作,但我在NetLogo字典中找不到它。我想知道是否有人可以建议我一个可以适用于我的情况。提前谢谢。

1 个答案:

答案 0 :(得分:2)

如果您想获得列表的最大值,只需使用max即可。所以,

set n-aband max (list n-aband-cell-labor n-aband-cell-money )

会将n-aband设置为这两个值中的最高值。