Reputation: 11
I am quite new to Netlogo. I try to create a model for the exchange of opinions in order to finds a suitable location for siting of a unpopular facility. The model contains of three breeds people with different opinions.
I imported a GIS raster layer with four different landuse classes (buildings, agriculture, forest, water). All breeds were randomly assigned to landuse class "buildings". The interaction takes place by randomly paired connections between two agents per tick. The default opinion value on how suitable a location might be should be based on landuse class in a certain distance. Distance should be divided in near (<= 20) , middle ( 21 -50) , and far (> 50 ). If a turtle is asked to give its opinion about a certain patch it should be automatically calculated in what distance to each other both are.
However, I do have quite some issue with finding a code that defines for each turtle what is of near, middle, or far distance to it. So far I had two main ideas, but the code I wrote did not provide a satisying results.
First attempt went this way:
calc-distance
ask turtles [
if (distancexy pxcor pycor) <= 20
[set location near]
if (distancexy pxcor pycor) > 20 and (distancexy pxcor pycor) <= 50
[set location middle]
if (distancexy pxcor pycor) > 50
[set location far]]
end
Second attempt went this way:
Turtels were located at a Patches were located at b Calculate automatically the distance between a and b
if ab <= 20
[set location near]
if ab > 20 and ab <= 50
[set location ...}
end
I would be please, if someone could provide any solution for this problem. Thanks in advance!
Jan
Upvotes: 1
Views: 1216
Reputation: 1297
You're trying to pass a breed variable name as an argument. That's a syntax error.
When using distancexy
the expected values are numbers. You can use loop to check all positions you want to check. However I think your turtles should have variables to store the opinion for every location.
calc-distance
ask turtles [
if (distancexy point1-pxcor point1-pycor) <= 20
[set point1-location "near"]
if (distancexy point1-pxcor point1-pycor) > 20 and (distancexy point1-pxcor point1-pycor) <= 50
[set point1-location "middle"]
if (distancexy point1-pxcor point1-pycor) > 50
[set point1-location "far"]
]
. . . continue with all other locations OR use loop.
end
Upvotes: 1