如何在netlogo中按其编号的升序或降序排列代理? [英] how to lineup the agents in the ascending or descending order of their who number in netlogo?

查看:159
本文介绍了如何在netlogo中按其编号的升序或降序排列代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个病人-外科手术床模型,其中我需要显示在贴片的左侧排队等待进入中心手术室的病人以及从右侧排队等待排队的病人. /p>

我希望外科医生和患者按照他们的who编号位于贴片上

S1 S2 S3->手术室< -P1 P2 P3

我使用下面的查询,我不确定在哪里包含电话号码

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

解决方案

排列它们后,您会得到一个move-to.它总是移动所有现有的患者.为了保持环境清洁,请编写一个单独的lineup处理程序.

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

您可以使用NetLogo的新实例对此进行测试,如下所示:

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

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

解决方案

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

这篇关于如何在netlogo中按其编号的升序或降序排列代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆