每次滴答从文件中读取数据
我正在使用NetLogo,并且希望在每个时间步长(滴答)中从每个代理的文件中读取两种类型的数据(例如"x"和"y").有人知道我该怎么做吗?
I am using NetLogo and I want to read two types of data (for example "x" and "y") from a file for each agent in each time step (tick). Does anyone know how I can do this?
这是代码:
breed [agents agent]
agents-own [ need tax]
to setup
clear-all
define-xy
reset-ticks
end
to define-xy
file-open "D:\\data\\xy.txt"
while [not file-at-end?]
[
let items read-from-string (word "[" file-read-line "]")
crt 1 [
set xcor item 0 items
set ycor item 1 items
set label ycor
]
]
file-close
end
to go
tick
if (ticks = 5)
[
stop
]
end
现在,如果我想定义两个参数tax,并且需要更改每个刻度,我应该怎么做.我有点困惑.在上面的代码中,我可以一次读取具有两列的文件.
Now if I want to define two parameters that are tax and need that change each tick what should I do. I am a little bit confused.In the code above I can do a one time read from a file that has two columns.
好.您提供的有关文本文件中数据结构的信息太少,因此我假设您只有两列.因此,文本文件如下所示:
Well. You give too little information about how the data is going to be structured in the text file, so I will suppose that you have only two columns. So the text file looks like this:
1 3
4 5
9 11
-1 33
首先,我认为您需要一种控制代理的方法,我再次假设您创建了一定数量的代理,并且文本文件的第1行用于代理1.
First, I think you'll need a way to control the agents, I'm again supposing you create a determinated number of agents and that row 1 of text file is used for agent 1.
也就是说,接下来要做的就是使用repeat number-of-agents [tasks]
That said, next thing you want to do is to use repeat number-of-agents [tasks]
tasks
可能类似于:
let auxiliar 0
repeat number-of-agents [
let data-read read-file-line
ask agent auxiliar [ set var1 first data-read
set var2 last data-read ]
tick ;Reads, Assigns, Ticks and all over again.
set auxiliar auxiliar + 1
]