Netlogo - 项目预期输入为字符串,但为零

时间:2018-02-03 22:19:04

标签: csv netlogo

这是与之前的帖子有关的后续问题Link我有16位笔记本电脑消费者的评论评分数据,这些评论要么满意(16人),要么不满意(6人)。它们被定义为海龟,它们可以通过询问布尔变量是否满足来区分?还是不满意?是真的。 enter image description here

数据集内容如下:

extensions [csv matrix array nw]

globals
[
  rowcounter
  csv 


 ii
  Sc-headings Bat-headings Pr-headings income-headings  average-headings; 

  Sc-set 
  Bat-set 
  Pr-set 

  prodcount ;num of producer agents

]

turtles-own [    
  turtle-Sc-list
  turtle-Bat-list
  turtle-Pr-list
  turtle-income-list
  turtle-average-list

  review-set 

  satisfied?
  dissatisfied?

  LapUtl-set 

  ScPWU
  BatPWU
  PrPWU
]

to setup
  clear-all
  file-close-all

  set rowcounter 1
  proddata
  readdataset
 reset-ticks
end

breed [ producers producer ]
to go

        Reviewrating
    end
to intlz
  set Sc-set []
  set Bat-set []
  set Pr-set []

end

阅读数据集:

to readdataset
  file-close-all ; close all open files
  file-open "turtle_details.csv"
  let headings csv:from-row file-read-line           ;header is read
  ; Splitting headings of the csv file into 5 categories representing screen 
  ; size data, battery charge data, Price data, income data, max age of an owner

  set Sc-headings sublist headings 2 7   
  set Bat-headings sublist headings 7 12
  set Pr-headings sublist headings 12 17
  set income-headings sublist headings 17 18
  set average-headings sublist headings 18 length headings

  while [ not file-at-end? ] [
  let data csv:from-row file-read-line

  create-turtles 1 [

       set shape "person"
       set size 2.5
       ifelse rowcounter <  11
      [
       set color 125
       set satisfied? true  
       set dissatisfied? false                                        ;                       
  ]
     ;else
      [
        set color 65

        set satisfied? false 
       set dissatisfied? true                                           ;                       
  ]


       setxy random-xcor random-ycor
       ; hide-turtle


       set turtle-Sc-list sublist data 2 7 
       set turtle-Bat-list sublist data 7 12
       set turtle-Pr-list sublist data 12 17

       set turtle-income-list sublist data 17 18
       set turtle-averageage-list sublist data 18 length data


  ]
  set rowcounter rowcounter + 1
   ]

  file-close-all
end

有3个制作人对屏幕,电池,价格有一些属性等级。

Sc  Bat Pr
24  10  18000
18  6   22000
30  8   26000

to proddata
  file-close-all ; close all open files

  if not file-exists? "Prodinitattr.csv" [
    user-message "No file 'Prodinitattr.csv' exists!"
    stop
  ]
  file-open "Prodinitattr.csv" ; open the file with the producers' initial attributes
  let headings csv:from-row file-read-line

  while [ not file-at-end? ] [
       let data csv:from-row file-read-line
       create-producers 1 [
       hide-turtle
       set producer? true   ; this agent is a producer
       set satisfied? false   ; this agent is not a referrer                                             ;                       REFERRERS
       set dissatisfied? false     ; this agent is not a pbuyer
       set prodcount prodcount + 1
     ;  set shape "house"
       setxy random-xcor random-ycor
       ]


       set Sc-set lput item 0 data Sc-set            
       set Bat-set lput item 1 data Bat-set
       set Pr-set lput item 2 data Pr-set


  ]
  file-close-all
end

应从数据集中提取的内容是对消费者(评论)的评估。每个消费者都有一个评论集,最初是一个空集[]。然后它将保留与三个生产者中每个生产者的三个评价值相对应的值。

to reviewrating

ask turtles   [

          set review-set []
     ]

 ask turtles [

          set ii 0
          while [ii < 3 ][
             set ScPWU turtle-Sc-rating item ii Sc-set
             set BatPWU turtle-Bat-rating item ii Bat-set
             set PrPWU turtle-Pr-rating item ii Pr-set


             set LapUtl-set lput (ScPWU  + BatPWU + PrPWU) LapUtl-set

             set ii ii + 1


        ] ; while

      ];ask

end
    to-report turtle-Sc-rating [Sc]

      let pos position Sc Sc-headings

      if  is-number? position Sc Sc-headings
          [
           let turt-Sc-rate-value item pos turtle-Sc-list
            report turt-Sc-rate-value
          ]

    end

    to-report turtle-Bat-rating [Bat]
      let pos position Bat Bat-headings
      if  is-number? position Bat Bat-headings
          [
           let turt-Bat-rate-value item pos turtle-Bat-list
            report turt-Bat-rate-value
          ]

        ;***************

    end
    to-report turtle-Pr-rating [Pr]
      let pos position Pr Pr-headings
      if is-number? position Pr Pr-headings
          [
           let turt-Pr-rate-value item pos turtle-Pr-list
            report turt-Pr-rate-value
          ]

    end

问题是由于错误我无法看到消费者的LapUtl向量。我之前报告过另一个错误,但我改变了写“go”程序的地方,现在错误标记了这一行:

let turt-Sc-rate-value **item** pos turtle-Sc-list

我该如何解决这个问题?

谢谢,

1 个答案:

答案 0 :(得分:2)

我怀疑您没有正确报告错误。我怀疑错误是ERROR: ITEM expected this input to be a string or list, but got a number instead。以下是产生此错误的方法示例:item 0 0。如果我是对的,那么您运行代码let turt-Sc-rate-value item pos turtle-Sc-list,而turtle-Sc-list的值为0。为了确认这一点,请用

替换此代码
ifelse (is-list? turtle-Sc-list)
  [let turt-Sc-rate-value item pos turtle-Sc-list]
  [error (word "turtle-Sc-list is not a list.")]

现在运行你的代码。如果它引发了错误"turtle-Sc-list is not a list.",那么您就可以搜索无法正确初始化此变量的方法。