I created a small undirected network, where some nodes are as sources and some are targets. then I created walkers placed on source nodes. Now, I want to implement a very simple local routing algorithm using this network. Here, my algo steps;
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
Question: I'm new to Netlog, and don't know how to implement this algorithm. Here is my code.
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
My Question/ algorithm Description:
My answer here is a slight modification to my answer to your other question. I'm not sure exactly what you mean by
check is-loop
, so in my solution I just have the walkers die if they have no neighboring nodes to which they can move (as they have already visited that node). Additionally, I'm suggesting a slightly different approach to accomplish the same idea as the algorithm you outline. The steps here are more like:locations-list
go
procedure, a new walker is spawned on the source node.Obviously if there is a linear path with multiple target nodes on it, the walkers will die each time they come to the first target and so will never visit those nodes that are farther along- but this is just an example. Remove the
die
chunk or modify other things to play around.Like I said, this is only a very small modification to the answer linked above, but I copy the whole code below for easy access.