首页 > 解决方案 > 如何使本地列表在程序中起作用?

问题描述

我希望全局列表患者列表保持不变,因此我想在 de procedure 中创建一个本地列表to call-up-patients。我希望最年长的患者首先与医生预约,然后,我希望最年长的患者将自己从本地列表中删除,以便呼叫下一个最年长的患者尝试创建预约。我添加了两个额外的 ifelse 功能,因为如果最年长患者的医生不在,第二大患者可以尝试与其医生预约。

下面的代码不起作用。但是,如果我更改set patientlist remove-item 0 patientlistset patientSlist remove-item 0 patientlist,它可以工作。但我不想改变全球患者名单。请注意,patientSlist(带有 S)是全局列表,而 patientlist 应该是本地列表。

有没有人看到错误?

breed [patients patient]
breed [doctors doctor]

globals [
patientslist
]

patients-own [
  age
]

to setup

setup patients

end


to setup-patients
create-patients number-patients [
    set age 1 + random 99
]
  set patientslist sort-on [(- age)] patients

end

to call-up-patients

   let patientlist patientslist

  ask doctors [

     if CurHour = 0 and CurMinute = 0 [set vaccinations-on-planning-this-day 0
                                      set vaccinations-done-today 0
                                      ask patients [set appointment? false]
                                      ask appointments [die] ]
    if (vaccinations-on-planning-this-day + vaccinations-done-today) < injection-capacity [ set available? true]
  ]

   if length patientlist != 0 [ ask item 0 patientlist [
    ifelse appointment? = true and [available?] of my-doctor = true
    [
      create-appointment-with my-doctor set color black set patientlist remove-item 0 patientlist ][if length patientlist >= 2 [ask item 1 patientlist [
    ifelse appointment? = true and [available?] of my-doctor = true
    [
          create-appointment-with my-doctor set color black set patientlist remove-item 1 patientlist ][if length patientlist >= 3 [ask item 2 patientlist [
    if appointment? = true and [available?] of my-doctor = true
    [
              create-appointment-with my-doctor set color black set patientlist remove-item 2 patientlist ] ]]]]]]]]
end
'''

标签: netlogo

解决方案


推荐阅读