Power loss Vs. Distance - netlogo

I am doing a simple radio propagation model in netlogo where i have to generate a plot of power loss Vs. Distance.Is there a way to plot one quantity vs other instead of one vs ticks. Any advice on procedures is greatly appreciated.
Thank you!

The plotxy primitive lets you do that.
I don't know how your power loss and distance data is stored, but let's build a quick example using turtles xcor and ycor as data. You should be able to adapt it easily.
Here is the very basic model:
to setup
ca
ask n-of 100 patches [ sprout 1 ]
reset-ticks
end
to go
ask turtles [ fd 1 ]
tick
end
Now you can create a plot. Put clear-plot in the plot update commands and ask turtles [ plotxy xcor ycor ] in the pen updates commands:
Also make sure that your pen is set to "point mode" in the advanced pen options, or you'll get a jumble of lines:
(Access the pen options by clicking on the pen icon next to the pen definition in the plot dialog.)

Related

NetLogo: use value of 'stock' in SDM as input for ABM

I made two simple models; one System Dynamics Model and one Agent Based Model in NetLogo. The SDM has a stock 'tourists' and its value depends on the in- and outflow. The value is re-calculated each tick. The tourists are sprouted in the ABM each tick. Now, I would like to use the value of the touristsStock as an input for the turtles that are sprouted each tick in the Agent Based Model. What is the best way to do this? I have already checked the example codes in the Model Library (Like the Tabonuco Yagrumo model) but it doesn't make any sense to me. What is the best way to integrate these models with each other? Thanks in advance!
The relevant piece of code of the ABM is as given below:
to go
clear-turtles
;sprouts turtles only on patches with value beach AND patches that are close to the lagoon (calculated in ArcMap)
;the initial number of tourists is multiplied by the percentage of tourists that were satisfied in the previous tick.
;percentage of tourists that were not satisfied is subtracted from 100 and divided by 100 to make it a factor between 0-1.
ask n-of (initial-number-tourists * ((100 - percent-dissatisfied) / 100)) (patches with [ beach_close_to_lagoon = 1])
[
sprout 1 [
set color black
set size 10
]
]
ask turtles [
set neighbor min-one-of other turtles [distance myself] ;; choose my nearest tourist based on distance
set distance-tourist distance neighbor ; measure/calculate distance of closest neighboring tourist
]
ask turtles
[ ifelse distance-tourist > 5
[ set satisfied? True]
[ set satisfied? False ] ]
update-turtles ;before the end of each tick, the satisfaction of each turtle is updated
update-globals ;before the end of each tick, the percentage of satisfied tourists is updated in globals
;clear-turtles ;because each tick represents one day, the tourists will leave the beach after one tick so the turtles will die
tick
end

How to plot a distribution in netlogo?

I have a NetLogo model. each turtle has two attributes, "closeness" and "deviation_from_oracle". Now let's say there are 1000 agents in the model. The question is, how can I plot the "closeness" against "deviation_from_oracle" ?
It would also be helpful if I can get a csv file from NetLogo that has the value of closeness and deviaiton_from_oracle of all turtles after for example 1500 steps.
I definitely agree with Hugh_Kelley regarding using Behaviorspace to output your values (or custom export functions that might make for easier data cleanup if you're looking to report values for a large dynamic number of turtles- depends on your comfort with your statistical software of choice).
If you do need to plot something on the interface to show your users or something, you may find the plotxy function does what you need. For example, you'll need a plot on the interface called "plot 1" and a single blank pen in that plot called "pen-0".
You can control that plot either by manually setting up its x and y extent or by using the set-plot-... commands as in this setup:
to setup
ca
crt 10
set-current-plot "plot 1"
set-current-plot-pen "pen-0"
set-plot-pen-mode 2
set-plot-x-range 0 17
set-plot-y-range 0 25
reset-ticks
end
If you need to have a value plotted for each of your turtles, you can get the turtles to call plotxy for whatever values you're looking to plot- here I just use their absolute x coordinate and distance to the center as an example:
to go
ask turtles [
rt random 61 - 30
fd 1
set-plot-pen-color color
plotxy ( abs xcor ) distance patch 0 0
]
tick
end
This gives output like:
Where each point was plotted by an individual turtle.
If you want instead some reported mean value, have the observer call plotxy instead- another example that plots the average distance to other turtles and the average distance to center:
to go
plotxy mean-closeness-to-others mean-distance-center
ask turtles [
rt random 61 - 30
fd 1
]
tick
end
to-report mean-closeness-to-others
report mean [ mean map distance sort other turtles ] of turtles
end
to-report mean-distance-center
report mean [ distancexy 0 0 ] of turtles
end
For an output like:

Netlogo Reporter Not Reporting

I've made a animal behavior model involving "turtles" and "roads" and I want the model to report back to me when the turtle "crosses" a road. All I want is that it tells me when the turtle moves from a patch that is the grey color to the red color. I've included the code asking it to report this and the program has no issue with the code. To give me a visual representation of what I want it to report, I put a monitor on interface. But it always gives me a "0" for road crossings, even as I can see that my turtle has crossed roads. I would count it by hand, but it's impossible to tell for certain how many road crossings there are and this is for scientific publication. My code is as follows...
turtles-own [
road-crossings
]
to setup
clear-all
;; create turtles on random patches.
ask patch 6 -15 [
sprout 1 [
set color one-of [green]
set size 1
set road-crossings 0
]
]
ask turtles [
if [pcolor] of patch-here = 14.9 [
set road-crossings road-crossings + 1
]
]
reset-ticks
end
to go
ask turtles [
repeat 100 [
repeat 39 [
pen-down
rt random-float 360
lt random-float 360
fd random-float 1.375
]
setxy 6 -15
]
]
tick
end
Any help is appreciated! Thank you!
There are several potential problems with this that I can see.
First, road-crossings is a turtle variable, which is the correct thing to do if you want each turtle to remember how many times it crosses a road. If so, however, the monitor must report sum [road-crossings] of turtles to get the road crossings of all turtles.
Second, which I think is actually your problem: you have the turtle checking whether it crosses the road in the setup procedure rather than the go procedure. The setup procedure is only run at the beginning.
Third, you don't actually have any roads in your example code, but I suspect that's just a failure to create a proper example. I assume that there are patches with pcolor of 14.9 in your real code. If not, though, that would also cause your error. You can make sure by going into the command center and asking count patches with [pcolor = 14.9]

How to create a fixed number of turtles at a certain point?

This may seem like a very simple question to ask but at present I do not know how to create a controllable number of turtles. In addition to this I do not know how to set the coordinates where the turtles should spawn. Ideally I would like the turtles to spawn on a patch that the user will draw out in the U.I. so that the turtles can then move along the network the user will have drawn in the U.I. Any answers would be greatly appreciated.
Patches use the sprout command
Ask patches [
Sprout 5 [set color red ]
]
Asks all the patches to make 5 red turtles.
Netlogo has fantastic documentation
The netlogo dictionary in help is insanely useful.
Or just ask one
Ask patch 4 5 [sprout 1]
create-turtles takes in the number of turtles to create. It also allows you to pass in a block of code that will then be run by the created turtles. So you can do:
create-turtles 50 [
setxy 3.5 4.7
]
This will create 50 turtles at the coordinates (3.5, 4.7).

Maintaining two states of turtles netlogo

I am doing a small university project. In which i have to maintain 2 states of turtles.
1. Disperse
2. Explore
Disperse :
In dispersion, when at the start all the turtles (20 turtles) are at 0,0 they should disperse from each other. Every turtle has a radius of 2 patches around it, no other turtle should be in that radius. All turtles should go far until they all attain this radius. then other behavior will be called i.e. Explore.
Explore:
In explore , they have to explore the world and avoid different types of obstacles. When ever two turtles come close to each other above mentioned radius then state should be changed to disperse.
I have procedures for obstacle avoidance, and move-speed, and all other individual behaviors under Disperse and Explore. But i don't know how to join all this in one simulation.
It is unclear that you really need to maintain turtle state, since you will have to repeatedly check for other turtles in any case. But since you said you wanted that, you can use turtles-own. For example:
turtles-own [state]
to setup
ca
crt 20
end
to go
ask turtles [set-state]
ask turtles [move]
end
to set-state ;;turtle proc
ifelse (any? other turtles in-radius 2) [
set state "disperse"
] [
set state "explore"
]
end
to move ;;turtle proc
if (not member? state ["disperse" "explore"]) [
error "unknown state"
]
if (state = "disperse") [
disperse
]
if (state = "explore") [
explore
]
end
to disperse ;;turtle proc
move-to one-of patch-set [neighbors] of neighbors
end
to explore
move-to one-of neighbors
end
You might want to take a look at Moore machine and Automata, NetLogo works great with those.
A Moore machine can be seen as a set of 5 elements that interact with each other, in this particular example the start state(S0) would be Dispersing. In NetLogo you can use the word run that receives a string. You'd had to make a procedure that returns a string (say "explore") by checking the actual state of a turtle.
I made something like that a few months ago. We were trying to make a hunter-prey model for polar bears and seals (or wolves and sheeps) based on Moore Machines.
You can use the example of #Alan of course, I just skimmed through and I believe it was fine.
Here is my example based on Moore Machine. It's in spanish but the idea is the same.