Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Netlogo 如何更新用于在循环中选择海龟的比例?_Netlogo - Fatal编程技术网

Netlogo 如何更新用于在循环中选择海龟的比例?

Netlogo 如何更新用于在循环中选择海龟的比例?,netlogo,Netlogo,在我的模型中,海龟有两种性别,有两种潜在的策略“0”和“1”。雌性在一个设定的半径内计算雄性的数量,并根据它们的策略在该池中进行选择 雌性对它们的潜在配偶池有一个限制,它们根据自己的策略在这个池中循环选择雄性。这都在选择过程中 一位同事注意到的一个问题是,每次雌性选择另一个配偶时,下面的代码行都应该更新,以便该比例反映剩余的潜在配偶,而不是在循环之外设置的n-max set prop_B(使用[strategy=0]统计可用雄性)/n-max 为清楚起见,如果n-max为5,并且一只雌性设置了p

在我的模型中,海龟有两种性别,有两种潜在的策略“0”和“1”。雌性在一个设定的半径内计算雄性的数量,并根据它们的策略在该池中进行选择

雌性对它们的潜在配偶池有一个限制,它们根据自己的策略在这个池中循环选择雄性。这都在
选择过程中

一位同事注意到的一个问题是,每次雌性选择另一个配偶时,下面的代码行都应该更新,以便该比例反映剩余的潜在配偶,而不是在循环之外设置的
n-max

set prop_B(使用[strategy=0]统计可用雄性)/n-max

为清楚起见,如果
n-max
为5,并且一只雌性设置了
prop_B
,则在循环的下一次迭代中
n-max
应以1为准,因为只剩下4只雄性

所以它应该是这样的:
set prop_B(使用[strategy=0]计算可用雄性数量)/n-max-已选择计数配偶)

请参见下面的模型工作示例。希望你能帮忙

turtles-own [sex availa-males mates mate-count max-mate-count strategy n-max prop_B proba_B] 
breed [males male]
breed [females female]
to setup
clear-all
  create-males 50
  create-females 1
  ask turtles [
  setxy random-xcor random-ycor
  ifelse random 2 = 1 [set strategy 1] [set strategy 0]  
   ]

  ask males [set color red]
  ask females [set color blue]
 reset-ticks 
end 

to go 
  ask males [
 ; fd 1
    ]
  ask turtles [
  set mates ( turtle-set ) 
  ]
  ask females [choose]
  tick
end 

to choose

    ; set a cap on possible mates for females; 5, or the number
    ; available within the radius if less than 5
  set availa-males males in-radius 5
    set n-max count availa-males
    set max-mate-count ifelse-value ( n-max < 5 ) [ n-max ] [ 5 ] ; 5 5

; Until a female has chosen up to her maximum number of mates:
  while [ mate-count < max-mate-count ]

     [; determine which available males are not already in her 'mates' agentset
      set availa-males availa-males with [ not member? self [mates] of myself ]

; assess the proportion of the '0' strategy in remaining available males
      set prop_B ( count availa-males with [ strategy = 0 ] ) / n-max

      ; example probability choice, just meant to choose '0 strategy' males
      ; with a frequency disproportionate to availability
      set proba_B ifelse-value ( prop_B <= 0.1 ) [ 0.8 ] [ 0.2 ] 

      ; use a random float to determine which strategy type is chosen
      set mates ( turtle-set mates
        ifelse-value ( random-float 1 < proba_B )
        [ one-of availa-males with [ strategy = 0] ]
          [ one-of availa-males with [ strategy = 1]] )

      ; count the current mates to break the while loop once
      ; the maximum number of mates is reached
      set mate-count count mates
    ]     
  ; have the female's males add her to their own mates agentset
    ask mates [ set mates ( turtle-set mates myself ) ]

    if n-max < count mates [ print  "Fewer available males than mates" ]
end 
海龟拥有[性可用雄性配偶数量最大配偶数量策略n-max prop_B proba_B]
品种[雄性]
繁殖[雌性]
设置
清除所有
创造男性50
创造女性1
问海龟[
setxy随机xcor随机ycor
ifelse random 2=1[设置策略1][设置策略0]
]
询问雄性[设置红色]
询问女性[设置蓝色]
重置滴答声
结束
外带
询问男性[
;fd 1
]
问海龟[
套装(海龟套装)
]
询问女性[选择]
打上钩
结束
选择
; 为雌性可能的配偶设定上限;5,还是号码
; 如果小于5,则在半径范围内可用
将Avila雄性设置在半径5内
设置可用的n最大计数
设置最大交配计数ifelse值(n-max<5)[n-max][5];5 5
; 直到雌性选择了最多数量的配偶:
而[配对计数<最大配对计数]
[;确定哪些可用的雄性不在她的“配偶”代理集中
用[非成员?我自己[配偶]设置Avila males Avila males]
评估“0”策略在剩余可用男性中的比例
设置属性B(使用[strategy=0]统计可用雄性)/n-max
;示例概率选择,仅用于选择“0策略”男性
;频率与可用性不成比例

设置proba_B ifelse值(prop_B由于您不需要按顺序选择它们,那么您应该考虑的一个选项是
rnd
扩展中的
n-of
的加权等价物。下面的代码是一个使用加权选择的完整模型,向您展示了它是如何工作的。但它不会给出与您的方法完全相同的结果。你的数学基本上是根据每种选择的比例来选择一种或另一种。我认为这可能对你有用,因为权重只是不成比例的证明

extensions [rnd]

turtles-own
[ sex
  mates
  strategy
] 
breed [males male]
breed [females female]

to setup
  clear-all
  create-males 50 [set color red set sex "M"]
  create-females 1 [set color blue set sex "F"]
  ask turtles
  [ setxy random-xcor random-ycor
    set strategy one-of [1 0]
    set mates nobody
  ]
  reset-ticks 
end 

to go 
  ask males
  [ ; fd 1
  ]
  ask females [choose]
  tick
end 

to choose
  let availa-males males in-radius 5
  let max-mate-count min (list 5 count availa-males)
  if max-mate-count < 5 [ print  "Fewer available males than mates" ]
  let new-mates rnd:weighted-n-of max-mate-count availa-males [ strategy-weight strategy ]
  set mates (turtle-set mates new-mates)
  ask new-mates
  [ set mates (turtle-set mates myself)
  ]
end

to-report strategy-weight [ #strategy ]
  if #strategy = 1 [ report 0.2 ]
  if #strategy = 0 [ report 0.8 ]
  report 0
end
extensions[rnd]
乌龟自己的
[性别
伴侣
策略
] 
品种[雄性]
繁殖[雌性]
设置
清除所有
创建男性50[设置颜色红色设置性别“M”]
创建女性1[设置颜色蓝色设置性别“F”]
问海龟
[setxy random xcor random ycor
将策略设置为[10]中的一个
谁也别跟谁约会
]
重置滴答声
结束
外带
询问男性
[;fd 1
]
询问女性[选择]
打上钩
结束
选择
让Avila雄性在半径5内
让最大配偶数最小(列出5只可用雄性)
如果最大交配数<5[打印“可用雄性数量少于配偶”]
让新配偶rnd:availa雄性最大配偶数的加权n[策略权重策略]
组合伙伴(乌龟组合伙伴新伙伴)
问新朋友
[团队伙伴(乌龟团队伙伴)
]
结束
报告战略权重[#战略]
如果#策略=1[报告0.2]
如果#策略=0[报告0.8]
报告0
结束

你会注意到我还删除了一堆
海龟
变量。你不需要有一个永久变量,只需要用
let
创建一个临时变量。我也注意到你作为海龟变量进行了性行为,但你实际上是在处理不同品种的性行为,但我留下它只是为了防止它有其他用途。

你不需要按顺序选择它们,那么你应该考虑的一个选项是来自
rnd
扩展的
n-of
的加权等价物。下面的代码是一个使用加权选择的完整模型,向你展示它是如何工作的。但它不会给出与你的方法完全相同的结果。你的数学basically会根据每个选项的比例来强制选择一个或另一个选项。我认为这可能对你有用,因为权重只是不成比例的证明

extensions [rnd]

turtles-own
[ sex
  mates
  strategy
] 
breed [males male]
breed [females female]

to setup
  clear-all
  create-males 50 [set color red set sex "M"]
  create-females 1 [set color blue set sex "F"]
  ask turtles
  [ setxy random-xcor random-ycor
    set strategy one-of [1 0]
    set mates nobody
  ]
  reset-ticks 
end 

to go 
  ask males
  [ ; fd 1
  ]
  ask females [choose]
  tick
end 

to choose
  let availa-males males in-radius 5
  let max-mate-count min (list 5 count availa-males)
  if max-mate-count < 5 [ print  "Fewer available males than mates" ]
  let new-mates rnd:weighted-n-of max-mate-count availa-males [ strategy-weight strategy ]
  set mates (turtle-set mates new-mates)
  ask new-mates
  [ set mates (turtle-set mates myself)
  ]
end

to-report strategy-weight [ #strategy ]
  if #strategy = 1 [ report 0.2 ]
  if #strategy = 0 [ report 0.8 ]
  report 0
end
extensions[rnd]
乌龟自己的
[性别
伴侣
策略
] 
品种[雄性]
繁殖[雌性]
设置
清除所有
创建男性50[设置颜色红色设置性别“M”]
创建女性1[设置颜色蓝色设置性别“F”]
问海龟
[setxy random xcor random ycor
将策略设置为[10]中的一个
谁也别跟谁约会
]
重置滴答声
结束
外带
询问男性
[;fd 1
]
询问女性[选择]
打上钩
结束
选择
让Avila雄性在半径5内
让最大配偶数最小(列出5只可用雄性)
如果最大交配数<5[打印“可用雄性数量少于配偶”]
让新配偶rnd:availa雄性最大配偶数的加权n[策略权重策略]
组合伙伴(乌龟组合伙伴新伙伴)
问新朋友
[团队伙伴(乌龟团队伙伴)
]
结束
报告战略权重[#战略]
如果#策略=1[报告0.2]
如果#策略=0[报告0.8]
报告0
结束
你会注意到我还删除了一堆
turtle
变量。