Netlogo-给2个以上Turtles的Agentset,找到最常见的颜色

时间:2018-09-09 17:23:02

标签: netlogo agentset

给定两只或更多只乌龟的坐席,我该如何找到最常出现的颜色?

如果可能,我想做类似的事情:

Cannot call "myclass.xyz" because property "xyz" is missing in "MyClass" [1].

3 个答案:

答案 0 :(得分:1)

使用此示例设置:

to setup
  ca
  crt 10 [
    set color one-of [ blue green red yellow ]
  ]
  print most-frequent-color turtles 
  reset-ticks
end

您可以利用to-report过程来执行此操作-注释中的详细信息:

to-report most-frequent-color [ agentset_ ]
  ; get all colors of the agentset of interest
  let all-colors [color] of agentset_

  ; get only the unique values
  let colors-used remove-duplicates all-colors

  ; use map/filter to get frequencies of each color
  let freqs map [ m -> length filter [ i -> i = m ] all-colors ] colors-used

  ; get the position of the most frequent color (ties broken randomly) 
  let max-freq-pos position ( max freqs ) freqs 

  ; use that position as an index for the colors used
  let max-color item max-freq-pos colors-used

  report max-color
end

答案 1 :(得分:1)

还有两个选项,都使用select count(*), h.book_desc from native.authbill p join native.chg h on p.book_chg_id = h.book_chg_id where (p.aut_key in (select aut_key from native.authcodes p where p.auth_code in (74233, 23421) ) or p.aut_key in (select aut_key from native.pubisbn_proc pat where isbn_code in ('373423', '0256543', '0257535') ) ) and p.genre_code in (select chg.genre_code from native.chgset chg where chg.genre_desc in ('Sci-fi', 'Action', 'Rom-com') ) group by h.book_desc; 扩展名:

table

我不太确定我喜欢哪一个...

答案 2 :(得分:1)

您正在寻找modes原语(https://ccl.northwestern.edu/netlogo/docs/dictionary.html#modes):

one-of modes [color] of my_agentset

它是“模式”,复数形式,因为可能会有平局。打破平局的一种方法是使用one-of进行随机选择。