2017-03-01 98 views
0

我有一個疑問,並道歉,如果答案是很明顯的。我創建了下面的代碼。很簡單&直截了當:秩序agentset代理商的不匹配

patches-own [ tl ls ls2 ls3 ls4 tsl] 
turtles-own [mysize] 

to setup 
    clear-all 
    reset-ticks 
    crt 5 
    ask turtles [ set heading random 360 jump random 20 set mysize random-float 1] 
    asd 
    inspect patch 0 0 
end 

to asd 
    let old sum [mysize] of turtles 
    ask patches [ set tl other turtles 
    set tsl [self] of tl 
    set ls [distance myself] of tl 
    set ls2 [distance myself^2] of tl 
    set ls3 [(mysize)/old] of tl 
    ] 
    ;print tl 

end 

to initial 
    set heading random 360 jump random 20 set mysize 1 
end 

to go 
    inspect patch 0 0 
    ask turtles [ fd 1 set mysize mysize + random-float 1] 
    let qwe random-float 1 
    print qwe 
    if qwe < 0.2 and count turtles > 2 [ask one-of turtles [die]] 
    if qwe > 0.8 [ ask one-of patches [sprout 1 [initial]]] 
    asd 
    tick 
end 

正如你所看到的,我在代碼中的檢查功能,下面是快照:

enter image description here 我的問題是,爲什麼是lsls2代理失靈。代理組TSL顯示了海龜的順序,所以不應該基於它創建的其他代理組遵循相同的順序。

回答

1

除非你以某種方式對它們進行排序,將的NetLogo以隨機的順序查詢代理於agentset。在功能上,ask tl遵循與ask turtles相同的邏輯,並且從代理集檢索變量也是如此。例如,如果您使用的指揮中心嘗試(運行您setupasd後)低於幾次的代碼,你會注意到,代理商的順序查詢是不是每次都一樣。

ask patch 0 0 [ print [distance myself] of tl ]

這一切說一個補丁的「TSL」列表的創建是獨立創作的其他名單的。它不是一個有序列表,它是從代理組「tl」隨機調用的烏龜列表。獲得一致的代理集排序的一種方法是使用sort原語之一。

+0

因此,在這種情況下,如果我不喜歡找到最小值龜在agentsets之一,採用'民一of'將它的問題,所有的agentsets不受類似的有序或會的NetLogo給我的一些操作正確的結果? – Yuvaraj

+0

只要您查詢代理集,就應該返回正確的結果 - 例如「詢問補丁0 0 [問我自己] [集合3]]」。另請注意,在您的示例屏幕截圖中,只有「tl」是一個代理程序集,其餘是列表 - 您以不同於代理程序集的方式查詢代理程序列表。 –

+0

既然你說只有'tl是一個agentset',其他的都是列表。如果我想在列表中的某個列表中找到具有「min」值的烏龜,則說'ls'我不能使用'lput'嗎?我可能能夠獲得列表中最小值的索引或「位置」,但是當我引用位置來識別代理集中的烏龜時,它會引發錯誤。例如'設置TL其他龜 組LS [距離自己^ 2] TL 組索引位置的(分鐘LS)ls'。直到這一點,它會工作,但是當我使用'lput item index tl'時。我會得到一個錯誤信息,詢問一個列表,而不是agentset – Yuvaraj