读卡器,
我是NetLogo的初学者。请帮我解决以下代码中的一些问题:
其他人没有在抵达的接待处移动,到达分流正在运行。
to setup-people
set-default-shape turtles "person"
set destination ( patch-set patch -2 34 patch 8 34 )
create-turtles uninfected
[ set color blue
allocate-turtles
]
create-turtles infected
[ set color red
allocate-turtles
]
end
to allocate-turtles
if (pcolor = 9.9 and any? turtles-here)
[
set size 1.5
set heading 0
setxy int random-xcor int random-ycor
]
end
to go
move-people
arrive-reception
arrive-triage
go-drroom
tick
end
to move-people
ask turtles [
rt 360
forward 1
]
end
to arrive-reception
ask n-of (random count turtles) turtles
[
if windows = 1
[
move-to patch -2 34
ifelse not any? turtles-here
[ wait wait-time ]
[ wait-in-queue ]
]
]
end
to wait-in-queue
set arrival-time ticks
bk 1
if any? other turtles-here
[ wait-in-queue ]
wait wait-time
if ticks - arrival-time > wait-time
[ set arrival-time 0
fd 1 ]
end
to arrive-triage
if triage = "Open"
[
move-to patch 26 11
if any? other turtles-here
[ wait-in-queue]
wait wait-time
move-to one-of patches with [pcolor = 109 and not any? other turtles-here ]
wait wait-time
]
end
to go-drroom
move-to one-of patches with [pcolor = 128]
if ( min-one-of other turtles in-radius 5 [distance myself] != nobody)
[
move-to one-of patches with [pcolor = 129]
if ( min-one-of other turtles in-radius 5 [distance myself] != nobody)
[
move-to one-of patches with [pcolor = 5]
if any? seats with [turtles = nobody]
[
move-to one-of max-n-of 6 neighbors [seats]
]
]
]
wait wait-time
die
end
感谢。
答案 0 :(得分:1)
首先,一些基本的编程技巧 - 在尝试调试之前不要写这么多。如果你做了一个小的改动并检查它,那么很容易找出错误的位置。程序的初稿可以简单如下:
to go-drroom
end
然后填写稍后程序中发生的细节。
通常此错误是因为您忘记在某处关闭括号。也就是说,其中一个程序以ask turtles [ ...
开头并且没有]因此NetLogo仍然认为该代码适用于海龟。但是,我看不出明显的遗漏]。
但你确实有一个概念问题。 NetLogo中使用术语context
来指代谁要求代码完成以及向谁提出。所以ask turtles [ forward 1]
是观察者要求海龟移动并且是观察者上下文程序。在编写程序时,您没有考虑自己的上下文,这可能是导致错误的原因。
在go
程序中,您首先拨打move-people
。 [{1}}这样做(适当地)来自观察者上下文。然后你打电话给ask turtles [ ]
,也没关系。
但是,您仍然可以从观察者上下文中调用arrive-reception
和arrive-triage
,并拥有go-drroom
之类的命令。谁被要求搬家?你没有move-to
。另一方面,过程ask turtles ...
包含wait-in-queue
之类的命令,但它很好,因为它只能在move-to
过程中的ask turtles ...
内调用。