I am building a dispersal model in a landscape with different landcover types: urban, forest, residential etc. Each one of these landcover types has a resistance-to-movement patch variable and they are found in clusters of patches:
urban - 4 + random-float 1.0
residential - 9 + random-float 1.0
forest - 1 + random-float 1.0.
I would like my turtles to move downhill the resistance values from one forest patch cluster to another. The issue I am having however, is that because the resistance values are not distributed in a gradient, the turtles will stay put if the resistance of its neighbours is the same or move backwards away from the forest patches if the resistance is lower in that direction.
Most models in the model library that use the downhill/uphill functions have gradient landscapes such as mountains, but mine are randomly distributed.
How can I get my turtles to move downhill while also maintaining a global direction towards the forest patches so that they do not move backwards?
Thanks!
That seems rather like a modelling problem than like a Netlogo problem to me.
How would you like the turtles to move, if they have visited all forest patches in that cluster?
Two ideas:
they move to the patch with the smallest resistance from all neighbor patches, that are closer to their destination, e.g. with min-one-of
face destination ; destination is a patch
; could be a global variable set in setup
let candidates (patch-set patch-right-and-ahead 30 1
patch-left-and-ahead 30 1
patch-ahead 1)
move-to min-one-of candidates [value] ; turtle moves to the candidate patch with the smallest "value"
or, if they have knowledge of the whole landscape, they could use a path search algorithm such as A* in order to minimize the sum of resistance on their path.
Related
I have each patch holding two lists: directions and magnitudes. Both lists contain values that are computed based on nearby turtles:
directions contains the headings from the patch to the various turtles (so basically it is just the turtle's heading rotated by 180°);
magnitudes contains a value that is directly proportional to the turtles' mass and inversely proportional to the distance between the patch and the turtles;
The items of the two lists are coupled in their order, i.e. the first item of directions and the first item of magnitudes are computed based on the same turtle, the two second items are computed based on another turtle and so on.
What I want to achieve is to come up with two single patch-own values, my-direction and my-magnitude, representing in some way the weighted average of directions, where the weights are magnitudes.
To put it another way, I am thinking of this in terms of vectors: turtles are exerting on the patch a force that can be represented as a vector, always pointing in the direction of the turtle and with a certain intensity (the magnitude). The resulting vector (represented by my-direction and my-magnitude) should be the resulting average of these forces.
I have seen this question. It does not address the issue of a weighted average; however it mentions the concept of circular mean. I've delved into it a bit, but I'm not sure how to apply it to my case and even if to apply it: does it still apply even with the formulation of the problem in terms of vectors?
I've seen this question/answer on SE Mathematics where it is said that the average vector can be found by averaging x- and y-coordinates of the initial vectors. In my case, ideally all the pairs of values in the two lists form a different vector with origin in the patch at issue, with heading found in directions and length found in magnitude. I suspect I can find the coordinates of each vector by multiplying its sine and cosine by its magnitude, however at this point I'd use some guidance as I might be overcomplicating things (either from the maths perspective or the NetLogo perspective).
This one below is a reduced version of the code that brings to the point where target-patches (not focusing on all patches, in order to make it quicker) have the two lists populated.
globals [
target-patches
]
turtles-own [
mass
reach
]
patches-own [
my-direction
my-magnitude
directions-list
magnitudes-list
]
to setup
clear-all
set target-patches n-of 10 patches
ask target-patches [
set directions-list (list)
set magnitudes-list (list)
set pcolor yellow + 3
]
create-turtles 10 [
move-to one-of patches with [(not any? turtles-here) AND (not member? self target-patches)]
set mass (random 11) + 5
set reach (mass * 0.8)
set size (mass / 8)
set shape "circle"
]
populate-lists
end
to populate-lists
ask turtles [
let relevant-targets (target-patches in-radius reach)
ask relevant-targets [
set directions-list lput (towards myself) (directions-list)
set magnitudes-list lput (magnitude-based-on-distance) (magnitudes-list)
]
]
end
to-report magnitude-based-on-distance
report [mass] of myself / (distance myself * 1.2)
end
Your initial instinct is right. You can do something like
LET my-dx mean (map direction magnitude [ theta scalar -> scalar * sin theta ])
(I may have that map and anonymous syntax wrong please edit)
And do the same for my-dy using cos (edit: or maybe negative cos?)
patch-at my-dx my-dy is one way of getting the patch.
You can also do (atan my-dx my-dy) to gets the new direction
And distancexy my-dx my-dy to get the magnitude
Don’t remember if patch can use distancexy or patch-at, but hopefully so. Otherwise you have to use a helper turtle, and do the math yourself.
I think I did a orbital mechanics toy model once that did something like this. It’s hiding on turtlezero.com.
I want to know the Relationship between turtle size and patch size in Netlogo. Also I want to make those sizes in a way such that any turtle moves from one patch to another at every tick.
Patch size is measured in pixels. It is configurable in the "Model Settings" dialog.
You can think of turtle size as measured in "patches". A turtle of size 1 should appear to be the size of one patch. (Note, however, that turtle size is a "display only" property. Conceptually, turtles are just points. They don't really occupy space in the NetLogo world even if they appear to do so.)
Changing the xcor or the ycor of a turtle by 1 should move it by exactly one patch. If you want them to move diagonally, things are a bit more messy. You might be better off targeting destination patches directly, e.g.:
; move to the patch north-east of current position:
ask one-of turtles [ move-to patch-at 1 1 ]
; move to an adjacent patch at random:
ask one-of turtles [ move-to one-of neighbors ]
Those are just examples, of course. The code to use will depend on what exactly you are trying to do. If you tell us more in a separate question, we might be able to help you.
Im struggling to get turtles to avoid certain patches with a colour green while still pathing towards a target patch.
my netlogo model simulates a countries ocean fishing with boats (turtle) leaving from ports into the sea and returning. Each boat currently sets a target patch in the ocean based on underlying GIS fishing effort data points (patch variables).
Currently, on the way to their target, some boats have to travel out of their semi enclosed ports and if using line of site will travel across land (green patches). I cannot figure out how to get the boats to choose a path which avoids green patches while still pathing towards the same target patch?
Most answers I have found here only accommodate relatively random movement where the heading is changed if a green patch is within a cone X or in front. I am trying to figure out a pathing technique which doesnt involve head towards X until you hit green then go random left or right but this model needs to be able to determine whether heading left or right after hitting green patch (in the cone) is the right way to go. very confused!!
Patches-own
land
vessels-own
home-port ; patch of the home port
target ; target patch for fishing
ask patches ; sets the color of land and sea patches
[ ifelse (land = 1)
[set pcolor green]
[set pcolor blue]
]
to choose-target
set target one-of patches in-radius 60 with [(fishing-
effort > 100) and (fishing-effort < 1010)] ; sets the
fishermen target to one of the patches with a fishing
effort score
end
to movement
ifelse distance target < 1
[stop] ;
[ face target
forward 1
set fuel fuel - 1] ; uses one fuel per movement forwards
if distance target < 1 [ stop]
end
Thanks!
when we ask a turtle to forward 2, does it mean:
on its heading direction, move to the second nearest patch
on its heading direction, move to the second nearest patch's center point
on its heading direction, move to the second nearest patch's center point which is (pxcor, pycor)
which one is correct? or are they the same answer?
How do we define the nearest patch this turtle is pointing to? Is the following understanding correct?
top patch: if heading is between -45(315) and 45 degree
right patch: if heading is between 45 and 135 degree
bottom patch: if heading is between 135 and 225 degree
left patch: if heading is between 225 and 315 degree
It means to move forward a distance of 1. The easiest way to see this is with the following code:
to setup
clear-all
create-turtles 1
[ setxy 0 0
set heading 45
forward 1
print xcor
print ycor
]
end
Try changing the heading and see what happens. Note that patches are exactly 1 unit wide and the centre of the patch is at integer values (so patch 0 0 extends from xcor -0.5 to xcor +0.5)
forward totally ignores patch boundaries and patch centers, so 1–3 are all incorrect. Patches don't enter into it; it's just trigonometry on the turtle's x and y coordinates. Specifically, forward 1 just means setxy (xcor + sin heading) (ycor + cos heading). The destination patch is simply whatever patch the new x and y coordinates happen to lie within. The destination may or may not be a patch center.
forward 1 might leave the turtle in the same patch (e.g. if the turtle is in the southwest corner of a patch facing northeast; the length of the diagonal is 1.414..., so forward 1 isn't enough to reach a new patch). Or, forward 1 might take the turtle to the nearest patch ahead, or to the second nearest patch ahead. (The latter can occur if the turtle just grazes the corner of a patch.)
A good model to play with to explore and understand all of these possibilities is Next Patch Example, in the Code Examples section of NetLogo's Models Library
As for the second part of your question, your definition is only correct if the turtle is initially standing on a patch center. For the general case, Next Patch Example answers that too. The next-patch procedure in that model is like your definition, but handles the general case.
In order for two way traffic to flow along a road that is the thickness of a single patch it is necessary for the position of each turtle to be to either the left or the right of the patch on which they are travelling. How can I control where a turtle resides on a patch while travelling along it so that there is enough space for two opposing flows of traffic on the same road?
You can use set xcor ... and set ycor ..., or setxy ... ..., or any other turtle motion command such as fd or bk, to position the turtle however you like. If the turtle's coordinates are both integers, it's on a patch center. If either or both aren't integers, then the turtle is in some other location in the patch.