我想模擬NetLogo中的特定交叉點。這裏是代碼(在開發的早期階段):Netlogo - 如何創建路徑?
breed [ trams tram ]
breed [ cars car ]
to setup
clear-all
set-default-shape trams "bug"
set-default-shape cars "car"
setup-patches
reset-ticks
end
to go
make-new-car frequency-SN-1 1 -20 0
make-new-car frequency-SN-2 2 -20 0
make-new-car frequency-NS-3 -3 20 180
setup-trams tram-frequency
move-trams
want-turn
move-cars
tick
end
to setup-trams [ freq ]
if (random-float 100 < freq) and not any? turtles-on patch 0 -20 [
create-trams 1 [
setxy 0 -20
set heading 0
set color black
]
]
end
to make-new-car [freq x y head ]
if (random-float 100 < freq) and not any? turtles-on patch x y [
create-cars 1 [
setxy x y
set heading head
set color one-of base-colors
]
]
end
to move-cars
ask cars [
ifelse not can-move? 1
[ die ]
[ fd 1 ]
]
end
to want-turn
ask cars-on patch 2 -7 [
ifelse (random-float 100 < 100) and not any? turtles-on patch 3 -7
[ rt 90 fd 1
lt 90 fd 4
rt 90 fd 2
lt 90 fd 2
rt 90 fd 1]
[ fd 1 ]
]
end
to move-trams
ask trams [
ifelse not can-move? 1
[ die ]
[ fd 1 ]
]
end
to setup-patches
ask patches [
ifelse abs pxcor <= 3 or abs pycor <= 3
[ set pcolor black ]
[ set pcolor green - 1 ]
ifelse abs pxcor <= 0.5
[ set pcolor red ]
[ ]
ask patch 3 -2 [ set pcolor red ]
ask patch -2 -1 [ set pcolor red ]
ask patch -1 -1 [ set pcolor red ]
if pycor = -3 and pxcor > 8
[ set pcolor green - 1 ]
if pycor <= 3 and pycor >= -1 and pxcor < -3
[ set pcolor green - 1 ]
if pxcor = 3 and pycor <= -8
[ set pcolor green - 1 ]
]
end
是什麼導致我的問題是需要轉彎過程。我想要一些汽車向右和向東移動。不過,我不能,直到現在(剛剛開始使用NetLogo)以不同的方式做 - 它只是爲了讓汽車在特定的補丁上消失並重新出現在另一個補丁上(這完全是由於在轉入程序中運行的轉彎過程造成的。它每次都會運行,但在轉彎時我會移動很多補丁,所以它看起來像傳送)。
我可以在那裏創造道路嗎?因此,不是將車輛手動移動到另一個補丁上,而是問這輛車是否符合特定補丁的條件(在這種情況下:補丁2-7),如果是 - 它會移動替代路。
我剛剛發現的NetLogo任何想法,歡迎來做到這一點
嗨SCAG,檢查出的[指南](http://stackoverflow.com/help/ mcve)來提高你獲得有意義答案的機會。我無法按照原樣運行你的代碼來重現你的模型(我認爲需要在界面上輸入一些內容),所以很難準確地告訴你後面的內容。 –
頻率-SN-1, 頻率-SN-2, 頻率-NS-3和有軌電車頻率是從1到100的接口值 - 它們僅表示按功能創建的每個時鐘的汽車數量make-new-car – scagbackbone
不夠公平 - 我的意思是說,讓你的問題重現得越容易,你就越有可能在Stack Overflow上獲得有用的答案。通常這意味着要剪掉與你的問題無關的東西;例如,有軌電車和不重要的汽車,在這種情況下。 –