我正在尝试获取单个进程(进程是乌龟)的who id,但出现此错误:“ cpu 0不是观察者运行PROCESS时的PROCESS错误。由过程GO调用。由按钮go调用“
我需要这个谁的id,因为我希望,如果可能的话,只有队列的第一个进程(具有最高优先级的进程)才能到达cpu的“未采用”核心。
我发现当我要求单次处理进行指令时,就会出现错误。它不在乎什么动作(我试图改变指令)。问题是“询问进程N [...]”。
to go
if ticks > 0 and ticks mod 10 = 0 and number-of-processes < max-number-of-processes
[
create-processes 1[
set color green
set shape "square"
set size 2
set xcor 0
set ycor 0
]
;set whonumber [who] of process current-process --> it'doesn't work.. same error below
ask process current-process [set whonumber who ] ; --> current-proces is a variable that start to 0.. yeah i've tried also to put 0 instead.. doesn't work
set mylist lput one-of processes with[who = whonumber] mylist
set number-of-processes number-of-processes + 1
set current-process current-process + 1 ;verificare se quando muore un processo l'assegnazione sia sempre sequenziale oppure debba fare -1 in caso di die
]
;TO DO : MOVE THE SPAWNED PROCESS TO THE (turtle)QUEUE IF POSSIBLE
ask processes [show who]
if any? cores with [core-taken = false] and number-of-processes > 0 [
; ask cores with [xcor = ([xcor] of one-of other processes)] [set core-taken true] ---> doesn't work.. the comand face doesn't reach the same core coord...
ask processes with[ who = [who] of process item 1 mylist] [face unused-core forward 1] ; this action in the future will be done by the first project in the turtle queue
]
tick
end
感谢您的帮助
答案 0 :(得分:1)
错误告诉您0号海龟实际上是品种cpu,而不是品种进程,但是您的代码将其视为进程。我的猜测是,列表中返回的数字为0,然后说ask process 0
,然后NetLogo告诉您没有“进程0”。
这类问题就是为什么在代码中使用who
数字通常不是一个好主意的原因。在创建乌龟时会按顺序分配它们。列表中没有who
号,而是只列出了一些海龟。