gpt4 book ai didi

netlogo - 预期关键字错误 - Netlogo

转载 作者:行者123 更新时间:2023-12-05 03:11:22 26 4
gpt4 key购买 nike

我从 Railsback 第 16 章的基于代理和基于个体的建模一书中获得了这段代码,但它不起作用,我也不知道为什么。我是 NetLogo 的新手,软件在第 22 行显示“Expected keyword”。(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

谢谢

最佳答案

您需要使用单词to 来启动一个过程,但是您不能调用一个过程create-packs,因为那实际上是一个NetLogo 命令。我手边没有这本书,但我怀疑这是安装程序。在上一行添加过程名称,大概是这样的:

to setup
create-packs initial-num-packs

您还需要以单词 end 结束每个过程,这也是缺失的。往下看应该是这样的:

end

to go

将来,在每个代码块的末尾进行语法检查(绿色勾号),而不是键入整个页面。这样您就知道错误在哪里,并且可以将您键入的内容与书中的内容进行比较。

关于netlogo - 预期关键字错误 - Netlogo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37176795/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com