totalWater-runoff图显示了norhing。我的If命令无效或我在Netlogo中编写的代码不正确

时间:2017-01-11 13:12:06

标签: netlogo

我曾试图为海拔较高的农民提供较低海拔的水源径流(上游水流径流)。但我的水流失图表并没有显示出来。请纠正我的错误!

 Globals [
      water-req
      elevation
      rain-amount
      total-runoff]
    patches-own [
      ]

    Breed[farmers farmer]
    farmers-own[farms
       ]

    ;;;;;;;;;;;;;;;;:::::: Environment Setup;;;;;;;;;;;;;;;;;;;
    to setup
      ca
      ask patches [
                   set pcolor green ]
                  create-farmers num-farmers
      ask farmers [
                  set rain-amount random monthly-rain
                  set water-req  10 + random 15

                  set elevation  xcor + ycor
                  move-to one-of patches

                  ]

 reset-ticks
 end

to go
   ask farmers [ 
     drain-water
    ]
    chart
    tick
    end

to drain-water
  if rain-amount > water-req ; Global of water-rew is set 
         [ let excess-rain-water rain-amount - water-req
                  let draining-farmers other farmers  in-radius srounding-farms with [elevation  >  [elevation] of myself and excess-rain-water > 0 ]
                   if draining-farmers = nobody [ stop]
                     ask draining-farmers [ set rain-amount rain-amount -  excess-rain-water ]
                       set  rain-amount rain-amount + excess-rain-water
                        set total-runoff  total-runoff + excess-rain-water


]

end



to chart

  set-current-plot "water runoff"
  plot total-runoff
  set total-runoff  0


end

chart setting for water-runoff

1 个答案:

答案 0 :(得分:1)

我认为您的麻烦来自于使用 reset-ticks / ticks 以及 set-current-plot / plot 命令。 勾选实际上会自动执行更新图表操作。以下是更多信息:https://ccl.northwestern.edu/netlogo/docs/programming.html#plotting

据我所知,您希望每天将总径流重置为0然后添加到它,这样您就可以通过添加以下内容来解决此问题:

set-current-plot-pen"默认"

在您的代码中绘制总径流之前,或者您可以取出:

 set-current-plot "water runoff"
  plot total-runoff

并添加:

plot total-runoff 

到绘图中第一支笔的笔更新命令部分。

无论哪种方式都应该这样做。