Reputation: 165
I am working on a project in netLogo in which i have a random network in which each and every link is assigned a bandwidth. The algorithm chooses a random Source and Destination by itself and after which it has to choose an optimal path between these two. My question is how shall i ask turtles whicj i created on a particular code to face and move on its neighbour nodes so as to explore the graph(atleast explore ,if it doesnt manage to reach the destination ) few trtles must travel on nodes other than "relay nod" also (the relay node is the optimal node path, but i want nodes to explore other nodes aswell). heres my code part:
to face-targets
ask ants ;with [ target-node]; = node 4 ] ;nobody ]
[
let d 0
face (one-of nodes with [ label = "Relay Node" ]);target-node
ask current-node [
set d distance (one-of nodes with [ label = "Relay Node" ]);target-node)
]
set distance-to-go d
]
end
to move-forward
face-targets
ask ants [
while [ distance-gone < (distance-to-go )]
[
fd 1
set distance-gone (distance-gone + 1)
]
]
ask ants [
if distance-gone < distance-to-go
[
set current-node target-node
setxy ([xcor] of current-node) ([ycor] of current-node)
set distance-gone 0
set distance-to-go 0
]
]
end
Upvotes: 1
Views: 222
Reputation: 12580
It's not entirely clear what you're asking. In general, you should try to narrow your questions down to a specific problem you need help with.
That said, my general approach to what you describe would look something like this:
turtles-own [ current-node ]
to go
ask ants [
let next-node pick-next-node
face next-node ;; This is purely for visual reasons and is not necessary to the behavior of the model
move-to next-node
set current-node next-node
]
end
to-report pick-next-node
;; Whatever strategy you want your ants to use to pick their next node. For example, random:
report one-of [ link-neighbors ] of current-node
end
Upvotes: 1
Reputation: 30453
I think no one has answered this yet because:
If you fix those two things (S.O. questions are editable), you'll have a lot better chance of getting useful feedback from someone here.
There are two relevant Code Examples in NetLogo's Models Library I suggest you look at:
In the former, the turtles move to the next node all at once; in the latter, they proceed gradually. I'm not sure which it is you're trying for? Normally if you're doing network stuff you would do the former approach; from your code, it appears you're trying for the latter, but it isn't clear why.
Note that you can replace setxy ([xcor] of current-node) ([ycor] of current-node)
with just move-to current-node
.
Upvotes: 0