在每个刻度线的前面的刻度线的值上添加一个全局值

时间:2019-01-07 15:59:21

标签: netlogo

我正在做一个项目,要求我划分补贴。我有两个品种,工业和港口。现在,我希望每个刻度线都将补贴添加到以前的金额,而不是仅选择该特定刻度线的值。我知道了:

to go
    if file-at-end? [ stop ]
  file-open "oil price.csv"
  set oil-price csv:from-row file-read-line
  file-open "co2 price.csv"
  set co2-price csv:from-row file-read-line
  file-open "electricity price.csv"
  set electricity-price csv:from-row file-read-line
  ;; model update goes here
  distribute-subsidies
  ask industries [update-profit]
if ticks >= 32 [stop]
  tick
end

to distribute-subsidies
 ask industries [set subsidy-industry (15000000 - 150000 * subsidy-to-port) / 25]
 ask ports [set subsidy-port 150000 * subsidy-to-port]
end

欢迎所有帮助!在此先感谢:)

最大

1 个答案:

答案 0 :(得分:1)

您需要一个变量来存储补贴。我认为您正在为每个行业和港口提供补贴。因此,您需要industries-ownports-own为每只乌龟定义一个变量。然后,您可以简单地将新补贴添加到以前的补贴中。

从您的代码中,我相信您已经有了这些变量。您尚未向我们显示own语句。将您的分发过程替换为:

to distribute-subsidies
 ask industries
 [ set subsidy-industry subsidy-industry + (15000000 - 150000 * subsidy-to-port) / 25
 ]
 ask ports
 [ set subsidy-port subsidy-port + 150000 * subsidy-to-port
 ]
end

或者,如果您担心效率,请计算一次并加到全部。

to distribute-subsidies
 let new-subsidy-industry (15000000 - 150000 * subsidy-to-port) / 25
 let new-port-subsidy 150000 * subsidy-to-port
 ask industries
 [ set subsidy-industry subsidy-industry + new-subsidy-industry
 ]
 ask ports
 [ set subsidy-port subsidy-port + new-port-subsidy
 ]
end