3

このコードは、Railsback の本 Agent-based and individual based-modeling by Railsback の第 16 章にありますが、機能せず、その理由もわかりません。私は NetLogo を初めて使用します。ソフトウェアは 22 行目に「予期されるキーワード」を表示します。 (create-packs)

breed [dogs dog]
breed [packs pack]
breed [disperser-groups disperser-group]

dogs-own
[
  age
  sex
  status
  my-pack
  my-disperser-group
]

packs-own [pack-members]

disperser-groups-own
[
  sex
  group-members
]

create-packs initial-num-packs
[
  ; set a location and shape just for display
  setxy random-xcor random-ycor
  set shape "box"

  ; create the pack’s dogs
  let num-dogs random-poisson initial-mean-pack-size

  hatch-dogs num-dogs
  [
    ; first, set display variables
    set heading random 360
    fd 1

    ; now assign dog state variables
    ifelse random-bernoulli 0.5
        [set sex "male"]
        [set sex "female"]

    set age random 7
    set-my-status ; a dog procedure that sets
                  ; social status from age
    set my-pack myself ; set dog’s pack to the one
                       ; creating it
  ] ; end of hatch-dogs

    ; Initialize the pack’s agentset that contains its dogs
  set pack-members dogs with [my-pack = myself]

  ; show count pack-members  ; Test output – off for now

  ; now select the alpha dogs
  update-pack-alphas  ; a pack procedure to give the
                      ; pack 2 alphas

] ; end of create-packs

to go

  tick
  if ticks > years-to-simulate [stop]

  ; First, age and status updates
  ask dogs
  [
    set age age + 1
    set-my-status
  ]

  ask packs [update-pack-alphas]

  ; Second, reproduction
  ask packs [reproduce]

  ; Third, dispersal
  ask packs [disperse]

  ; Fourth, mortality
  ask dogs [do-mortality]

  ; Fifth, mortality of collectives
  ask packs [do-pack-mortality]
  ask disperser-groups [if count group-members = 0 [die]]

  ; Sixth, pack formation
  ask disperser-groups [do-pack-formation]

  ; Finally, produce output
  update-output
end

to disperse ; a pack procedure
  ; First, identify the subordinates and stop if none
  let my-subordinates pack-members with
      [status = "subordinate"]
  if not any? my-subordinates [stop]

  ; Now check females
  if count my-subordinates with [sex = "female"] = 1
  [
    if random-bernoulli 0.5
    [
      create-disperser-group-from
             my-subordinates with [sex = "female"]
    ]
  ]

  if count my-subordinates with [sex = "female"] > 1
  [
    create-disperser-group-from
           my-subordinates with [sex = "female"]
  ]

  ; And check males
  if count my-subordinates with [sex = "male"] = 1
  [
    if random-bernoulli 0.5
    [
      create-disperser-group-from
             my-subordinates with [sex = "male"]
    ]
  ]

  if count my-subordinates with [sex = "male"] > 1
  [
    create-disperser-group-from
           my-subordinates with [sex = "male"]
  ]
end ; to disperse

to create-disperser-group-from [some-dogs]
  ; a pack procedure
  ; "some-dogs" is an agentset of the dispersers

  ; First, create a disperser group and put the dogs in it
  hatch-disperser-groups 1
  [
    ; Set disperser group variables
    set group-members some-dogs
    set sex [sex] of one-of some-dogs

    ; Display the group
    set shape "car"
    set heading random 360
    fd 2

    ; Now the disperser group sets the variables of the
    ; dispersing dogs
    ask some-dogs
    [
      set my-disperser-group myself
      set status "disperser"
      set color green

      ; and display them in a line from the disperser group
      move-to my-disperser-group
      set heading [heading] of my-disperser-group
      fd 1 + random-float 2
    ] ; end of ask some-dogs

  ] ; end of hatch-disperser-groups

  ; Finally, remove the dispersers from their former pack
  let dogs-former-pack [my-pack] of one-of some-dogs
  ask dogs-former-pack
  [set pack-members pack-members with
       [status != "disperser"]]

end ; to create-disperser-group-from

ありがとう

4

1 に答える 1

4

単語で手順を開始する必要がありtoますが、実際には NetLogo コマンドであるため、手順 create-packs を呼び出すことはできません。手元に本がありませんが、これが設定手順だと思います。おそらく次のように、前の行にプロシージャ名を追加します。

to setup
  create-packs initial-num-packs

また、各手順を単語で終了する必要がありますがend、これも欠落しています。さらに下は次のようになります。

end

to go

将来的には、ページ全体を入力するのではなく、コードのすべてのブロックの最後で構文チェック (緑色のチェックマーク) を行います。そうすれば、エラーがどこにあるのかがある程度わかり、入力した内容と本の内容を比較できます。

于 2016-05-12T09:04:16.617 に答える