Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables Netlogo变量作为txt(csv)文件_Variables_Text_Netlogo - Fatal编程技术网

Variables Netlogo变量作为txt(csv)文件

Variables Netlogo变量作为txt(csv)文件,variables,text,netlogo,Variables,Text,Netlogo,我对Netlogo很陌生。 连接一个GIS文件,我想制作一个模型,模拟人们对PM(特殊物质)等空气污染的反应。当然,我也需要考虑其他的变量,比如气温、降水等等。我有一个由邻里收集的关于食物消费、空气污染和所有其他变量的面板数据 我的问题是,我们是否可以使一个变量随时间而变化,也就是说,当勾号前进时,变量的值会发生变化。例如,代理可能会对其附近的空气污染作出反应,并改变其食物消费行为。我想为社区(斑块)建立一个“空气污染”变量,它会随着时间而变化(根据我收集的数据)。所以,不知何故,我想链接每个变

我对Netlogo很陌生。 连接一个GIS文件,我想制作一个模型,模拟人们对PM(特殊物质)等空气污染的反应。当然,我也需要考虑其他的变量,比如气温、降水等等。我有一个由邻里收集的关于食物消费、空气污染和所有其他变量的面板数据

我的问题是,我们是否可以使一个变量随时间而变化,也就是说,当勾号前进时,变量的值会发生变化。例如,代理可能会对其附近的空气污染作出反应,并改变其食物消费行为。我想为社区(斑块)建立一个“空气污染”变量,它会随着时间而变化(根据我收集的数据)。所以,不知何故,我想链接每个变量的文本文件,让net logo在勾号前进时读取它


有办法吗?非常感谢您的建议。

我不知道如何链接到一个文件,只需提取一个项目。这听起来像是访问一个数据库,而我看不到或不知道(只有我一个人)从netlogo到数据库系统的直接接口

比如说,有人可以使用Python编写这样的东西,并使用Python的接口提取所需的数据。或者,您也可以通过稍微调整再次使用R的界面,因为R确实有一些非常好的方法来读取CSV文件,并通过R中正确的智能语句逐项访问它们

写这两篇文章都很有趣。有人吗

如果没有这一点,您可以将所有数据读入NetLogo,然后填充列表(按勾号概念索引)(4或5个变量按勾号变化),然后使用NetLogo语句拉取按勾号索引的正确列表(加或减1,观察零对一索引)。当您需要时,然后解析该列表以从中提取变量。这肯定会奏效

今天下午我可能会写并发布这样一个列表解决方案列表。取决于天气。同时,这里有一个相关的例子,我写过一次,在一个CSV文件中读取变量,并将变量写入一些补丁程序自己的变量,这是您最需要的

我认为这段代码是有效的(当然有一个要读取的文件)


下面的示例代码从csv文件中读取时间序列数据,并将其放入列表列表中,以便稍后提取

extensions[csv]
全局[列表列表]
设置
清除所有
重置滴答声
;; 让最大行数读取3;;用于测试目的
文件关闭
;; 将斜杠加倍,以便在Windows计算机上工作
;; 设置当前目录“C:\\Users\\wades\\Documents\\netlogo\\countries”;
;; 但更简单的是,让用户导航到该文件
;; 文件打开“countries.csv”
让我的路径“?”
;; 设置当前目录用户目录
文件打开用户文件
让标题文件读取行
打印(word“有”列:“标题”);
让标题列表csv:来自行标题
让colcount长度标题列表
打印(word找到了这么多列:“colcount”)
让我0
重复colcount[
让我们决定第一项的标题
打印(单词“第i列”为“确定”)
集合i(i+1)
]
打印“====================================================”
;; 如果需要,请跳过行
;  让nextline文件读取行
;  打印(“跳过标题信息的第二行”)
;  打印下一行
;  打印“”
让行数为0
设置列表的列表[]
而[不是文件结尾?]
[
设置rowcount rowcount+1
;如果rowcount>max rows to read[打印”列表:“显示列表列表文件关闭停止]
让nextline文件读取行
让mydata csv:从下一行开始
打印“============================================================================”
打印(word“下一个要处理的输入行是:”下一行)
打印我的数据;
让我列出
项目0我的数据
项目1我的数据
项目2(数据)
设置列表列表lput onelist列表列表列表
]
显示列表列表
文件关闭;
结束
外带
让索引器滴答滴答;;也许你想要从刻度中减去一定量。
ifelse(索引器<列表长度列表)
[
让datalist项索引器列出列表
让时间项0数据列表
让临时项目1数据列表
让烟雾项目2数据列表
打印(word“At tick”indexer“处理此列表:”数据列表)
打印“屈服”:
打印(word“At tick”indexer“time=“time”temp=“temp”和smog=“smog”\n)
]
[
打印“全部完成。祝您愉快!”
]
打上钩
结束

非常感谢您的友好回答,它似乎对我的数据分析有用!!!我只是需要一些时间来消化你的代码一个接一个,因为我有点新的网络标志。我可以再问一次问题吗?非常感谢你的帮助。再次非常感谢你!!!
extensions [csv ]
globals [ XC YC ]
patches-own [
  country
  population
  emissions_mass
  vulnerability
  jetfuel_civilian
  climate_finance
]

to setup
  clear-all
  file-close
  ;; double the slashes so this works on a Windows computer
  ;; set-current-directory "C:\\Users\\wades\\Documents\\netlogo\\countries" ;
  ;; but simpler once just the let the user navigate to the file
  ;; file-open "countries.csv"
  let mypath "???"

  set-current-directory user-directory
  file-open user-file



  let headers file-read-line
  print (word "There are the columns: " headers);
  let headlist csv:from-row headers
  let colcount length headlist
  print (word "this many columns: " colcount)
  let i 0

  repeat colcount [
      let determ item i headlist
      print (word "column " i " is " determ)
      set i ( i + 1 )
    ]
  print "================================"

  let nextline file-read-line
  print ("skipping the second row of header info")
  print nextline
  print " "

  while [ not file-at-end?  ]
  [
    set nextline file-read-line
    let mydata csv:from-row nextline
    print "=============================================="
    print (word "next incoming line to process is: " nextline )
    print mydata;

    set XC item 1 mydata
    set YC item 2 mydata
    print (word " data for patch (" XC ", " YC " )" )

    let mytarget one-of patches with [ pxcor = XC and pycor = YC ]
    ask mytarget
     [
        set country           item 0 mydata
        set population        item 3 mydata
        set emissions_mass    item 4 mydata
        set vulnerability     item 5 mydata
        set jetfuel_civilian  item 6 mydata
        set climate_finance   item 7 mydata
        set pcolor blue
        set plabel country

     ]
    print " that patch should now be blue"


  ]

  file-close;
  reset-ticks
end


to go
  stop
  tick
end
extensions [csv ]
globals [ list-of-lists ]

to setup
  clear-all
  reset-ticks
 ;; let max-rows-to-read 3 ;; for testing purposes
  
  
  file-close
  ;; double the slashes so this works on a Windows computer
  ;; set-current-directory "C:\\Users\\wades\\Documents\\netlogo\\countries" ;
  ;; but simpler once just the let the user navigate to the file
  ;; file-open "countries.csv"
  let mypath "???"

 ;; set-current-directory user-directory
  file-open user-file



  let headers file-read-line
  print (word "There are the columns: " headers);
  let headlist csv:from-row headers
  let colcount length headlist
  print (word "Found this many columns: " colcount)
  let i 0

  repeat colcount [
      let determ item i headlist
      print (word "column " i " is " determ)
      set i ( i + 1 )
    ]
  print "================================"

;; skip lines if you need to 
;  let nextline file-read-line
;  print ("skipping the second row of header info")
;  print nextline
;  print " "

  let rowcount 0
 
  set list-of-lists [ ]
  
  while [ not file-at-end?  ]
  [
    set rowcount rowcount + 1
  ;  if rowcount > max-rows-to-read [ print "list of lists: " show list-of-lists file-close stop]
    
    let nextline file-read-line
    let mydata csv:from-row nextline
    print "=============================================="
    print (word "next incoming line to process is: " nextline )
    print mydata;

    
        let  onelist ( list 
               item 0 mydata
               item 1 mydata
               item 2 mydata )
      set list-of-lists lput onelist list-of-lists
     
      ]
 
  show list-of-lists
  file-close;
   
end


to go
  let indexer ticks ;; maybe you want this offset from ticks by some amount.
 
 
  ifelse ( indexer < length list-of-lists )
[
  let datalist item indexer list-of-lists
  let time item 0 datalist
  let temp item 1 datalist
  let smog item 2 datalist
  
  print (word "At tick " indexer " processing this list: " datalist )
  print "yielding: "
  print (word "At tick " indexer " time = " time " temp= " temp " and smog=" smog "\n")
]
  [
     print "All done. Have a nice day!"
  ]
 
 tick
end