【问题标题】:how to lineup the agents in the ascending or descending order of their who number in netlogo?如何在netlogo中按照他们的编号升序或降序排列经纪人?
【发布时间】:2018-03-16 14:05:17
【问题描述】:

我正在创建一个病人-外科医生-手术床模型,其中我需要显示在补丁左侧排队等待进入中心手术室的外科医生和右侧排队等候的患者。

我希望外科医生和患者按照他们的who 号码定位在补丁上

S1 S2 S3 --> 手术室

我使用下面的查询,我不确定在哪里加入 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

【问题讨论】:

  • 我是 netlogo 的新手,也尝试过使用列表,但无法按照 who number to lineup-patients let number-of-list 3 let patients-per 将它们排列在补丁上-list 7 let gapp 10 let jj 0 REPEAT initial-number-patients [ create-patients initial-number-patients [ SETXY ( 0 + jj * gapp ) 20 组组 [] ;空列表 set groups lput who ["number-of-list"] set shape "person" ] 询问患者 [ MOVE-TO ONE-OF PATCHES WITH [ PCOLOR = yellow ] SET color random 126 ] ] End
  • 好的。下次记得在每行代码前加 4 个空格来格式化你的代码。
  • 好的,谢谢

标签: netlogo agent


【解决方案1】:

你有一个move-to 在你排队之后。它总是移动所有现有的病人。为了让事情更整洁,请编写一个单独的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

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

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

【讨论】:

  • 非常感谢艾伦。它给排队的病人。我只是不明白 _xqs 和 [p x] 是什么,如果您能解释一下,将不胜感激。
  • _xqs 是排队患者的 x 轴位置。请参阅n-values 的文档。 [p x] 是循环中使用的局部变量(用于患者和 x 轴位置)。请参阅将foreach 与多个列表一起使用的文档。 Hth.
猜你喜欢
  • 2018-05-03
  • 1970-01-01
  • 2018-04-25
  • 2011-08-25
  • 2018-05-23
  • 2018-03-18
  • 2020-11-09
  • 2018-10-09
  • 2020-02-08
相关资源
最近更新 更多