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



我有一个问题,我在这里寻求帮助:如何使用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

问题是我还有两个变量(新陈代谢(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

问题是我得到了以下回报:

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

最新更新