I try to add a number (1) to a part of the turtles after a tick. The function should always add one to the variable after one tick but currently, the function adds it only one time - after the first tick and then stops. The variable "updated_prob" is currently not steadily updated.
This is how the Goprocess looks like
to go
ask turtles[
ifelse (color = grey)
[update_update_prob]
[e-bikenutzung]]
tick
end
to e-bikenutzung
ask turtles with [color = green]
[if ticks = 48
[set color grey
set ebike? false
set probability_ebike_start 50]]
end
to update_update_prob
ask turtles with [color = grey]
[set prob_sum probability_ebike_start + environment_add + subventionierung_bonus]
ask turtles with [color = grey]
[set updated_prob prob_sum + 1] ------- is not steadily updated
end
Is there a typo in your code? The statement
set updated_prob prob_sum + 1
adds 1 to prob_sum, not to updated_prob and if prob_sum doesn't change from tick to tick, neither will updated_prob. Do you want
set updated_prob updated_prob + 1
instead?
Your code also has a lot of redundancies. If update_update_prob is executed only for grey turtles, then you don't need in update_update_prob to ask only gray turtles to do what you are doing in that procedure. Only gray turtles will execute it anyway. With lots of turtles, that can add a lot of overhead.
to update_update_prob
[set prob_sum probability_ebike_start + environment_add + subventionierung_bonus]
[set updated_prob updated_prob + 1]
end
should do it.
Related
How can I build a syntax for an "ifelse" statement that has a turtle in a specified patch and has the turtle determine if the turtle's color is the specified color? The following is sample code, but it won't work. Incidentally, I would like to build it using "max-pxcor - 1".
ifelse count turtles-on patch (max-pxcor - 1) with [color = red] = 1[ ;The following code is omitted
(1) The patch X Y notation selects a specific patch but you have not provided a pycor. I assume you therefore want any patch with the correct value for pxcor. How many of those patches are coloured red? (2) If you are not selecting a patch with its identifier, then you are working with a patchset rather than a patch, even if there is only one patch in that set. If you need to get a patch from a patchset, you need one-of.
If you actually want to identify that patch so you can do something with it, then this approach separates the patches from the turtles so is reasonably readable:
let wanted-patch one-of patches with [pxcor = max-pxcor - 1 and color = red]
ifelse count turtles-on wanted-patch = 1
[
But you could also do:
ifelse any? patches with [pxcor = max-pxcor - 1 and
color = red and
count turtles-here = 1]
[
Of, if you genuinely want the patchset so the total number of turtles on all the right hand column red patches is 1 (so 1 on one patch and 0 on others), then:
ifelse count (turtles-on patches with [pxcor = max-pxcor - 1 and color = red]) = 1
[
For this last one, the () are optional, for readability.
I want [turtles with [shape = "sheep"]] to move either to the lefthand side or the righthand side, depending on how many [attractive (green) patches] are around a certain relative patch.
How the turtles with [shape = "sheep"] should count the patches (yellow)
The (incorrect) code looks like this:
to move-sheep
ask turtles with [shape = "sheep"] [
right random (16 + (count neighbors4 with [pcolor = green] patch-right-and-ahead 60 2)^ 2)
left random (16 + (count neighbors4 with [pcolor = green] patch-right-and-ahead -60 2)^ 2)
forward 1
#(some other commands…)
]
end
Thank you ^^
It would be much easier if you actually told us what the problem is. You say your code is wrong, but not how you know it's wrong. Is it reporting an error (and, if so, what is the error and which line is reporting it)? Is the moving turtle going the wrong way?
Regardless, the easiest way to approach this is to do something smaller before trying to move. If you simply count the number of green patches and print that out, you can test the code. Once you introduce movement, how will you tell if it counted correctly?
I am still not entirely sure what you are asking. But I think this code might help you diagnose your problem. It tells you what the count is around the target patches, so you can see if it is doing the correct count. Once you know the counting works, you can then modify for movement.
to testme
clear-all
ask patches [set pcolor one-of [yellow green]]
create-turtles 1 [set heading 30 set color black]
ask one-of turtles
[ ask patch-right-and-ahead 60 2 [set pcolor red]
type "Right: "
print count ([neighbors4] of patch-right-and-ahead 60 2) with [pcolor = green]
ask patch-right-and-ahead -60 2 [set pcolor red]
type "Left: "
print count ([neighbors4] of patch-right-and-ahead -60 2) with [pcolor = green]
]
end
Dear Stackoverflow users,
I am a newbie to NetLogo and the community here, so I hope I can express myself adequately. If you need more information in order to understand my question, please, let me know. As I am not completely sure, where my problem lies, my title might even be misleading.
Here is what I am trying to do: I want an ego-centric network model, in which 1 ego (a Latino immigrant in the US) starts with a given value (between 1 and 6) for
identification with Latino culture and
identification with US/White culture.
The ego (breed #1) has 8 alters (breed #2). The alters consist of Latinos and Whites (ratio to be determined by slider in the interface: number-Latinos). The alters are randomly connected between themselves (amount of undirected links to be determined by another slider in the interface: number-of-alter-links). Each alter has a value for degree d (which is the number of links within the same ethnicity).
At each tick, ego is supposed to interact randomly with one of the alters. If the alter is Latino, then ego's initial value for Latino identification should increase by 0.1 + d * 0.1. If the alter is White, ego's initial value for US identification should increase by 0.1 + d * 0.1. The maximum value that can be reached for the identification variables is 6.
Here comes the code:
breed [egos ego]
breed [alters alter]
egos-own[identification-US identification-Latino]
alters-own[degree]
to setup
clear-all
setup-alters
setup-egos
reset-ticks
end
to setup-alters
create-alters 8
[layout-circle alters 8
if who < number-Latinos [set color orange] ; Latinos are orange
if who >= number-Latinos [set color yellow] ; Whites are yellow
]
while [count links < number-of-alter-links][
let node1 random 8
let node2 random 8
if (node1 != node2)[
ask alter node1 [create-link-with alter node2]
]
]
ask alters [ ; set degree within same ethnicity
ifelse color = yellow
[set degree (count link-neighbors with [color = yellow])]
[set degree (count link-neighbors with [color = orange])]
]
end
to setup-egos
create-egos 1 [
set identification-US initial-US-identification-ego
set identification-Latino initial-Latino-identification-ego]
end
to go
if ticks >= 50 [stop]
interact
change-identification
tick
end
to interact
ask egos [create-link-with one-of alters [set color green]]
end
to change-identification
ask links with [color = green] [let d [degree] of end1
ask egos [
ifelse link-neighbors = yellow
[ifelse (identification-US < 6)
[set identification-US identification-US + 0.1 + d * 0.1]
[set identification-US 6]
]
[ifelse (identification-Latino < 6)
[set identification-Latino identification-Latino + 0.1 + d * 0.1]
[set identification-Latino 6]
]
]
]
ask egos [ask my-links [die]]
end
This is my problem: When I am running the simulation, only the value for Latino identification changes, but not the one for US identification. This is even true, when there are no Latinos in the network. I am not sure where the problem lies. Is it in the nested ifelse command? I have tried to work my way around the nested ifelse and made several if commands, but the problem remains. Does it have to do with how I defined the two ethnicities with colors? Also, when I ask in the command center something about a particular turtle (e.g., turtle 3), I get the answer 9 times (total number of turtles). Maybe the problem is how I ask the link-neighbor(s) for its color?
Thanks for your attention! Any idea, suggestion or possible solution is highly appreciated.
This will always be false: link-neighbors = yellow.
Btw, if you post an entire model like this, you need to replace the interface globals with code-based declaration and initialization of the variables.
i am making a model for a class in netlogo, but i have run into a problem, whenever a turtle asks the patch that it is on what color it is, it thinks that it is black, even when it is colored white
globals [var inside outside var1 ratio]
turtles-own [randomX randomY]
to setup
reset-ticks
ask patches [set pcolor black]
set var 0
set var1 0
while [var <= 360] [ask patch 0 0 [sprout 1 [set color white set heading var pd fd 100]]set var var + 0.15]
ask turtles [die]
tick
end
to go
ask patch 0 0 [sprout 1[]]
check-location
ask turtles [set randomX random 2000000 / 10000 - 100
set randomY random 2000000 / 10000 - 100
set xcor randomX
set ycor randomY]
tick
reset-variables
end
to check-location
ask turtles [ ask patch-here[if pcolor != black [set inside inside + 1]]]
ask turtles [ ask patch-here[if pcolor != white [set outside outside + 1]]]
end
to reset-variables
set outside 0
set inside 0
end
I have a setup button, a go button with forever checked, a monitor that shows the variable inside, another monitor that shows the variable outside, and a monitor that shows count turtles. the outside monitor always shows the same number as the total monitor. any help would be greatly appreciated.
Putting the turtles pen down colors over the patches. It does not change the color of the patches. (You just cannot see that anymore.) To changes the patch color, always use pcolor.
I have the code :
if color of patch-here = blue [set heading towards one-of patches in-radius 180 with pcolor = grey ( do that or ) die ]
What I want to be able to do is to allow each turtle to randomly select one of the two options. I appreciate I could assign each command a number and then use a random number generator to select one of the two commands, but I am wondering whether there is a combination of commands that I could use to replace ( do that or ).
Thanks.
Roll a dice, if dice < 5, do something, else do the other thing. Example:
if pcolor = blue [
let dice random 10
ifelse dice < 5 [
set heading towards one-of patches in-radius 180 with pcolor = grey]
[die]
]