netlogo中的虚拟婚姻

netlogo中的虚拟婚姻,netlogo,Netlogo,在netlogo中,我模拟了一个群体,我希望16岁至50岁的个体随机与群体中的另一个个体结婚。每个人都有一个家庭id,我希望男性个人将其家庭id更改为他的“妻子”家庭id,但我不知道怎么做。现在我有了这个代码 ask individuals [ if not married? and sex = "male" and age >= 16 and age <= 50 [ let potential-mate one-of individuals with [

在netlogo中,我模拟了一个群体,我希望16岁至50岁的个体随机与群体中的另一个个体结婚。每个人都有一个家庭id,我希望男性个人将其家庭id更改为他的“妻子”家庭id,但我不知道怎么做。现在我有了这个代码

ask individuals [
  if not married? and sex = "male" and age >= 16 and age <= 50 [ 
    let potential-mate one-of individuals with [
      not married? and age >= 16 and age <= 50
      and sex = "female" and household-id != household-id
    ]
    if potential-mate != nobody [
      ; this command do an Bernoulli equation,
      ; the relation is based on empirical data i have
      ifelse random-bernoulli (- 0.765 * ln age + 2.9753) [
        stop
      ] [
        set my-mate potential-mate            
        set married? true            
        ask my-mate [ set married? true ]            
        ask my-mate [ set my-mate myself ]
      ]
    ]
  ]
]
询问个人[

如果没有结婚?和sex=“male”和age>=16和age=16和ageLuke C的评论是正确的:你需要的是,如:

话虽如此,我还是强烈建议将婚姻这样的东西作为一个模型。下面是一个有效的例子:

breed [individuals individual]
individuals-own [age sex household-id]

undirected-link-breed [marriages marriage]

to setup
  clear-all
  create-individuals 100 [
    set age random 100
    set sex one-of  ["male" "female"]
    set household-id random 100
    setxy random-xcor random-ycor
  ]
  marry-individuals
  reset-ticks
end

to marry-individuals
  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 not random-bernoulli (- 0.765 * ln age + 2.9753) [
        let mate one-of potential-mates
        create-marriage-with mate
        set household-id [ household-id ] of mate
      ]
    ]
  ]
end

to-report married? ; individual reporter
  report any? my-marriages
end

to-report my-mate ; individual reporter
  report [ other-end ] of one-of my-marriages
end
品种[个体]
个人拥有[年龄性别家庭id]
无向连接品种[婚姻]
设置
清除所有
创建个人100[
随机设定年龄100岁
将性别设置为[“男”“女”]
将住户id随机设置为100
setxy随机xcor随机ycor
]
个人结婚
重置滴答声
结束
个人结婚

让单身汉和个人[未结婚?和年龄>=16岁,如果你能编辑这个问题,那么代码的格式会更好一些,这将有助于人们理解它。看看字典条目中的示例,感谢所有三位的评论。我自己知道这个问题,但我没有想过如何在这个问题中使用。感谢尼古拉斯给我们的提示INing Link,我想它也会更好,我会尝试改变代码,这样它就工作了。关于家庭,他们实际上是代理,个人是从他们孵化出来的。但是我也会考虑这样做为链接。我知道编程和使用NETLogo,所以我多次不做最高效的代码!所以非常感谢你们。帮助
breed [individuals individual]
individuals-own [age sex household-id]

undirected-link-breed [marriages marriage]

to setup
  clear-all
  create-individuals 100 [
    set age random 100
    set sex one-of  ["male" "female"]
    set household-id random 100
    setxy random-xcor random-ycor
  ]
  marry-individuals
  reset-ticks
end

to marry-individuals
  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 not random-bernoulli (- 0.765 * ln age + 2.9753) [
        let mate one-of potential-mates
        create-marriage-with mate
        set household-id [ household-id ] of mate
      ]
    ]
  ]
end

to-report married? ; individual reporter
  report any? my-marriages
end

to-report my-mate ; individual reporter
  report [ other-end ] of one-of my-marriages
end