It is a pretty simple model so far. I want the walker to move to the patches, but not randomly how it is now but with a probability. In this case it is the list "priority" which describes the probability for each patch (used vehicle).
So my question: How can I implement the calculated priority to the move statement?
Here's the code:
breed [nodes node]
breed [walkers walker]
globals [
cost
time
wellbeing
efficiency
vec1
vec2
vec3
nodelist
; rain
]
walkers-own [
Temp_best ;aim temp
capital ; capital for each timestep to invest in transportation
adaptation
location
priority
delta-priority
] ;; holds a node
patches-own [
]
to setup
clear-all
set-default-shape nodes "circle"
;; create a random network
create-nodes 1 [ set color white ]
create-nodes 1 [ set color blue ] ;car
create-nodes 1 [ set color yellow ] ;bike
create-nodes 1 [ set color green ] ;public transportation
ask node 0 [ create-link-with node 1 ]
ask node 0 [ create-link-with node 2 ]
ask node 0 [ create-link-with node 3 ]
;; lay it out so links are not overlapping
repeat 500 [ layout ]
;; leave space around the edges
ask nodes [ setxy 0.95 * xcor 0.95 * ycor ]
;; put some "walker" turtles on the network
create-walkers 1 [
set color red
set location node 0
move-to location
]
reset-ticks
ask walkers [
set capital 5
set adaptation 0.1
set wellbeing n-values 3 [0]
set priority n-values 3 [0] ;sum of all must be 1
set delta-priority n-values 3 [0] ;sum of all must be 0
set efficiency n-values 3 [0]
]
set cost [3.5 1 0.1]
set time [0.3 0.6 0.7]
set vec1 [0.7 0.7 0.7] ;if change one, than also the other --> sum must be 1
set vec2 [0.3 0.3 0.3] ;
set vec3 [1 1 1]
ask walkers[
output-print wellbeing
]
set cost (map * cost vec1)
set time (map * time vec2)
ask walkers[
output-print cost
output-print time
]
ask walkers [
set wellbeing (map + cost time)
set wellbeing (map / vec3 wellbeing) ;devided by 1 to have a high number for wellbeing
set priority [0 0.1 0.9]
; set priority (map + priority delta-priority)
if rain? [
set priority replace-item 2 priority 0
set priority replace-item 1 priority (1 - item 0 priority + item 2 priority)
]
]
ask walkers[
output-print wellbeing
output-print priority
]
;set efficiency replace-item 1 efficiency (wellbeing 1 / )
set efficiency (map / wellbeing cost)
output-print efficiency
;end
;to calculate
;ask walker[
;set delta-priority replace-item 0 delta-priority ( adaptation * item 0 priority * ((item 0 wellbeing) - ) - ((item 1 priority * item 1 wellbeing)+(item 2 priority * item 2 wellbeing)))
; set priority replace-item 0 priority (priority 0 + delta-priority 0)
;set priority replace-item 1 priority (priority 1 + delta-priority 1)
;set priority replace-item 2 priority (priority 2 + delta-priority 2)
; set priority (map + priority delta-priority)
;ifelse wellbeing 2 > wellbeing 1
; output-print delta-priority
; ]
end
to layout
layout-spring nodes links 0.5 2 1
end
to go
ask links [ set thickness 0 ]
ask walkers [
let new-location one-of nodes ;i want to introduce the priority for each node
;one-of [link-neighbors] of location
;; change the thickness of the link I just crossed over
;ask [link-with new-location] of location [ set thickness 0.5 ]
face new-location ;; not strictly necessary, but improves the visuals a bit
move-to new-location
set location new-location
]
tick
ask nodes
[show count walkers-here]
end
Related
With this model I need the code for the first year (tick = 0) to be different to the remaining 4. I've run the code below and the first tick runs ok, it then ticks and stops - none of the tick = 1 code seems to be running.
globals [num_agents difference year leader_test ]
breed [tasks task]
breed [managers manager ]
tasks-own [requirement leadership matched ]
managers-own [ability wealth matched requirement task_leader]
to setup
clear-all
set num_years 5
set tolerance 5
set num_agents 100
create-tasks num_agents [
set shape "box"
set leadership one-of [10 20 30 40 50 60 70 80 90 100]
ifelse who < 50 [setxy 0 who set color blue][setxy 45 (who - 50) set color blue]
set heading 90
set requirement who + 100
set matched 0
]
create-managers num_agents [
setxy random 30 + 10 random 50
set shape "person" set color green set heading 270
set ability (who - num_agents + 100)
set wealth 0 set matched 0
]
reset-ticks
end
to go
;;first year -different to remaining
ifelse ticks < 1 [
ask managers with [matched = 0]
[show ticks
move-to one-of tasks with [matched = 0]
fd -1
set requirement [requirement] of one-of tasks-on patch-ahead 1
set task_leader [leadership] of one-of tasks-on patch-ahead 1
set difference abs(requirement - ability)
set matched 1
set wealth (requirement)
show wealth
show task_leader
ask tasks-on patch-ahead 1 [set matched 1 set shape "arrow" set heading 0]
if difference > tolerance [set color red ask tasks-on patch-ahead 1 [set shape "circle" ] ]]
]
; years 2 - num_years
[
ask managers [
if ability > (requirement + tolerance) [
ask tasks-on patch-ahead 1 [set matched 0 set shape "box" ]
setxy random 30 + 10 random 50
set shape "person" set color green set heading 270 set matched 0
]
]
ask managers with [matched = 1]
[ set leader_test random 100
if ability < (requirement - tolerance) [
if leader_test <= task_leader
[;;leader should make correct decision and fire manager
ask tasks-on patch-ahead 1 [set matched 0 set shape "butterfly" ]
setxy random 30 + 10 random 50
set shape "person" set color green set heading 270 set matched 0]
]
]
]
ask managers with [matched = 0]
[move-to one-of tasks with [matched = 0]
fd -1
set matched 1]
ask managers with [matched = 1][
set requirement [requirement] of one-of tasks-on patch-ahead 1
set task_leader [leadership] of one-of tasks-on patch-ahead 1
set difference abs(requirement - ability)
set wealth (wealth + requirement)
ask tasks-on patch-ahead 1 [set matched 1 set shape "arrow" set heading 0]
if difference > tolerance [set color red ask tasks-on patch-ahead 1 [set shape "circle" ]
]
]
ifelse ticks > (num_years ) [
stop] [tick ]
I have had problems with ticks and stop before - there is obviously something I'm not getting.
Per LeirsW
It runs just fine for me. You are using a forever button right?
I will be very grateful if someone could give me any kind of advice about a problem that I have in my code. I am working on a model with four kind of agents. Each type of agents uses a different strategy. These strategies are Prisoner Dilemma variations. Two of these strategies (tit for tat and unforgiving) need to record (in a list) who was the partner of interaction, and depending if that partner defected or not, will be the behave (cooperative or defect) of the agent in the next encounter with the same partner. Agents move randomly through the world. The problem come when agents die or birth according of their resources level. At this point these strategies that require to record who was the previous partner and how was his behave (cooperative or defect) do not work. This is the message that show up.
I am really appreciate any support!!!!.
number of initial turtles is 42, but two ticks later the number is 52
Below is a code that reproduces the error. In order to run it, it is necessary to create the sliders: n-tit-for-tat-com; n-unforgiving-com; inc-ecological-resources; energy-consume-companies:
globals
[
;;Number of companies with each strategy¨
num-tit-for-tat-com
num-unforgiving-com
;;number of interactions by each strategy
num-tit-for-tat-com-games
num-unforgiving-com-games
;; Total score of all companies playing each strategy
tit-for-tat-com-score
unforgiving-com-score
; Total companies en each ticks
num-companies
]
breed [companies company]
;;create companies variables
companies-own [
score-com
score-com-round
strategy-com
defect-now?-com
partner-defected?-com ;;action of the partner
partnered?-com ;;am I partnered?
partner-com ;;WHO of my partner (nobody if not partnered)
partner-history-com ;;a list containing information about past interactions with other turtles (indexed by WHO values)
earnings-tit-for-tat-Com
earnings-unforgiving-Com
earnings-com
tit-for-tat-com-score-round
unforgiving-com-score-round
]
patches-own
[
resources-amount ;; resources amount in each patches
resources-to ;; aux variable to count resources taken
]
;;;Setup Procedures;;;
to setup
clear-all
setup-patches
setup-companies ;;setup the turtles and distribute them randomly
reset-ticks
end
; Setup patches
;===============
to setup-patches
ask patches [set resources-amount random 4] ;; patches represent ecological system. Resources are distributed randomly. [0,1,2 or 3] 0 -> non resources; 3 -> plenty of resources
ask patches [
set pcolor (ifelse-value
resources-amount = 0 [49]
resources-amount = 1 [58]
resources-amount = 2 [67]
resources-amount = 3 [65]
[63] ;; this case never happen. Because 4 means integer number in range [0 to 3]
)]
end
to setup-companies
make-companies ;;create the appropriate number of turtles playing each strategy
setup-common-variables-com ;;sets the variables that all turtles share
end
;;create the appropriate number of turtles playing each strategy
to make-companies
create-companies n-tit-for-tat-com
[ set strategy-com "tit-for-tat-com"
set color 135
set earnings-tit-for-tat-Com random 4 + 1 ;;randomly initial resources in the range [ 1 - 4 ]. It is sum + 1 to enforce never inicial resource = 0
]
create-companies n-unforgiving-com
[ set strategy-com "unforgiving-com"
set color 4
set earnings-unforgiving-Com random 4 + 1 ;;randomly initial resources in the range [ 1 - 4 ]. It is sum + 1 to enforce never inicial resource = 0
]
end
; Setup common variables
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
;;set the variables that all turtles share
to setup-common-variables-com
ask companies [
set shape "pentagon"
set size 1.3
set tit-for-tat-com-score-round 0
set unforgiving-com-score-round 0
set score-com 0
set partnered?-com false
set partner-com nobody
setxy random-xcor random-ycor
]
end
;;;Runtime Procedures;;;
to go
ask companies [birth-die-com]
store-initial-companies-counts ;;record the number of turtles for each strategy
setup-history-lists-com
clear-last-round
ask companies [ partner-up-com ] ;;have turtles try to find a partner
let partnered-com companies with [ partnered?-com ]
ask partnered-com [ select-strategy-com ] ;;all partnered turtles select action
ask partnered-com [ play-a-round-com ]
adjust-patches
tick
end
;Birth-die-com ; According to the level of resources companies can die or birth
;======================
to birth-die-com
(ifelse
strategy-com = "tit-for-tat-com"
[
set earnings-com earnings-tit-for-tat-com
(if earnings-com > 2 * energy-consume-companies [
hatch 1 [set earnings-tit-for-tat-com random 2 + 1 ] ;;randomly initial resources in the range [ 1 - 2 ]. It is sum + 1 to enforce never inicial resource = 0
set earnings-com (earnings-com - energy-consume-companies )])
( if earnings-com < energy-consume-companies [ die ])
]
strategy-com = "unforgiving-com"
[
set earnings-com earnings-unforgiving-com
(if earnings-com > 2 * energy-consume-companies [
hatch 1 [set earnings-unforgiving-com random 2 + 1 ] ;;randomly initial resources in the range [ 1 - 2 ]. It is sum + 1 to enforce never inicial resource = 0
set earnings-com (earnings-com - energy-consume-companies )])
( if earnings-com < energy-consume-companies [ die ])
]
)
end
;;STORE INITIAL COMPANIES¨
;===========================
;;record the number of turtles at the begining of each tick
;;The number of turtles of each strategy is used when calculating average payoffs.
to store-initial-companies-counts
set num-tit-for-tat-com (count companies with [strategy-com = "tit-for-tat-com"])
set num-unforgiving-com (count companies with [strategy-com = "unforgiving-com"])
end
;Setup-History-Lists-com;; initialize PARTNER-HISTORY list in all turtles
;========================
to setup-history-lists-com
set num-companies (count companies)
let default-history-com [] ;;initialize the DEFAULT-HISTORY variable to be a list
;create a list with NUM-TURTLE elements for storing partner histories
repeat (count companies) [ set default-history-com (fput false default-history-com) ]
;give each turtle a copy of this list for tracking partner histories
ask companies [ set partner-history-com default-history-com ]
end
;Clear-last-round
;================
to clear-last-round
let partnered-com companies with [ partnered?-com ]
ask partnered-com [ release-partners-com ]
end
; release partner between companies and turn around
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
to release-partners-com
set partnered?-com false
set partner-com nobody
rt 180
set label ""
end
;;have turtles try to find a partner
;;Since other turtles that have already executed partner-up may have
;;caused the turtle executing partner-up to be partnered,
;;a check is needed to make sure the calling turtle isn't partnered.
;;partner-up. Find partner
;===========================
to partner-up-com ;;turtle procedure
if (not partnered?-com) [ ;;make sure still not partnered
rt (random-float 90 - random-float 90) fd 1 ;;move around randomly
set partner-com one-of other (companies in-radius 1 ) with [ not partnered?-com ]
if partner-com != nobody [ ;;if successful grabbing a partner, partner up
set partnered?-com true
set heading 270 ;;face partner
ask partner-com [
set partnered?-com true
set partner-com myself
set heading 90
]
]
]
end
;Select stratey company
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
;;choose an action based upon the strategy being played
to select-strategy-com ;;turtle procedure
if strategy-com = "tit-for-tat-com" [ tit-for-tat-com ]
if strategy-com = "unforgiving-com" [ unforgiving-com ]
end
;Play a round-companies
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
to play-a-round-com ;;turtle procedure
get-payoff-com ;;calculate the payoff for this round
update-history-com ;;store the results for next time
end
; get-payoff-com
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
;;calculate the payoff for this round and
;;display a label with that payoff.
;; Strategy-companies
;Turtles l l
;Action l C l D
;__________l________ l__________
; C l 3 l -3
;----------l---------l----------
; D l 5 l -2
to get-payoff-com
set partner-defected?-com [defect-now?-com] of partner-com
ifelse partner-defected?-com [
ifelse defect-now?-com
[ set score-com (score-com + 1 ) set label 1 set score-com-round 1 ]
[set score-com (score-com + 0) set label 0 set score-com-round 0]
]
[ifelse defect-now?-com
[set score-com (score-com + 5) set label 5 set score-com-round 5]
[set score-com (score-com + 3) set label 3 set score-com-round 3]
]
end
;Update-history
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨
;;update PARTNER-HISTORY based upon the strategy being played
to update-history-com
if strategy-com = "tit-for-tat-com" [ tit-for-tat-com-history-update ]
if strategy-com = "unforgiving-com" [ unforgiving-com-history-update ]
end
;;;Strategies;;;
; Tit-for-tat-com
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
to tit-for-tat-com
set num-tit-for-tat-com-games num-tit-for-tat-com-games + 1
set partner-defected?-com item ([who] of partner-com) partner-history-com
ifelse (partner-defected?-com)
[set defect-now?-com true]
[set defect-now?-com false]
ask companies in-radius 1 [
ask patches in-radius 1 [set resources-to (resources-amount * 1)]
ask patches in-radius 1 [set resources-amount (resources-amount - resources-to)]
set tit-for-tat-com-score-round ( tit-for-tat-com-score-round + score-com-round )
set earnings-tit-for-tat-com (earnings-tit-for-tat-Com + ((sum [ resources-to ] of patches in-radius 1)/ 2) + tit-for-tat-com-score-round - energy-consume-companies )
ask patches in-radius 1 [set resources-to 0 ]
set tit-for-tat-com-score-round 0
]
end
;Tit-for-tat-com-history-update¨
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
to tit-for-tat-com-history-update
set partner-history-com
(replace-item ([who] of partner-com) partner-history-com partner-defected?-com)
end
;unforgiving-com ; Works similar to tit-for-tat, but once the another defect, always defect
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
to unforgiving-com
set num-unforgiving-com-games num-unforgiving-com-games + 1
set partner-defected?-com item ([who] of partner-com) partner-history-com
ifelse (partner-defected?-com)
[set defect-now?-com true]
[set defect-now?-com false]
ask companies in-radius 1 [
ask patches in-radius 1 [set resources-to (resources-amount * 1)]
ask patches in-radius 1 [set resources-amount (resources-amount - resources-to)]
set unforgiving-com-score-round ( unforgiving-com-score-round + score-com-round )
set earnings-unforgiving-com (earnings-unforgiving-Com + ((sum [ resources-to ] of patches in-radius 1)/ 2) + unforgiving-com-score-round - energy-consume-companies)
ask patches in-radius 1 [set resources-to 0 ]
set unforgiving-com-score-round 0
]
end
;unforgiving-com-history-update
;¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
to unforgiving-com-history-update
if partner-defected?-com [
set partner-history-com
(replace-item ([who] of partner-com) partner-history-com partner-defected?-com)
]
end
;; Adjusting Patches
;; Put limits
to adjust-patches
ask patches [ set resources-amount resources-amount + random-float Inc-Ecological-resources ] ;; Resources are renewable. They grow up again between [0-3). Use Slider
ask patches [ ;; Resources range [0-3)
set resources-amount (ifelse-value
resources-amount < 0 [0] ;;
resources-amount > 3 [3] ;;
[resources-amount]
)
]
;; Patches are colored according their level
ask patches [
set pcolor (ifelse-value
resources-amount < 0 [ black ]
resources-amount = 0 [ 38 ]
resources-amount > 0 and resources-amount <= 0.5 [ 49 ]
resources-amount > 0.5 and resources-amount <= 2 [ 67 ]
resources-amount > 2 and resources-amount <= 3 [ 65 ]
resources-amount > 3 and resources-amount <= 4 [ 63 ]
[ white ])
]
end
I'm creating a code that is supposed to make a certain number of turtles have a status of 1 and the rest have a status of 0, the number is calculated using slider inputs from the interface. I've been trying to make the program use n-of but it turns more than the desired number of turtles into the 1 variety (the turtles are set to status 0 from before).
code below (switch for single is to change to only one turtle and tumble switch is for modelling tumbling and running):
to spawn
ifelse (single = false )
[create-turtles N [
set color black
set xcor 0
set ycor 0
set heading random-float 360
set status 0
if (tumble = true)
[
print (N * p1 / (p1 + p2))
ask n-of (N * p1 / (p1 + p2)) turtles [set status 1 set color red]]
]
]
[create-turtles 1 [
set color black
set xcor 0
set ycor 0
set heading random-float 360
pendown
]]
end
The problem is in your placement of the ask n-of statement. The code is the brackets after create-turtles N is executed for each turtle that is created, so each of the N created turtles is in turn asking n-of ... turtles to set status to 1. You will get many more turned turtles than you want. Moving the if (tumble ... block out of the create-turtles block should lead to its being executed only once, after all N turtles are created.
to spawn
ifelse (single = false ) [
create-turtles N [
set color black
set xcor 0
set ycor 0
set heading random-float 360
set status 0
]
if (tumble = true) [
print (N * p1 / (p1 + p2))
ask n-of (N * p1 / (p1 + p2)) turtles [set status 1 set color red]
]
]
[create-turtles 1 [
set color black
set xcor 0
set ycor 0
set heading random-float 360
pendown
]
]
end
I am working with the daisyworld model and am planning to add a predator to the model which will eat the daisies (this is for a class project). I have successfully added the predators (brown rabbits eat the white daisies, grey rabbits eat the black daisies). But in order for them to eat the daisies, their coordinates have to line up perfectly causing very little "eating" to occur. Is there a way for me to generate rabbits with random xy cor but be generated in the exact center of the pixel?
globals [
max-age ;; maximum age that all daisies live to
global-temperature ;; the average temperature of the patches in the world
num-blacks ;; the number of black daisies
num-whites ;; the number of white daisies
scenario-phase ;; interval counter used to keep track of what portion of scenario is currently occurring
]
breed [daisies daisy]
breed [brown-rabbits brown-rabbit]
breed [grey-rabbits grey-rabbit]
patches-own [temperature] ;; local temperature at this location
daisies-own [
age ;; age of the daisy
albedo ;; fraction (0-1) of energy absorbed as heat from sunlight
daisy-black ;; boolean if daisy is black
]
brown-rabbits-own
[energy]
grey-rabbits-own
[energy]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Setup Procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
clear-all
set-default-shape daisies "flower"
ask patches [ set pcolor gray ]
set max-age 25
set global-temperature 0
if (scenario = "ramp-up-ramp-down" ) [ set solar-luminosity 0.8 ]
if (scenario = "low solar luminosity" ) [ set solar-luminosity 0.6 ]
if (scenario = "our solar luminosity" ) [ set solar-luminosity 1.0 ]
if (scenario = "high solar luminosity") [ set solar-luminosity 1.4 ]
seed-blacks-randomly
seed-whites-randomly
ask daisies [set age random max-age]
ask patches [calc-temperature]
set global-temperature (mean [temperature] of patches)
update-display
;reset-ticks
create-grey-rabbits grey-rabbit-number
[
setxy random-xcor random-ycor
set shape "rabbit"
set size 1.5
set color grey
set energy random (2 * grey-rabbit-gain-from-food)
]
create-brown-rabbits brown-rabbit-number
[
setxy random-xcor random-ycor
set shape "rabbit"
set size 1.5
set color brown
set energy random (2 * brown-rabbit-gain-from-food)
]
reset-ticks
end
to seed-blacks-randomly
ask n-of round ((start-%-blacks * count patches) / 100) patches with [not any? daisies-here]
[ sprout-daisies 1 [set-as-black] ]
ask daisies [set daisy-black true]
end
to seed-whites-randomly
ask n-of floor ((start-%-whites * count patches) / 100) patches with [not any? daisies-here]
[ sprout-daisies 1 [set-as-white] ]
ask daisies [set daisy-black false]
end
;to daisy-black
; ifelse color = 0
; [daisy-black true]
; [daisy-black false]
;end
;ask daisies if color = 0 [set daisy-black true]
;ask daisies if color = 9.9 [set daisy-black false]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Runtime Procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
ask grey-rabbits [
move
set energy energy - 1
eat-black-daisies
death
reproduce-grey-rabbits
]
ask brown-rabbits [
move
set energy energy - 1
eat-white-daisies
death
reproduce-brown-rabbits
]
ask patches [calc-temperature]
diffuse temperature .5
ask daisies [check-survivability]
set global-temperature (mean [temperature] of patches)
update-display
tick
if scenario = "ramp-up-ramp-down" [
if ticks > 200 and ticks <= 400 [
set solar-luminosity precision (solar-luminosity + 0.005) 4
]
if ticks > 600 and ticks <= 850 [
set solar-luminosity precision (solar-luminosity - 0.0025) 4
]
]
if scenario = "low solar luminosity" [ set solar-luminosity 0.6 ]
if scenario = "our solar luminosity" [ set solar-luminosity 1.0 ]
if scenario = "high solar luminosity" [ set solar-luminosity 1.4 ]
end
to move
rt random 20
lt random 20
fd 1
end
to eat-black-daisies ;grey rabbits eat black daisies
ask grey-rabbits
[if any? daisies-here with [daisy-black = true]
[let prey one-of daisies-here; with [daisy-black = true]
if prey != nobody
[ask prey [die]
set energy energy + grey-rabbit-gain-from-food]
]
]
end
to eat-white-daisies ;brown rabbits eat white daisies
; ask brown-rabbits
; ;[if any? daisies-here with [daisy-black = false]
; patch-here
; [let prey one-of daisies-here with [daisy-black = false]
; if prey != nobody
; [ask prey [die]
; set energy energy + brown-rabbit-gain-from-food]
; ]
; ;]
end
to reproduce-grey-rabbits
if random-float 100 < grey-rabbits-reproduce [
set energy (energy / 2)
hatch 1 [rt random-float 360 fd 1]
]
end
to reproduce-brown-rabbits
if random-float 100 < brown-rabbits-reproduce [
set energy (energy / 2)
hatch 1 [rt random-float 360 fd 1]
]
end
to death
if energy < 0 [die]
end
to set-as-black ;; turtle procedure
set color black
set albedo albedo-of-blacks
set age 0
set size 0.6
end
to set-as-white ;; turtle procedure
set color white
set albedo albedo-of-whites
set age 0
set size 0.6
end
to check-survivability ;; turtle procedure
let seed-threshold 0
let not-empty-spaces nobody
let seeding-place nobody
set age (age + 1)
ifelse age < max-age
[
set seed-threshold ((0.1457 * temperature) - (0.0032 * (temperature ^ 2)) - 0.6443)
;; This equation may look complex, but it is just a parabola.
;; This parabola has a peak value of 1 -- the maximum growth factor possible at an optimum
;; temperature of 22.5 degrees C
;; -- and drops to zero at local temperatures of 5 degrees C and 40 degrees C. [the x-intercepts]
;; Thus, growth of new daisies can only occur within this temperature range,
;; with decreasing probability of growth new daisies closer to the x-intercepts of the parabolas
;; remember, however, that this probability calculation is based on the local temperature.
if (random-float 1.0 < seed-threshold) [
set seeding-place one-of neighbors with [not any? daisies-here]
if (seeding-place != nobody)
[
if (color = white)
[
ask seeding-place [sprout-daisies 1 [set-as-white] ]
]
if (color = black)
[
ask seeding-place [sprout-daisies 1 [set-as-black] ]
]
]
]
]
[die]
end
to calc-temperature ;; patch procedure
let absorbed-luminosity 0
let local-heating 0
ifelse not any? daisies-here
[ ;; the percentage of absorbed energy is calculated (1 - albedo-of-surface) and then multiplied by the solar-luminosity
;; to give a scaled absorbed-luminosity.
set absorbed-luminosity ((1 - albedo-of-surface) * solar-luminosity)
]
[
;; the percentage of absorbed energy is calculated (1 - albedo) and then multiplied by the solar-luminosity
;; to give a scaled absorbed-luminosity.
ask one-of daisies-here
[set absorbed-luminosity ((1 - albedo) * solar-luminosity)]
]
;; local-heating is calculated as logarithmic function of solar-luminosity
;; where a absorbed-luminosity of 1 yields a local-heating of 80 degrees C
;; and an absorbed-luminosity of .5 yields a local-heating of approximately 30 C
;; and a absorbed-luminosity of 0.01 yields a local-heating of approximately -273 C
ifelse absorbed-luminosity > 0
[set local-heating 72 * ln absorbed-luminosity + 80]
[set local-heating 80]
set temperature ((temperature + local-heating) / 2)
;; set the temperature at this patch to be the average of the current temperature and the local-heating effect
end
to paint-daisies ;; daisy painting procedure which uses the mouse location draw daisies when the mouse button is down
if mouse-down?
[
ask patch mouse-xcor mouse-ycor [
ifelse not any? daisies-here
[
if paint-daisies-as = "add black"
[sprout-daisies 1 [set-as-black]]
if paint-daisies-as = "add white"
[sprout-daisies 1 [set-as-white]]
]
[
if paint-daisies-as = "remove"
[ask daisies-here [die]]
]
display ;; update view
]
]
end
to update-display
ifelse (show-temp-map? = true)
[ ask patches [set pcolor scale-color red temperature -50 110] ] ;; scale color of patches to the local temperature
[ ask patches [set pcolor grey] ]
ifelse (show-daisies? = true)
[ ask daisies [set hidden? false] ]
[ ask daisies [set hidden? true] ]
end
; Copyright 2006 Uri Wilensky.
; See Info tab for full copyright and license.
Instead of checking whether 2 turtles are exactly on the same spot, I would use patch-here to see if they are on the same patch.
https://ccl.northwestern.edu/netlogo/docs/dictionary.html#patch-here
I want x% of turtles, called pholders, to change their choice from a good 1 to a good 2.
The code is as follows:
ask pholders [ifelse random-float 1 <= probkauf
[ask (n-of (count pholders with [choice-num = 1] * 0.01) pholders with[choice-num = 1]) [set choice-num 2]]
[ifelse random-float 1 < 0.5[imitation set typeofchoice 1][beratung set typeofchoice 4]]
]
Initially 100% of the pholders chose good 1. The Problem is as follows: When i rise the number of pholders above something between 102 and 108 n-of doesn't calculate a 1%-fraction anymore, it calculates 10%. The higher the number of pholders the bigger the fraction: for 200 pholders the code calculates 60%. When i leave the number of pholders constant and below 108 but change the percentage from 0.01 to 0.02 it calculates something like 55% or 58%. Is the problem probably coming from ask n-of in an ask environment?
Thank you very much in advance.
Your problem is that you are running the probabilistic code multiple times. Your code has this structure:
ask pholders
[ ifelse random-float 1 <= probkauf
[ ask (n-of (count pholders with [choice-num = 1] * 0.01) pholders with [choice-num = 1])
[ set choice-num 2]
]
[ <do something else> ]
]
If you have 500 pholders, then there will be 500 times that a pholder selects a random number and, if the number is lower than your value probkauf, it instructs a number of pholders with choice-num of 1 to change it to choice-num 2. 500 potential occasions of 1% conversion is why you have so many being converted.
Based on the description in your comments, I think you want this:
globals [probkauf]
turtles-own [choice-num]
to setup
clear-all
set probkauf 0.5
create-turtles 1000
[ setxy random-xcor random-ycor
set color blue
set choice-num 1
]
reset-ticks
end
to go
update-choices
tick
end
to update-choices
ifelse random-float 1 < probkauf
[ ask turtles with [choice-num = 1]
[ if random-float 1 < 0.01
[ set choice-num 2
set color red
]
]
]
[ ; whatever happens with other part of probability
]
end