how to lineup the agents in the ascending or descending order of their who number in netlogo?

*爱你&永不变心* 提交于 2019-12-12 04:43:42

问题


I am creating an patient-surgeon-operation bed model, wherein I need to show surgeons lined up on the left side of patch awaiting to enter operation room in the center and the patients awaiting in the queue from the right side.

I want the surgeons and patients to be located on the patch as per their who number

S1 S2 S3 --> Operation room < -- P1 P2 P3

I use the below query, I am not sure where to incorporate the who number

to lineup-patients
  LET gapp 10                    
  LET directions 
  [45 90 230 180 45 90 230 180 45 90 45 90 230 180 45 90 230 180 45 90 45 90 ]
  LET jj 0                        ; counter / index
  REPEAT initial-number-patients
  [ create-PATIENTS 1
    [  SETXY (0 + jj * gapp) 20
      set shape "person"
      SET size 1.2
      SET label who
      SET label-color black
      SET heading item jj directions
    ]
    SET jj jj + 1
    ASK patients [
      MOVE-TO ONE-OF PATCHES WITH [ PCOLOR = yellow ]
  ] ]
END

回答1:


You have a move-to after you line them up. And it always moves all existing patients. To keep things cleaner, write a separate lineup proc.

to lineup [#patients #patch #gap]
  let _x ([pxcor] of #patch)
  let _y ([pycor] of #patch)
  let _xqs n-values (count #patients) [[n] -> _x + n * #gap]
  (foreach sort #patients _xqs [
    [p x] -> ask p [setxy x _y]
  ])
end

You can test this with a new instance of NetLogo as follows:

to test
  ca
  crt 20
  lineup turtles one-of patches 0.5
end


来源:https://stackoverflow.com/questions/46577394/how-to-lineup-the-agents-in-the-ascending-or-descending-order-of-their-who-numbe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!