How to give turtles directional commands when moving along a drawn out network? - netlogo

I want turtles to be able to flow along the paths I have drawn out for them. To do this I think it might be a reasonable idea to have a list in the u.i that allows the user to select a preordained direction of movement for that patch so the turtles know how to flow along the network. Has anyone else produced a model with this feature? If so would it be possible to give an example of the relevant source code for implementation into my own project?

I did something a while back where each patch had a direction variable that turtles set their heading to when on the patch.
Something like
patches-own[dir]
to go
ask turtles [set heading dir fd .1]
end

Related

How do I make linked turtles move together in NetLogo?

I'm trying to model fish movement and need them to form schools when there is more than 1 of the breed in a given patch. So far I have managed to get them to form links when they encounter each other with the function below, but then they continue moving independently. I'd also like to re-scale the color of turtles in a linked group so that the more turtles in the group the darker the color is (I'm guessing this is similar to the way you make contour maps according to environmental gradients but I haven't figured it out yet).
Any assistance is always appreciated!
to form_link
if count breed_1-here > 1
[
ask breed_1
[create-links-with other breed_1-here]]
end
If linking isn't the way to get them to move together, I'm fine with another method.

What is the sequence of Netlogo execution?

Have I got this correct please?
If I write:
ask turtles
[go_forward
go_backward]
is it correct that a random turtle will move forward then move backward, and then a second random turtle will do the same, and so on? As opposed to:
ask turtles [go_forward]
ask turtles [go_backward]
which will get all turtles in a random order to move forward, and then all turtles in a (different) random order to move backward.
That is correct. There's a very similar example right at the end of the section on ask in the NetLogo Programming Guide: http://ccl.northwestern.edu/netlogo/docs/programming.html#ask
See also Ask Ordering Example, in the Code Examples section of NetLogo's Models Library.

netlogo turtles moving on coordinates

I created turtles called "birds" that shall move on a specific route. The route is made out of links between turtles I called "rasts". As I couldn't find a way to make the turtles move from the first rast to the second, third, fourth and fifth, I changed the rasts an created them as patches.
So, now I have patches in red (rests).
How do I get the birds moving to exactly these patches and, when they are at the patch, how do I make them go to the next one?
I have no code at the moment, because I always hope to find the fault in my first model (see my other questions).
Is there anybody who knows how to solve my problem?
the move-to command moves your turtle to any other turtle or patch you specify. You can also use the face and forward commands to gradually move along a route (see the 'Move Towards Target' code example in the Models Library that comes with NetLogo)

When using the forward command is the movement specified carried out after each tick?

I am trying to make turtles move along fixed paths that the user can draw in the u.i. The forward command can make turtles move a certain fraction of a patch forward per tick I assume, however to instigate smooth movement would it be possible to specify a fixed movement per tick in the setup commands for turtles? If this is possible what would be the basic structuring of the code I would use to achieve this?
The fd command (bk as well) accept floating-point inputs. I.e.
Ask turtles [ fd .01 ]
Makes each turtle move forward 1/100th of a patch. This movement happens at the time of the command.
Tick does not have any connection to when commands are carried out. If you set view updates to on ticks it can effect when you see updates otherwise it is usually a scheme for keeping track of how many times go has run.
A sample model of turtles moving at different speeds.
Turtles-own [speed]
To setup
Crt 100[
Set speed random-float 1
]
End
To go
Ask turtles[ rt 1 fd speed]
End
Copy and paste that into a new model make setup and go buttons. Mess with it for a while.

Efficient access to a Turtle's variable which is a patch address, or How to filter patches that are not assigned to turtles?

In my simulation each turtle has a my-home variable which is the patch agent family lives in, so agents with same Family-ID have same my-home until one of agents moves out or family grows to more than 7 agents.
when an agent wants to move out , I have to check if there is any patch nearby which is not another's agent my-home, what I have done is to store all my-homes in a list and check if any selected possible next home is not a member of this list, but I believe there should be better way to do this:
let all-homes [my-home] of agents with [belongs_to = BS]
set my-home min-one-of patches with [not member? self all-homes and label_ = BS][distance m]
m is current home address
min-one-of patches with ... assesses every patch in the entire world before picking a winner. That's going to be slow. I'd suggest searching nearby patches first, then farther patches, and so forth. Most of the time the turtle will find a new home after only a very brief search, so you'll have replaced code that's O(n) in the number of patches with code that's O(1)-ish. That should fix the main performance problem with this code.
The simplest such search routine I can think of is for the turtle to simply head in a random direction and keep moving fd 1 until it lands on a free patch. But if you want to do something more rigorous that always results in finding the closest possible new home, you could do that too; you'll just have more code to write.
Building the all-homes list is probably only a secondary performance problem here, but it's fixable too. The simplest fix I can think of is to add:
patches-own [home?]
initialize it with ask patches [ set home? false ], and then make sure that whenever a turtle adopts a patch as its home, it does ask my-home [ set home? true ]. Now you can replace member? self all-homes with simply home?. After all, you don't really need to know what all of the home patches are; you only need to know whether some particular patch is a home patch.