如何使用NetLogo 6.2公平分配海龟? [英] How to make an equitable distribution of turtles using NetLogo 6.2?

查看:0
本文介绍了如何使用NetLogo 6.2公平分配海龟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我在这里请求帮助:How to make an equal distribution of turtles for each profile type using NetLogo 6.2?

莉娜帮了我很多:)

但是,我对我想要的东西不是很精确,它部分地得到了解决。我试图调整Lena的响应方式,但我做不到,因为我陷入了非常类似的问题,我仍然不知道如何处理代码。

所以我的问题如下:

我有31个海龟概况,指的是5种类型的栖息地的组合。例如:

profile1: turtles are only born in habitat 1
profile2: turtles are only born in habitat 2
profile3: turtles are only born in habitat 3
profile4: turtles are only born in habitat 4
profile5: turtles are only born in habitat 5
profile6: turtles are only born in habitats 1 and 2
profile6: turtles are only born in habitats 1 and 3
... until you reach profile 31 where the turtles are born in habitats 1, 2, 3, 4 and 5

问题是我还有两个变量(新陈代谢(M)和生殖(R)),每个变量都有3个级别:

M1R1
M1R2
M1R3
M2R1
M2R2
M2R3
M3R1
M3R2
M3R3

我想要31个海龟配置文件的这9个组合。例如:

Perfil1 (turtles are only born in habitat 1):
M1R1
M1R2
M1R3
M2R1
M2R2
M2R3
M3R1
M3R2
M3R3

Perfil2 (turtles are only born in habitat 2): 
M1R1
M1R2
M1R3
M2R1
M2R2
M2R3
M3R1
M3R2
M3R3

... until you reach profile 31 where the turtles are born in habitats 1, 2, 3, 4 and 5:
M1R1
M1R2
M1R3
M2R1
M2R2
M2R3
M3R1
M3R2
M3R3

问题是我得到以下回报:

profile21: M1R1
profile17: M1R2
profile20: M1R3
profile17: M2R1
profile6: M2R2
profile26: M2R3
profile30: M3R1
profile7: M3R2
profile27: M3R3

但我希望的是31个图谱中每一个的新陈代谢和生殖变量的组合。例如:

profile1: M1R1
profile1: M1R2
profile1: M1R3
profile1: M2R1
profile1: M2R2
profile1: M2R3
profile1: M3R1
profile1: M3R2
profile1: M3R3

profile2: M1R1
profile2: M1R2
profile2: M1R3
profile2: M2R1
profile2: M2R2
profile2: M2R3
profile2: M3R1
profile2: M3R2
profile2: M3R3

... until you reach profile 31 
profile31: M1R1
profile31: M1R2
profile31: M1R3
profile31: M2R1
profile31: M2R2
profile31: M2R3
profile31: M3R1
profile31: M3R2
profile31: M3R3

有人能帮我了解如何解决这个问题吗?

提前感谢:)

代码如下:

globals [ AvailablePatch UnassignedProfileCountList ValidHabs ]

turtles-own [ metabolism reproduction code-metabolism code-reproduction all-code  turtle-profiles-habitat ]

patches-own [ turtle-count habitatcover ]


to setup
  clear-all
  random-seed 1  
  resize-world 69 * 0 ( 69 * 1 )  ( 69 * -1 ) 69 * 0 
  read
  setup-patches
  reset-ticks
  foreach sort turtles
                  [
                    t ->
                    ask t
                    [
                      print ( word "I am turtle:" " " who " "  "my profile type:" " " turtle-profiles-habitat " " "my code:" " " all-code " " "my code reproduction level:" " " code-reproduction " " "my code metabolism level:" " " code-metabolism )
                    ]
  ]
end

to read  
  set ValidHabs [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ]  
end


    
to-report get-any-incomplete-profile [ habtype ]
  let kkk 0
  let shortlist [ ]
  let validhablist [];

  repeat 30
  [
    set kkk ( kkk  + 1 ) 
    set validhablist item kkk ValidHabs
    
    if (
      (( item kkk UnassignedProfileCountList > 0 ) and (  true =  member? habtype validhablist ))
    )
    [
      set shortlist lput kkk shortlist
     
    ]
  ]

  let mypick -1
 
  ifelse ( 0 < length shortlist )
      [
        set mypick  item 0 (  n-of 1 shortlist )
        

        let oldcount item mypick UnassignedProfileCountList
        let newcount ( oldcount - 1 )
        set UnassignedProfileCountList replace-item mypick UnassignedProfileCountList newcount
  ]
  [
    set mypick -1
  ]
  report mypick
end


to setup-patches 

  let n 2 
  set AvailablePatch patches with [
    ( pxcor mod ( n + 1 ) = 0 ) and ( pycor mod ( n + 1 ) = 0 )   ]
  set UnassignedProfileCountList [ 0 ]  
  repeat 30 
  [
    set UnassignedProfileCountList lput 9 UnassignedProfileCountList
  ]

  let list1 ( list 2 4 8 )
  let list2 ( list 5 10 15 )

  (
    foreach list1
    [
      this-metabolism ->

      foreach list2
      [
        this-reproduction ->

        ask one-of AvailablePatch           
            [
              sprout 1
              [
                set turtle-profiles-habitat oneprofile
                set metabolism this-metabolism
                set reproduction this-reproduction

                setup-turtles
              ]
              set turtle-count count turtles-here
              set AvailablePatch other AvailablePatch 
            ]
          ]
        ]
      ]
    ]
  )
end


to setup-turtles   
   (
    ifelse
    metabolism = 2 [set code-metabolism "M1"]      
    metabolism = 4 [set code-metabolism "M2"]      
    metabolism = 8 [set code-metabolism "M3"]
  )
  (
    ifelse
    reproduction = 5 [set code-reproduction "R1"]
    reproduction = 10 [set code-reproduction "R2"]
    reproduction = 15 [set code-reproduction "R3"]
  )
  set all-code ( word code-metabolism code-reproduction )
  set color reproduction
  set pcolor metabolism
end 

推荐答案

同样,您有一个列表,并且希望为该列表与其他列表的每个组合创建特定数量的乌龟。因此,您可以使用Foreach循环:

foreach ValidHabs [
  this-profile ->
  ;code that should be run for every entry of ValidHabs
]

整个安装补丁功能:

to setup-patches 
  
  let n 2 ;; 20 meters away each turtle will be from another turtle
  set AvailablePatch patches with [
    ( pxcor mod ( n + 1 ) = 0 ) and ( pycor mod ( n + 1 ) = 0 )   ]
  set UnassignedProfileCountList [ 0 ]  ;; effectively start from item 1 not zero
  repeat 30 
  [
    set UnassignedProfileCountList lput 9 UnassignedProfileCountList
  ]
  
  let list1 ( list 2 4 8 )
  let list2 ( list 5 10 15 )
  
  (
    foreach ValidHabs [
      this-profile ->
      
      foreach list1
      [
        this-metabolism ->
        
        foreach list2
        [
          this-reproduction ->
          
          ask one-of AvailablePatch
          [ 
            sprout 1
            [
              set turtle-profiles-habitat this-profile
              set metabolism this-metabolism
              set reproduction this-reproduction
              
              setup-turtles
            ]
            set turtle-count count turtles-here
            set AvailablePatch other AvailablePatch ;this patch is no longer available
          ]
        ]
      ]
    ]
  )
end

这篇关于如何使用NetLogo 6.2公平分配海龟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆