我創建了一個小型無向網絡,其中一些節點作爲源,一些作爲目標。然後我創建了放在源節點上的步行者。 現在,我想要使用這個網絡實現一個非常簡單的本地路由算法。 在這裏,我的算法步驟;使用Netlogo在複雜網絡上進行本地路由
1 go
2 get-list-of-neighbors
3 select one-of from list of neighbors
check is-visited:
if yes: [remove from the list
check is-loop
if yes: Die
else go to setp 3]
4 else Move-to selected node
5 check is-target?
if yes: die
else add to list-of-visited and Go
問題: 我是新使用Netlog,不知道如何實現這個算法。 這是我的代碼。
to go
ask walkers[
set list-of-neighbors (list [link-neighbors] of location)
let selected-node one-of list-of-neighbors
if (visited?=true)[ set list-of-neighbors remove-duplicate list-of-neighbors
chek if loop? exist
if yes:
if no:
if(visited?=false)[ move-to selected-node]
set location selected-node
ask location[ ifelse target=true[die][set list-of-visited lput location
go ]
end
太感謝你了,先生,我得到了我的答案。通過檢查Is循環?我的意思是檢查是否有任何圈子?通過移動到選定的節點。所以行人應該死亡。 –