2016-07-25 27 views
-2

我特别喜欢Netlogo的“Flocking”模型。我想要的是选择一个代理,并查看是否有其他代理存在于所选代理的接下来的3个补丁中。我想检查代理的所有代码,以便我获得矩阵形式的数据并将其保存在excel/cvs文件。如何在Excel文件中打印来自Netlogo的补丁矩阵数据?

+0

你实际上在找什么有些不清楚。 你想让每只乌龟看看前面的3个补丁并输出到一个文件中有什么?或者查看3个单位半径内的所有补丁并输出那里的内容?什么是感兴趣的输出因子(密度,距离,大小,颜色)?你想让你的矩阵组成什么?你是否希望在每次运行结束时为每个蜱,每个参数,每只乌龟都做这个?请具体说明,以便我们能更好地帮助您。提供一些编码尝试/可重现的问题或代码片段以供使用 – Jesse001

+1

首先也是一个好主意。是的,我希望海龟看3个补丁,但不是以半径方式,而是以矩阵方式。我只想看看矩阵中是否还有其他的乌龟,只是一个布尔值。就像有一只乌龟那么这个值应该是1,如果没有这个值应该是矩阵的0。我想要每个蜱和每只乌龟的数据。希望这清除了一切。 –

回答

1

不幸的是我没有给你一个明确的答案,但我想你会想要做类似的东西:

globals 
[ output_matrix] 
patches-own 
    [occupied?] 
to setup 
clear-all 
reset-ticks 
    create-turtles 50 
    set output_matrix [] 
end 
to go 
    move 
    tick 
end 
to move 
    ask turtles [set heading random-float 361 forward random-float 2 ] 
    ask patches with [count turtles-here > 0] [set occupied? 1] 
    ask patches with [count turtles-here = 0] [set occupied? 0] 
    check_surroundings 
end 
to check_surroundings 
    ask turtles [ ifelse any? turtles-on patch-ahead 1 
    [set output_matrix lput 1 output_matrix] 
    [set output_matrix lput 0 output_matrix]] 
    ask turtles [ ifelse any? turtles-on patch-ahead 2 
    [set output_matrix lput 1 output_matrix] 
    [set output_matrix lput 0 output_matrix]] 
    ask turtles [ ifelse any? turtles-on patch-ahead 3 
    [set output_matrix lput 1 output_matrix] 
    [set output_matrix lput 0 output_matrix]] 
end 

这将会给你两个选择。 1您可以使用行为空间将每个节点列表输出到一个文件(您将在行为空间中指定),并使用简单的0或1来表示每个文件是否被占用。第二个选择是使用这个创建的output_matrix列表(不知道你的最终游戏是什么)。这将给你每个蜱的每个乌龟的三个0和1的系列(如果你想估计随着时间的推移聚合形式可能会更有用)。

你也可以在把目光转向输出打印和打开文件/文件关闭原语

我敢肯定,如果你产生一些示例代码,社区将能够进一步帮助你。

0
globals [rpts] ;write your code to set global only once 

to test 
    ca 
    set rpts moore-offsets 3 
    ask n-of 50 patches [sprout 1 [set color red]] 
    ask one-of turtles [ 
    ask patches at-points rpts [set pcolor yellow] 
    print any? other turtles-on patches at-points rpts 
    ] 
end 

to-report moore-offsets [#n] ;includes center ... 
    let _result [] 
    let _xs n-values (1 + 2 * #n) [? - 3] 
    foreach _xs [ 
    let _y ? 
    foreach _xs [ 
     let _x ? 
     set _result lput (list _x _y) _result 
    ] 
    ] 
    report _result 
end