2014-03-28 52 views
2

我正在Netlogo中開發模型。我的模特里有很多代理人。每個代理商都必須擁有無線電範圍。兩個代理可以相互通信,並將它們放置在一個共同的作用域中時傳輸一些關鍵數據。代理之間在Netlogo中的通用範圍內通信數據

想象一下,我有100個具有5px範圍的代理和200個具有3px範圍的代理。我也有1位主要代理人在這個詞中移動。這個主代理也有一個範圍(例如7px)。代理商可以在共同範圍內進行溝通。當他們溝通時,他們可以傳輸他們的一些數據。首先只有主代理有這個關鍵數據,只有主代理可以傳輸這些重要數據。但是,在將數據傳輸到其他代理之後,具有此數據的其他代理也可以傳輸此數據。重要的條件是在共同的範圍內。

我該怎麼做?

謝謝

回答

3

你只是給你的問題的一個非常籠統的說法。如果您努力實際開始實施並詢問您遇到的更具體的困難,您將得到更好的答案。

這就是說,我做了一個小模型,或多或少符合您的描述。也許它可能對你有用,作爲一個起點,如果你有一些問題,你可以提出單獨的(更確切的)後續問題。

turtles-own [ scope data ] 

to setup 
    clear-all 
    ; make a big world so agents don't 
    ; bump into one another right away: 
    resize-world -100 100 -100 100 
    set-patch-size 3 
    ; create turtles and distribute them around: 
    crt 100 [ set scope 5 set data "" ] 
    crt 200 [ set scope 3 set data "" ] 
    crt 1 [ set scope 7 set data "important data" ] 
    ask turtles [ 
    set size 3 
    setxy random-xcor random-ycor 
    recolor 
    ] 
end 

to go 
    ask turtles [ travel ] 
    ask turtles with [ not empty? data ] [ share-info ] 
    ask turtles [ recolor ] 
end 

to travel 
    ; you haven't specified how turtles should move 
    ; so here's a classic "wiggle": 
    rt random 30 
    lt random 30 
    fd 1 
end 

to share-info 
    ask other turtles in-radius scope with [ empty? data and distance myself < scope ] [ 
    set data [ data ] of myself 
    ] 
end 

to recolor 
    set color ifelse-value empty? data [ grey ] [ red ] 
end 

編輯:

繼賽斯的評論,我的第一個版本可能沒有捕捉共同範圍的想法,我已經添加and distance myself < scope。這樣,只有看到彼此可以共享信息的龜。

當我問海龜分享信息時,我還增加了一個with [ not empty? data ]條款,因爲沒有用空白數據的海龜分享它。

+0

我不認爲這抓住了「共同的範圍」部分。如果我理解正確,A可以看到B是不夠的; B也必須能夠看到A.阿里,那是對的嗎? –

+0

這很可能是正確的。我編輯了我的答案。 –

+0

謝謝尼古拉斯,我正在處理你的答案,我會告訴你結果 –