Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Netlogo 将全局值添加到上一个勾号的值,每个勾号_Netlogo - Fatal编程技术网

Netlogo 将全局值添加到上一个勾号的值,每个勾号

Netlogo 将全局值添加到上一个勾号的值,每个勾号,netlogo,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

我正在从事一个需要我分配补贴的项目。我有两个品种,工业和港口。现在,我希望每一个勾号都将补贴添加到之前的金额中,而不是仅仅选择特定勾号的价值。我明白了:

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
欢迎大家帮忙!提前感谢:)


Max

您需要一个变量来存储补贴。我认为你们是在给每个行业和港口补贴。因此,您需要
industries own
ports 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

非常感谢!工作很有魅力:)@MaxGoessens-如果Jen的答案解决了您的问题,请单击他们答案顶部附近的小复选标记,将此问题标记为已结束。