netlogo - 如何使本地列表在程序中起作用?
问题描述
我希望全局列表患者列表保持不变,因此我想在 de procedure 中创建一个本地列表to call-up-patients
。我希望最年长的患者首先与医生预约,然后,我希望最年长的患者将自己从本地列表中删除,以便呼叫下一个最年长的患者尝试创建预约。我添加了两个额外的 ifelse 功能,因为如果最年长患者的医生不在,第二大患者可以尝试与其医生预约。
下面的代码不起作用。但是,如果我更改set patientlist remove-item 0 patientlist
为set 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
'''
解决方案
推荐阅读
- android - 使用手势或触摸事件旋转节点 Sceneform AR Core
- oracle - 选择时间跨度覆盖特定时间的所有行
- c++ - 提升随机输出从 1.58 到 1.67 的已知差异?
- swift - Xcode Swift 如何访问自定义对象?
- c# - 使用实体类型生成器允许外键为空
- twitter-bootstrap - 启用 scrollX 时,包含按钮下拉列表的行会导致垂直滚动
- x86 - 发送到未处于等待 SIPI 状态的活动 AP 的启动 IPI 会发生什么情况
- python - 如果在递归函数中发生异常,Python 返回 NoneType
- css - Wordpress 中的菜单按钮/文本与粘滞菜单不对齐
- c# - 将 curl --form 转换为 C#