2015-10-13 53 views
0

嗨,我正在做一个模型,我需要使用时间变量的值做一个元素列表。这是我用来定义我的时间变量的代码与时间变量做一个列表,并选择随机的那些元素

to react 
    ask cells 
    [ 
    let Ai1 count turtles with [color = blue and xcor < -13 and ycor > -26] 
    let Ai2 count turtles with [color = blue and xcor < -13 and ycor < -27] 
    let Ai3 count turtles with [color = blue and xcor > -12 and xcor < 11 and ycor > -26] 
    let Ai4 count turtles with [color = blue and xcor > -12 and xcor < 11 and ycor < -26] 
    let Ai5 count turtles with [color = blue and xcor > 11 and ycor > -26] 
    let Ai6 count turtles with [color = blue and xcor > 11 and ycor < -26] 
    let Aimax list (Ai1 Ai2 Ai3 Ai4 Ai5 Ai6) 
    set calories (44.5 * random Aimax) 
    ] 
    end 

所以我需要做AI1到AI6值的列表,然后选择ramdomly这6个数值之一,在未来使用它时间变量Aimax的乘法如此可能做到这一点?如果我使用随机命令,它可以用在列表中? Tks阅读。

回答

1

one-of会随机挑选一个项目从列表:

set calories (44.5 * one-of Aimax) 
+0

谢谢,我认为这只能与海龟和补丁一起使用,不适用于任何种类的代理列表。任何建议集合变量?因为命令“list”仅适用于不具有临时变量的常量。 –

+0

我弄清楚如何制作列表。我使用“句子”命令将3个变量分组,首先将2个临时变量分组,然后再与另一个变量分组。我将其与其他3个时间变量进行了对比,最后加入他们列出了6个时间变量。我这样做是因为它通过这个命令表明它不能与其他更多项目一起加入2个项目列表,因此我需要制作2个相同数量项目(3)的列表并使用“句子“把他们分组。 –

0

不要那样做。你让每个单元格计算所有计数,只需要确定一次。你也重复过滤蓝色的乌龟。如果我们坚持自己的边界,我们可以写

to-report countblues 
    let blues (turtles with [color = blue]) 
    let counts (list 
    count blues with [xcor < -13 and ycor > -26] 
    count blues with [xcor < -13 and ycor < -27] 
    count blues with [xcor > -12 and xcor < 11 and ycor > -26] 
    count blues with [xcor > -12 and xcor < 11 and ycor < -26] 
    count blues with [xcor > 11 and ycor > -26] 
    count blues with [xcor > 11 and ycor < -26] 
    ) 
    report counts 
end 

to react 
    let counts countblues 
    ask cells[ 
    set calories (44.5 * one-of counts) 
    ] 
end 

请注意,如果你龟永远不会改变颜色,你可以把blues成全球性的,虽然会有小幅上涨至每全球在引用透明成本。

相关问题