通过搜索Netlogo中的CSV标题行为turtles分配值
我有3个制片人。每个人都有200名购买笔记本电脑的海龟消费者。所有生产商都出售笔记本电脑。笔记本电脑有三种功能:屏幕大小、价格、电池寿命。每一个都有一定的层次。例如,电池寿命有5小时、12小时、24小时、30小时。每个制作人都有一些关于消费者如何根据他们在csv文件中的体验对这些物品进行评级的信息。CSV文件头是这样的: 消费者12 13 13.5 14 14.5 15 500 600 750 550 700 5 12 24 30 (以标题为例:12-15代表屏幕大小级别,500-700价格,5-30小时电池寿命) 每个生产者都需要分析存储在CSV文件中的数据。我使用库中的示例代码来使用csv文件,该文件创建了一个海龟,并使用item为其赋值通过搜索Netlogo中的CSV标题行为turtles分配值,csv,header,netlogo,agent-based-modeling,Csv,Header,Netlogo,Agent Based Modeling,我有3个制片人。每个人都有200名购买笔记本电脑的海龟消费者。所有生产商都出售笔记本电脑。笔记本电脑有三种功能:屏幕大小、价格、电池寿命。每一个都有一定的层次。例如,电池寿命有5小时、12小时、24小时、30小时。每个制作人都有一些关于消费者如何根据他们在csv文件中的体验对这些物品进行评级的信息。CSV文件头是这样的: 消费者12 13 13.5 14 14.5 15 500 600 750 550 700 5 12 24 30 (以标题为例:12-15代表屏幕大小级别,500-700价格,5
to read-turtles-from-csv
file-close-all ; close all open files
if not file-exists? "turtles.csv" [
user-message "No file 'turtles.csv' exists! Try pressing WRITE-TURTLES-TO-CSV."
stop
]
file-open "turtles.csv" ; open the file with the turtle data
; We'll read all the data in a single loop
while [ not file-at-end? ] [
; here the CSV extension grabs a single line and puts the read data in a list
let data csv:from-row file-read-line
; now we can use that list to create a turtle with the saved properties
create-turtles 1 [
if item 2 data > item 2 data ...
if item 7 data < item 8 data ...
]
]
file-close ; make sure to close the file
end
到目前为止,它运行得很好。但是,我需要使用标题。例如,我想创建一种情况,当用户选择一个数字时,如果它在其中一列中(在标题中),则该值被选中。否则,如果标头中不存在该值,则应执行其他操作。我可以让代码在使用代理时识别CSV头吗
谢谢
If item 2 > item 3 ...