Netlogo:使用特定数量的海龟设置特定的setxy模式吗? [英] Netlogo: Set specific setxy patern with set number of turtles?

查看:741
本文介绍了Netlogo:使用特定数量的海龟设置特定的setxy模式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过文件创建一定数量的海龟以拥有自己的补丁?像总是在同一个位置吗?

Is it possible to create a set number of turtles, from a file, to have their own patches? Like always be in the same location?

我从文件中读取了106只海龟,我希望它们可以在自己的补丁上创建,就像方形格子一样.我希望能够查看模型世界并轻松识别乌龟.

I've got 106 turtles I'm reading in from a file and I was hoping to have them be created on their own patches, like a square latice kind of thing. I want to be able to look at the model world and easily identify a turtle.

file-open "turtledata_A.txt"
show file-read-line
while [not file-at-end?] 
[
set param read-from-string (word "[" file-read-line "]")
create-turtles 1 [setxy ??]
]
file-close 
]

推荐答案

可能最容易使用csv扩展名,并将xy数据添加到您正在读取的文件中.例如,如果您有turtle_data.csv看起来像这样的文件:

Probably easiest to use the csv extension and just add xy data to the file you're reading in. For example, if you have a turtle_data.csv file that looks like:

param-to-read,x,y
John,-10,10
Billy,-5,5
Bob,0,0
Simon,5,-5
Michael,10,-10

您可以这样做:

extensions [ csv ]

turtles-own [ param ]

to setup
  ca
  reset-ticks
  file-close-all
  file-open "turtle_data.csv"

  ;; read the headings line in to skip it for data extraction
  let headings csv:from-row file-read-line

  while [ not file-at-end? ] [
    let data csv:from-row file-read-line
    create-turtles 1 [
      set param item 0 data
      setxy item 1 data item 2 data
    ]
  ]

  file-close-all
end

这会给你类似的东西

然后,您可以修改.csv文件中的xy值,以将海龟放置在所需位置.那行得通吗?

Then you can modify the x and y values in your .csv file to place your turtles where you want them. Would that work?

当然,您可以在.csv文件中添加其他列(例如颜色,大小,形状等),以帮助您一目了然地识别海龟.

Of course, you can add other columns in the .csv file (like color, size, shape, etc) that will help you identify turtles at a glance.

这篇关于Netlogo:使用特定数量的海龟设置特定的setxy模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆