Search code examples
netlogoschedulinground-robinmulti-agent

trying to get who id of a single <process> : "cpu 0 is not a <breed-name>. error while observer running <breed-name> "


i am trying to get the who id of a single process (the process is a turtle) but i got this error : " cpu 0 is not a PROCESS error while observer running PROCESS. Called by procedure GO. Called by button go"

i need this who id because i want that only the first process of the queue (the process with max priority) can reach the "not-taken" core of a cpu if possible.

i find out that the error comes out when i ask to a sinmgle process to do an istruction. it doesn't care what action is ( i've tried to change the istruction). The problem is "ask process 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

thanks for helping


Solution

  • The error is telling you that turtle number 0 is actually of the breed cpu, not of the breed process, but your code is treating it as if it is a process. My guess is that you have 0 as the returned number from your list, you then say ask process 0 and NetLogo is telling you there is no 'process 0'.

    This sort of problem is why it is generally a bad idea to use who numbers in your code. They are assigned sequentially as you create turtles. Instead of having who numbers in your list, simply do a list of turtles instead.