NetLogo
NetLogo

NetLogo

NetLogoNN
to setupcacrt N
ask turtles [set shape "circle"]layout-circle sort turtles 10endn(turtle n)
ask turtles [set label who]
05who

to link-example1
ask (turtle 0) [create-link-with turtle 5]
end
NetLogo"ask links [set thickness 0.2]"

to link-example2
ask turtles [create-link-with one-of other turtles with [not link-neighbor? self]]
end”World wraps horizontally" "World wraps vertically"to link-layout-spring
repeat 50 [ layout-spring turtles links 0.2 5 1 ]end

2to link-example3
ask turtles [create-link-with (turtle ((who + 1) mod N))]end
"a mod b"

ab

C%

24β

Webβ

44NPSPS4NetLogo
PS 0PS

10.0051-PS

ask turtles [ifelse (random-ﬂoat 1.0 < PS) [][]]
setup
create-sw- links

NetLogo

globals [ clustering-coefﬁcient average-path-length]
turtles-own [node-clustering-coefﬁcient distance-from-other-turtles]

to calc-clustering-coefﬁcient
ifelse all? turtles [count link-neighbors <= 1][;; it is undeﬁned;; what should this be?
set clustering-coefﬁcient 0][
let total 0
ask turtles with [ count link-neighbors <= 1][ set node-clustering-coefﬁcient "undeﬁned" ]ask turtles with [ count link-neighbors > 1][
let hood link-neighbors
set node-clustering-coefﬁcient (2 * count links with [ in-neighborhood? hood ] /((count hood) * (count hood - 1)) );; ﬁnd the sum for the value at turtles
set total total + node-clustering-coefﬁcient];; take the averageset clustering-coefﬁcient total / count turtles with [count link-neighbors > 1]]
end
to-report in-neighborhood? [ hood ]report ( member? end1 hood and member? end2 hood )end
to calc-average-path-length;; reset the distance list
ask turtles[
set distance-from-other-turtles []]let i 0
let j 0
let k 0let node1 one-of turtles
let node2 one-of turtles
let node-count count turtles;; initialize the distance lists
while [i < node-count] [set j 0while [j < node-count] [set node1 turtle i
set node2 turtle j;; zero from a node to itself
ifelse i = j[
ask node1 [set distance-from-other-turtles lput 0 distance-from-other-turtles]][;; 1 from a node to it's neighborifelse [ link-neighbor? node1 ] of node2[
ask node1 [set distance-from-other-turtles lput 1 distance-from-other-turtles]][
ask node1 [set distance-from-other-turtles lput 99999 distance-from-other-turtles]]]
set j j + 1]
set i i + 1]
set i 0
set j 0let dummy 0
while [k < node-count] [set i 0
while [i < node-count] [set j 0while [j < node-count][;; alternate path length through kth node
set dummy ( (item k [distance-from-other-turtles] of turtle i) +(item j [distance-from-other-turtles] of turtle k));; is the alternate path shorter?
if dummy < (item j [distance-from-other-turtles] of turtle i)[ask turtle i [set distance-from-other-turtles replace-item j distance-from-other-turtles dummy]]
set j j + 1]
set i i + 1]
set k k + 1]
let num-connected-pairs sum [length remove 99999 (remove 0 distance-from-other-turtles)] ofturtles
ifelse ( num-connected-pairs != (count turtles * (count turtles - 1) ))[set average-path-length 0][set average-path-length (sum [sum distance-from-other-turtles] of turtles) / (num-connectedpairs)]
endcalc-average-path-length
calc- clustering-coefﬁcient

average-path-length
clustering-coefﬁcient

Netlogo Models Library Small Worlds

βPS 0

1PS4PSPS”Plot””Edit”

setupto create-calc-sw
clear-turtles
create-turtles N [set shape "circle"]layout-circle sort turtles 10
create-sw-links
calc-average-path-length
update-plots
endPS

create-calc-sw

APL

10””

1/^αBA3

N

select-turtle-pa
create-sf
to-report select-node-pa
let total random-ﬂoat sum [count link-neighbors] of turtles
let partner nobody
ask turtles[let nc count link-neighbors
if partner = nobody [ifelse nc > total[ set partner self ][ set total total - nc ]]]report partner
end

Barabási–Albert

to create-sfca
crt 3 [set shape "circle"]
ask turtle 0 [create-links-with other turtles]
repeat N - 3 [let partner select-node-pa
let partner2 partner
while [partner2 = partner][set partner2 select-node-pa]
create-turtles 1 [create-link-with partner
create-link-with partner2
set shape "circle"]]repeat 500 [ layout-spring turtles links 0.2 8 0.5 ]update-plots
endhistogram [count link-neighbors] of turtles”Bar"PS

to create-sw
ca
crt N [set shape "circle"]create-sw

create-sw-links
layout-circle sort turtles 10
update-plotsend
Chooser

if

topology

Scale free

Chooser

topology

to setup_choose
if (topology = "Scale free") [create-sf]
if (topology = "Small world") [create-sw]
end

Small worldstateturtles-own[ ... ]state

update-propagate
to setup-propagate
setup_choose
clear-all-plots
ask turtles [set state 1]
ask one-of turtles [set state 0]
reset-ticks
update-propagate
end
to propagate
ask turtles [let partner one-of link-neighborsif (([state] of partner) = 0) [set state 0]]
update-propagate
end
to update-propagate
ask turtles [ifelse (state = 0) [set color red][set color blue]]
tickendsetup-propagate
propagate01

setup-propagate

propagate"plot count turtles with [state = 0]"

BehaviorSpace
BehaviorSpacePS"Tools" "BehaviorSpace""New"["PS" [0 0.1 1]] "PS”

01["PS" 0 0.1 1]

Repetitions
Measure runs...
"count turtles with [state = 0]"
Setup commands
Go commands
Time limit

0.1110, 0.1, 1s0experiment

RunOK

CSV Comma separated vector678 910111213
141516PS””””

Cooperate

P1 / P2””

C

Defect DCCD

D(R, R) = (4, 4)(S, T) = (0, 5)(T, S) = (5, 0)(P, P) = (1, 1)(x, y) = (P1

T, R, P, S

T>R>P>SP2

CD

state
state=1

state=0

score
turtles-own[ ... ]scorestate_next

R, T, P, S0
game
score

to gameask turtles [set score 0]
ask turtles [let player self
ask link-neighbors [if (([state] of player = 0) and (state = 0)) [set score (score + P)]
if (([state] of player = 0) and (state = 1)) [set score (score + S)]
if (([state] of player = 1) and (state = 0)) [set score (score + T)]
if (([state] of player = 1) and (state = 1)) [set score (score + R)
]
]
]
end
evolve
score

50.01

scoreto evolve
game
ask turtles [set state_next state]
ask turtles [set state_next stateif((max [score] of link-neighbors) > score) [set state_next ([state] of (max-one-of link-neighbors [score]))]]ask turtles [set state state_next]
update-propagate
end

setup-propergate

N=100

evolve