如何使用 NetLogo 6.2 公平分配海龟?

How to make an equitable distribution of turtles using NetLogo 6.2?

我有一个问题在这里寻求帮助:

Lena 帮了我很多 :)

但是,我对我想要的东西不是很精确,它已经部分解决了。我试图调整 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

问题是我还有2个变量(代谢(M)和繁殖(R)),每个变量有3个水平:

M1R1
M1R2
M1R3
M2R1
M2R2
M2R3
M3R1
M3R2
M3R3

我想要 31 个海龟轮廓的这九个组合。例如:

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

问题是我得到以下 return:

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