更新下一个tick的变量

时间:2016-02-12 10:43:04

标签: variables netlogo

我试图在netlogo中建模电池存储。我需要将电池剩余电量从一个滴答计算到下一个滴答作为初始值,直到模拟结束。 我尝试使用Arthur(NETLOGO: Using variable from previous tick)建议的方法,但它没有用。 有没有办法在netlogo(版本5.3)中这样做? 谢谢!

我的代码如下所示:

 globals[ remaining-electricity-last-tick] 
 to go
 ifelse tick = 1 [ set remaining-electricity 0 ;; set initial storage zero ] 
                 [set remaining-electricity remaining-electricity-last-tick ] 
 ... 
 ... 
 ... 
 set remaining-electricity-last-tick remaining-electricity 
end

1 个答案:

答案 0 :(得分:3)

You never change it from zero. Let's rewrite what you have as follows:

to setup
  ;note: remaining-electricity-last-tick = 0 (default value)
  set remaining-electricity 0 ;; set initial storage zero
end

to go
  ;therefore you set remaining-electricity to 0
  set remaining-electricity remaining-electricity-last-tick
  ;therefore you set remaining-electricity-last-tick to 0
  set remaining-electricity-last-tick remaining-electricity
end