I'm new to Netlogo and trying to simulate (a part of) a brain network in which the turtles represent brain areas and 'fclinks' represent the links between those brain areas, which should decrease in weight ('weight-edge') over time.
This is a snippet of code:
ask fclinks
[ set weight-edge weight-edge - fc-change ]
; change thickness of links
ask fclinks
[ if weight-edge < 1000
[ set shape "medium"
]
if weight-edge < 500
[ set shape "thin"
ask symptom 3
[ set color 15 ]
]
]
end
'symptom 3' is another node that should change color if the weight-edge passes a certain threshold (when weight edge is lower than 500). However, the node is already changing color before this threshold is reached.
Why is this happening?
Thanks!
You have the node changing colour if the weight is low if weight-edge < 500 but your question is phrased in such a way that I think you don't want it to change colour until the threshold is reached, so the colour indicate higher weights. If this is the correct interpretation, then the problem is simply that you have < instead of >
Related
I am new to Netlogo and learning a model is about animals moving around to eat grass based on the grazing model from NetLogo. The moving behavior is based on the biomass's richness, so it is not just impacting at right angles.
Given the conditions, I don't know how to add a monitor in my model that calculates the total distance a turtle moved by traveling each pixel.
Move specifically, I wonder if there is a way to calculate the total length of the pen-marked lines. (Show in the picture)
enter image description here
The basic setting of move is
to move-turtles
uphill-biomass
forward 1
set distance-traveled (distance-traveled + 1)
if not can-move? 1 [ rt random 150 ]
end
to uphill-biomass
let biomass-ahead biomass-scent-at-angle 0
let biomass-right biomass-scent-at-angle 35
let biomass-left biomass-scent-at-angle -35
if (biomass-right = biomass-ahead) and (biomass-left = biomass-ahead) [ wiggle ]
if (biomass-right > biomass-ahead) or (biomass-left > biomass-ahead)
[ ifelse biomass-right > biomass-left
[ rt 35 ]
[ lt 35 ] ]
end
Thank you very much for any helps!
You need to use some turtle variables with the turtles-own primitive and do the distance calculation by hand.
The easiest way to do such a calculation is to save the coordinates between a turtle's previous coordinates with turtle variables and then use the distancexy primitive (link for dictionary entry: https://ccl.northwestern.edu/netlogo/docs/dictionary.html#distancexy)
Here's a simple implementation:
turtles-own [last-x last-y distance-traveled]
move-turtle
uphill-biomass
set last-x xcor
set last-y ycor
forward 1
set distance-traveled (distance-traveled + (distancexy last-x last-y))
if not can-move? 1 [ rt random 150 ]
end
I hope this answers your question.
In the simulation I am working on, I have red turtles.
I want them to be yellow at the beginning, then turn orange after 10 ticks, then red after 10 other ticks.
How can I do so ?
to ignite
ask fires [
if count neighbors > 0 [
ask one-of neighbors with [pcolor = white or pcolor = green ]
[
if count fires-here < 6 [
sprout-fires 3
[ set color red set size 3 ]
]
]
]
]
end
Note that you have tick in your setup procedure as provided. That needs to be in your go procedure. setup is for everything when the simulation starts, and go is what happens each time step. The command tick advances the counter for the time steps, and the reporter ticks reads the time step counter.
If you are going to change a turtle's colour based on how long it's been alive, the first thing you need to do is to have the turtle know when it is 'born', so create a variable for that and store the current value of ticks in that variable during the creation.
fires-own
[ state ; you have this already
birth-tick ; this is the new one
]
Change this:
sprout-fires 3
[ set color red set size 3 set state "live"]
to this (note that spacing does not matter to NetLogo, but helps with readability)
sprout-fires 3
[ set color red
set size 3
set state "live"
set birth-tick ticks
]
So that creates the birth time. Now, within your go procedure (which you don't show), you want all the turtles that are 10 ticks old to change colour. One way is:
ask fires with [ birth-tick = ticks - 10 ] [ set color orange ]
i'm trying to make an archaeological model, in which hunters are making paintings in shelters, depending on their quality.
breed [shelters shelter]
breed [hunters hunter]
shelters-own [quality paintings]
The value of each shelter quality is set in the setup (with a slider for the actual number of shelters).
create-shelters number-shelters [set quality random 100]
The action of painting-or-not is then defined by random against the quality of each shelter:
to make-painting
ask shelters [
if any? hunters-on patch-here [
if random 100 < quality [set paintings paintings + 1]
]
]
end
Now, I would like to complexify it a bit more: the quality wouldn't be defined by the shelter itself (and thus be the same for every hunter), but by the hunters: each of them would attribute a different quality for each shelter. The action of painting-or-not would still be a test against random, but with this new variable defined by each individual hunter...
But I can't find a way to code it down properly.
Does anyone have a suggestion?
I think I got it right. Basically, I had every hunter to create a matrix filled with random numbers. The size is 33x33, so it goes all over the world (had to set it to start in a corner, or it gets negative coordinates).
create-hunters number-hunters [
set color white
set size 1
setxy random-xcor random-ycor
set hunter-matrix matrix:make-constant 33 33 random 10
]
ask n-of number-shelters patches [
sprout-shelters 1 [
set color one-of base-colors
set size 1
set xpatch xcor set ypatch ycor
]
Then, when they would reach a shelter, the value corresponding to that patch location would be extracted and used to paint-or-not.
ask patches [
ask hunters-here [set quality matrix:get hunter-matrix xpatch ypatch]
let paintings-here sum [paintings] of shelters-here
if any? hunters-here and any? shelters-here [
if random 10 < quality [
ask shelters-here [
set paintings paintings + 1]
]
]
]
I'm still not completely sure it actually does what I think it's doing, tho.
In my model I have some agents collecting from another agent who they bump into at random after which they move back to their base. As they move back they drop off some material as defined by the random function. Here's some sample code
to go
ask searchers
[ set energy energy - 1
fd 0.0125
if random-float 1 < (1 / 50)
[ ifelse random 2 = 0
[ rt 45 ]
[ lt 45 ]
]
search
]
end
to search
if any? depots in-radius vision with [color = yellow]
[spread
set energy 0] ;; makes them to back to base
end
to spread
if random 10000 = 1 [hatch-rubbish 1 [ set color white
set shape "circle"
set size 0.5]]
end
If I set the visual radius to something enormous so they can always see the depot the number of bits of rubbish works out.
However if I allow them to move around with a radius of 1, the count of rubbish is much higher than 1 in 10,000.
Why would that make a difference?
Thanks
Is it possible to create random shapes (see below for example) of a given area in NetLogo?
A first stab at Seth's suggestion #1. It creates a neat visual too!
patches-own [ height ]
to blobbify
clear-all
repeat (ceiling 2 * (ln (world-height * world-width))) [
ask patch (round (random (world-width / 2)) - world-width / 4)
(round (random (world-height / 2)) - world-height / 4)
[ set height world-width * world-height ] ]
while [ count patches with [ height > 1 ] < (world-width * world-height / 4)]
[ diffuse height 1
ask patches with [ height > 0 ] [ set pcolor height ]
]
ask patches with [ height > 1 ] [ set pcolor white ]
end
I found a really simple approach that produces pretty nice results.
Create a turtle. The turtle performs a random walk. After each step, they set the uncolored patch closest to them to the desired color. The turtle does this a number of times equal to the desired area.
Here's the code:
to make-blob [ area ]
let blob-maker nobody
crt 1 [ set blob-maker self ]
repeat area [
ask blob-maker [
ask min-one-of patches with [ pcolor = black ] [ distance myself ] [ set pcolor blue ]
rt random 360
fd 1
]
]
ask blob-maker [ die ]
end
This naturally produces nicely curved blobs.
Making the turtle's step size smaller makes the blob more circle-y. Making it bigger results in thinner, more sporadic blobs (though you run the risk of getting disconnected patches).
Edit:
I noticed that my answer runs quite slowly when you have a gigantic number of patches. Here's a much faster version:
to make-blob [ area x y ]
let blob-maker nobody
crt 1 [ set blob-maker self setxy x y ]
let border patch-set [ patch-here ] of blob-maker
repeat area [
ask blob-maker [
ask min-one-of border [ distance myself ] [
set pcolor green
set border (patch-set border neighbors4) with [ pcolor = black ]
]
rt random 360
fd .8
]
]
ask blob-maker [ die ]
end
Generating random blobs is a hard problem with no obvious solution. Fixing the area of the blob makes it even harder.
You'll need to pick an approach, then try to figure out how to express that approach in NetLogo code.
As for what approach to pick, I imagine there's literature on this if you search. But just off the top of my head, I have three ideas:
Scatter random points around the world, use diffuse to make a smooth landscape around these peaks. (See the Diffusion Graphics model, in the Art section of NetLogo's Models Library, for code for this; you'll want to turn world wrapping off, though.) Then select only those patches where the "elevation" exceeds some threshold. To get the desired area, vary the threshold until the target is reached.
Draw a curve around the center point using polar coordinates, where theta goes from 0 to 360 and 4 varies randomly. You'll need a way to get smooth random variation in the radius, perhaps by generating random numbers and then applying a smoothing function to them. In order to force the blob to have the desired area, first generate the whole curve, then scale it as needed. You'll need some trick to avoid a discontinuity where theta = 0, perhaps by using a smoothing function that wraps.
Generate a random polygon by scattering points around the world, then discarding some or all points in the middle. (You could take the convex hull, but then you'll always get a convex shape, which might not be "blobby" enough for you. So you might want to something like like generating n random points and then keeping the m points that are farthest from the center, without regard to convexity.) Once you've got the random polygon, apply some smoothing function to turn it into a curvy blob. Then scale the whole thing as necessary to get the desired area.