Как исправить ошибку «Ничего не названо? Определено» в NetLogo 6.0.4 - PullRequest
0 голосов
/ 02 февраля 2019

Я загрузил модифицированный код случайных кластеров для генерации моделей нейтральных ландшафтов, используя версию модифицированного подхода случайных кластеров Миллингтона в общих моделях NetLogo.Когда я нажимаю кнопку «генерировать ландшафт», процедура «заливка ландшафта» в коде вызывает ошибку «Ничего не названо? Было определено».

Когда я создал прикрепленный образ интерфейса и попытался запустить приведенный ниже код.Похоже, проблема связана с вопросительным знаком в функции отчета «вхождения».Функция уменьшения не работает должным образом.Есть ли обходной путь для этого?См. Интерфейс, затем код ниже: enter image description here

  ifelse ( any? neighbours with [ cluster != nobody ] )  ;; check if there are any assigned patches in neighbourhood
  [

    let covers []

    ask neighbours with [ cluster != nobody ]
    [
      set covers fput cover covers    ;;ask neighbours to add their covers to the list
    ]

    let unique-covers remove-duplicates covers    ;;create a list of unique covers

    let max-cover-count -1                 ;the number of neighbours with the maximum cover
    let max-cover -1                       ;the maximum cover

    ifelse(length unique-covers > 1)
    [
      ;if there is more than one unique-cover
      foreach unique-covers                  ;for each of the unique covers
      [
        let occ occurrences ? covers          ;count how many neighbours had this cover

        ifelse(occ > max-cover-count)        ;if the count is greater than the current maximum count
        [ 
          set max-cover ?                    ;set this as the dominant cover
          set max-cover-count occ            ;update the current maximum count

;---------------

to-report occurrences [x the-list]
  report reduce
    [ifelse-value (?2 = x) [?1 + 1] [?1]] (fput 0 the-list)
end 
;---------------    

Предполагается, что код генерирует нейтральную модель ландшафта с использованием подхода модифицированных случайных кластеров, разработанного Saura и Martinez-Millan (2000 г.).).Тем не менее, ошибка «Ничего не названо? Был определен» ошибка код работает неправильно.Ждем мыслей ...

Ответы [ 2 ]

0 голосов
/ 04 февраля 2019

Сочетание ответа Брайана (первая процедура) и словаря NetLogo (вторая процедура) дает вам следующее.Комментарии указывают на новые биты.Не проверено.

ifelse ( any? neighbours with [ cluster != nobody ] )
[ let covers []
  ask neighbours with [ cluster != nobody ]
  [ set covers fput cover covers
  ]
  let unique-covers remove-duplicates covers
  let max-cover-count - 1  ; added a space around subtraction
  let max-cover - 1        ; more spacing
  ifelse(length unique-covers > 1)
  [ foreach unique-covers
    [ this-cover ->                  ; here's the new bit, calling ? 'this-cover'
      let occ occurrences this-cover covers ; passes to the occurrences procedure
      ifelse(occ > max-cover-count)
      [ set max-cover this-cover     ; using the name this-cover again
        set max-cover-count occ

А для случаев можно выполнить процедуру непосредственно из словаря NetLogo reduce пример

to-report occurrences [#x #the-list]
  report reduce
    [ [occurrence-count next-item] -> ifelse-value (next-item = #x)
        [occurrence-count + 1] [occurrence-count] ] (fput 0 #the-list)
end
0 голосов
/ 02 февраля 2019

Старый синтаксис ? из NetLogo 5.x был заменен новым синтаксисом -> в NetLogo 6. См. https://ccl.northwestern.edu/netlogo/docs/programming.html#anonymous-procedures

Так, например, в NetLogo 5 вы должны написать:

foreach [0 1 2 3] [
  print ?
]

в NetLogo 6, вы пишете:

foreach [0 1 2 3] [ x ->
  print x
]
...