更新netlogo

时间:2017-10-05 14:21:29

标签: list netlogo agent-based-modeling

我有4个生产商具有不同的属性,例如他们的新产品的价格,尺寸,客户费率。我定义了4个代表它们的列表。

set att-price ((list p1-pr p2-pr p3-pr p4-pr)); 4个生产商的所有产品的价格

set att-size ((list p1-sz p2-sz p3-sz p4-sz))



set att-rates ((list p1-rt p2-rt p3-rt p4-rt))

随着时间的推移,价格会得到更新,所以我将其定义为实现这一目标:

set (item 0 att-price) (item 0 att-price) * 0.20;生产者1产品价格的变化

set (item 1 att-price) (item 1 att-price) * 0.08

set (item 3 att-price) (item 3 att-price) * 0.43

但它有一个错误说"这不是你可以"设置"上"!

如何更新这些项目呢? 感谢

1 个答案:

答案 0 :(得分:2)

您可以使用replace-item。例如:

set att-price replace-item 0 att-price (0.2 * item 0 att-price) 

也就是说,我们不是设置列表中的项目,而是替换项目创建一个新列表,然后将列表变量设置为该项目。

如果您想一次更换所有项目,可以使用map。例如,您可能会看到价格变化的价格比率列表:

let ratios [ 0.2 1.0 0.08 0.43 ]
set att-price (map [ [ price ratio ] -> price * ratio ] att-price ratios)