我模擬NetLogo中的行人運動,並且無法從頭開始創建障礙避免算法。有在線算法,但不適合移動障礙物(其他行人)。另外,我的特工正在從他們的出生點(A點)移動到他們的目標(B點)。Netlogo,創建障礙避免算法
這是我的NetLogo算法:
globals [ wall walkway center dest ]
turtles-own [ gender goal velocity spawnpoint mid turn ]
to setup
clear-all
ask patches[
set wall patches with [
(pxcor > 3 and pycor > 3) or
(pxcor < -3 and pycor > 3) or
(pxcor < -3 and pycor < -3) or
(pxcor > 3 and pycor < -3)
]
set walkway patches with [
(pxcor > -4 and pxcor < 4) or
(pycor > -4 and pycor < 4)
]
set center patch 0 0
]
ask patches [
set pcolor black
]
ask walkway [
set pcolor 9
]
crt population [
set velocity 0.1
set mid 0
set gender random 2
if gender = 0 [set color red]
if gender = 1 [set color blue]
set spawnpoint random 4
if spawnpoint = 0 [ move-to one-of walkway with [not any? turtles-here and (pxcor < -11)]]
if spawnpoint = 1 [ move-to one-of walkway with [not any? turtles-here and (pycor > 11)]]
if spawnpoint = 2 [ move-to one-of walkway with [not any? turtles-here and (pxcor > 11)]]
if spawnpoint = 3 [ move-to one-of walkway with [not any? turtles-here and (pycor < -11)]]
set goal random 4
while [ goal = spawnpoint ] [ set goal random 4 ]
if spawnpoint != 0 and goal = 0 [set goal patch -16 0]
if spawnpoint != 1 and goal = 1 [set goal patch 0 16]
if spawnpoint != 2 and goal = 2 [set goal patch 16 0]
if spawnpoint != 3 and goal = 3 [set goal patch 0 -16]
]
reset-ticks
end
to decelerate
ifelse velocity > 0.01
[ set velocity velocity - 0.01 ]
[ rt 5 ]
end
to accelerate
if velocity < 0.1
[ set velocity velocity + 0.01 ]
end
to go
ask turtles [
ifelse patch-here != goal[
set turn random 2
if distance center < 3 [ set mid 1]
if mid = 0 [ set dest center ]
if mid = 1 [ set dest goal ]
face dest
ifelse any? other turtles-on patches in-cone 1.5 60
[ if any? other turtles-on patches in-cone 1.5 60
[ bk velocity
rt 90 ] ]
[ accelerate
face dest
fd velocity ]
]
[ die ]
]
end
這個仿真的模擬環境是一個交集:
http://imgur.com/nQzhA7g,R5ZYJrp#0
(對不起,我需要10個代表處,發佈圖片:()
圖1顯示了設置後的環境狀態圖2顯示了代理移動到他們的目標後發生了什麼(目標!= ir spawnpoint)。面對不同方向的代理商展示了經過中心代理商混亂的代理商,現在正在實現他們的目標。然而,中心的代理因爲我的算法而停留在那裏。當代理人數量更多時,模擬問題更加嚴重,這意味着他們只會在環境中心雜亂無章,而且在移動時只會出現口吃。
我基於我的算法http://files.bookboon.com/ai/Vision-Cone-Example-2.html。原諒我的算法,我在一週前開始在NetLogo中編程,直到現在我仍然沒有正確的編程思維。我確信有一個更好的方法來實現我的想法,但是,當我試圖想到許多實現時(但從未接近真實的事物),我感到沮喪。
P.S:這是我在StackOverflow中的第一篇文章/問題!我希望我的問題(和我提問的方式)不錯。
謝謝您花時間爲我的問題編寫算法,但我沒有提及黑色斑塊是牆壁,因此代理商可以旅行的唯一區域是白色斑塊。 我正在進行的模擬是在具有十字路口的基礎設施上的行人移動(以及在這種情況下可能增加一個環形道以改善行人運動)。 P.S:我真的很感謝你重寫了我發佈的代碼,我從你的代碼版本中學到了很多東西。 – Gannicus
我認爲避免牆壁是某些時候需要添加的東西,但我想給你一個建立基礎。提示:「任何? [pcolor = black] in-cone 1.5 60'的貼片會告訴你視錐中是否有壁。然而,總是向右轉可能不夠成熟,所以你可能需要在方向上變得更聰明。 ['towards'](http://ccl.northwestern.edu/netlogo/docs/dictionary.html#towards)原語應該可以幫助您實現這一目標。讓我們知道你想出什麼... –
謝謝!我會盡力在此建立。我仍然無法克服NetLogo開發人員回答我的問題的事實:)我非常感謝您的幫助。我將用我將提出的算法更新這篇文章。 – Gannicus