我是第一次在netlogo编程,所以我有点困难。我试图模拟一个土着社区,重点关注决定时间分配到不同的生产活动(农业和狩猎)。在整个模型中,将有人口统计过程(繁殖,死亡),农业和狩猎程序等的变化。现在我试图模拟婚姻和家庭分裂的动态,这样的工作:当人们结婚时,男性移动到女性的房子,成为家庭的一部分。当家庭变得过于庞大时,他们将家庭分成两部分。我成功地完成了这个部门并创建了一个新家庭,其中有一半成员(考虑到儿童和成人),但我不知道如何让这些人结婚。因此,我想知道的是:如果我随机选择已婚成员加入新家庭,我该怎样为配偶做呢?
到目前为止,我的代码就像这样(我只是以某种方式显示与节省空间的问题有关的部分)。
Breed [individuals individual]
Breed [households household]
undirected-link-breed [marriages marriage]
individuals-own [
id
sex
age
household-id
married?
mate-id
married-prob
]
households-own [
household-members
adult-members
child-members
]
patches-own [
class
]
to setup
clear-all
create-households hsdsinitial
[
setxy random-xcor random-ycor
set shape "house"
let number-individuals random-normal initial-mean-hsds-size 6
hatch-individuals number-individuals
[
ifelse random-bernoulli 0.5 ;; flip a coin
[ set sex "male" ]
[ set sex "female"]
set age max
(list 0 random-exponential 23)
if age > 97 [die]
set household-id myself
set married? false
]; end of hatch-individuals
]
do-marry
ask households [
set household-members individuals with [household-id = myself]
set adult-members household-members with [age >= 16]
set child-members household-members with [age < 16]
reset-ticks
end
to go
tick
if ticks >= years-to-simulate [stop]
do-marry
hshd-division
end
to do-marry
ask individuals with [ sex = "male" and not married?]
[
set married-prob (-0.028 * ln age + 0.1097)
]
ask individuals with [ sex = "female" and not married?]
[
set married-prob (-0.056 * ln age + 0.1998)
]
let bachelors individuals with [ not married? and age >= 16 and age <= 50]
ask bachelors with [ sex = "male" ] [
let potential-mates bachelors with [sex = "female" and household-id != [ household-id ] of myself]
if any? potential-mates [
if (random-float 1 <= married-prob and random-float 1 <= [married-prob] of one-of potential-mates) [
let mate one-of potential-mates
create-marriage-with mate
set household-id [ household-id ] of mate
set married? true
set mate-id mate
ask mate [set married? true
set mate-id myself
]
let destination-patch [patch-here] of household-id
move-to destination-patch
ask mate [hatch-individuals 1
[
ifelse random-bernoulli 0.5
[ set sex "male" ]
[ set sex "female"]
set age 0
set household-id [household-id] of myself
set married? false
]
]
]]]
end
to hshd-division
ask households
[ if ( count household-members) > max-hsds-member
[let my-childs n-of ( count child-members / 2 ) individuals with [household-id = myself]
let my-adults n-of ( count adult-members / 2 ) individuals with [household-id = myself]
let my-members (turtle-set my-childs my-adults)
create-new-hshd-from
my-members]
]
end
to create-new-hshd-from [my-members]
hatch-households 1
[
set household-members my-members
setxy random-xcor random-ycor
ask my-members
[set household-id myself
let mate individuals with [mate-id = one-of individuals with [household-id = myself]]
ask mate [set household-id [household-id] of myself]
let destination-patch [patch-here] of household-id
move-to destination-patch
]
]
end