我很难让“会员”正确地加入“家庭”。每个成员都有预定义的变量,'mbzone''abshid''abspid'和'absfid',有些成员可以拥有与这些预定义变量完全相同的值集。从同样的意义上说,家庭代理人可以为他们预先定义的'hhzone'和'abshid'拥有相同的价值观。
我想让会员代理通过以下代码中的给定条件加入家庭代理。但事实证明,一些家庭的[成员列表]并不仅包含具有独特“abspid”和“absfid”的成员代理。在家庭代理人的成员名单中的含义可能有成员具有相同的abspid和absfid。我的问题是如何防止这种情况发生?
提前谢谢你。对不起,如果我写的不清楚,我很乐意在必要时更详细地解释。
breed [members member]
breed [households household]
members-own [mbzone abshid abspid absfid]
households-own [hhzone abshid]
to members-join-households
ask members [
set hhid one-of households with [hhzone = [mbzone] of myself and abshid = [abshid] of myself and [abspid] of hhmemberlist != [abspid] of myself and [absfid] of hhmemberlist != [absfid] of myself]
ask hhid [
let newmember myself
set hhmemberlist (turtle-set hhmemberlist newmember)
]
]
output-print "member-join-households is done"
end
答案 0 :(得分:1)
@JenB说的是什么。额外的考虑因素:测试你找到了这样一个家庭。
breed [members member]
breed [households household]
members-own [mbzone abshid abspid absfid hhid]
households-own [hhzone abshid hhmemberlist]
to members-join-households
ask members [
let _pid abspid
let _fid absfid
set hhid one-of households with [
hhzone = [mbzone] of myself
and abshid = [abshid] of myself
and not member? _pid ([abspid] of hhmemberlist)
and not member? _fid ([absfid] of hhmemberlist)
]
if (hhid != nobody) [ ;did such a household exist?
ask hhid [
set hhmemberlist (turtle-set hhmemberlist myself)
]
]
]
output-print "member-join-households is done"
end
但与使用定向链接相比,以这种方式保留成员列表非常笨拙,因此我建议您切换到该列表。如果您的成员形成了指向家庭的有向链接,那么一个家庭的成员就是其中的邻居,而成员的hhid
就是它所链接的家庭。