每次滴答从文件中读取数据 [英] Read data from file in every ticks

查看:78
本文介绍了每次滴答从文件中读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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
]

这篇关于每次滴答从文件中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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