0

我正在尝试获取单个进程的 who id(进程是乌龟),但我收到此错误:“cpu 0 不是 PROCESS 错误,而观察者运行 PROCESS。由过程 GO 调用。由按钮调用调用”

我需要这个 who 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

谢谢你的帮助

4

1 回答 1

1

该错误告诉您龟号 0 实际上是品种 cpu,而不是品种进程,但您的代码将其视为一个进程。我的猜测是,您的列表中返回的数字是 0,然后您说ask process 0NetLogo 告诉您没有“进程 0”。

这类问题就是为什么who在代码中使用数字通常是个坏主意。它们在您创建海龟时按顺序分配。与其who在列表中添加数字,不如简单地做一个海龟列表。

于 2019-09-09T07:25:34.033 回答