每个刻度读一行文件

时间:2015-04-30 08:54:36

标签: netlogo

我模拟了考古沉降的分布和动态。 我想每年使用与此类似的.csv文件更新结算站点的房屋数量:

    Settlement 1,Settlement 2,Settlement 3
    0,0,0
    1,0,0
    5,0,1
    ...

我有两个问题:

1)我没有成功使用Netlogo手册中提出的程序。在那里它读取

cl <- makeCluster(12)
registerDoParallel(cl)

但是csv:from-row会导致错误消息(“没有命名为......已定义”)。我该怎么做?

2) 我不仅仅有一个网站。有没有办法只使用一个.csv文件,如

sim <- foreach(j=1:nsim,.combine=c,
.packages=c('rugarch','stats'),.inorder=FALSE) %dopar%
{
exp(diffinv(ugarchsim(fit_list[["CHF"]],n.sim=horizon)@simulation$seriesSim))[horizon+1]
}

并确保结算1根据第1栏,第2栏第2栏等更新房屋?

感谢您的帮助! 直到

1 个答案:

答案 0 :(得分:3)

extensions [csv]
globals [settlements-list]  ;;to keep them in order
breed [settlements settlement]
settlements-own [n-houses]

to setup
  file-close-all
  ca
  create-settlements 3  ;;3 settlements, to match your example
  set settlements-list [self] of settlements ;;or sort if you wish
  file-open "c:/temp/temp.csv"
  let _trash file-read-line  ;;discard headers
end

to go
  file-open "c:/temp/temp.csv"
  if file-at-end? [ stop ]  ;;or at least, stop reading data!
  let _data csv:from-row file-read-line  ;;get data as list
  foreach n-values length settlements-list [?] [
    ask (item ? settlements-list) [set n-houses item ? _data]
  ]
  ask settlements [
    show n-houses
  ]
end