Baseline Netlogo model
From Santa Fe Institute Events Wiki
breed [problems problem]
problems-own [ problem-list number-solved components-solved solutions-used ]
breed [solutions solution]
solutions-own [ solution-list ]
globals
[ match-level; indicates the least number of bits that must be correct ]
to setup
clear-all setup-problems setup-solutions set match-level ( round ( 1 - (solution-number-of-bits * (100 - match-level-percent) / 100 ))) setup-plot plot-problems
end
to setup-problems
set-default-shape problems "target"
create-problems number-of-problems
[
set color red
set size 2
set number-solved 0
set components-solved []
set solutions-used []
set problem-list (list (list 1))
set problem-list but-first problem-list
repeat problem-number-of-components
[
let t1 (list (random 2))
repeat solution-number-of-bits - 1
[
set t1 lput (random 2) t1 ; lput = put on the list
]
set problem-list lput t1 problem-list
]
setxy (random-float world-width) ; randomize problem location width-wise
(random-float world-height) ; randomize problem location height-wise
]
end
to setup-solutions
set-default-shape solutions "circle"
create-solutions number-of-solutions
[
set color blue
set solution-list list (random 2) (random 2) ; why repeat random 2 twice?
repeat solution-number-of-bits - 2 ; what is the significance of -2?
[
set solution-list lput (random 2) solution-list
]
setxy (random-float world-width) ; randomize solution location width-wise
(random-float world-height) ; randomize solution location height-wise
]
end
to-report hamming-distance [list1 list2]
let difference 0
let step 0
repeat solution-number-of-bits
[
if ( item step list1 != item step list2 )
[
set difference difference + 1
]
set step step + 1
]
report difference
end
to move-problems
ask problems [ rt random-float 30 - random-float 30 fd 2 ]
end
to move-solutions
ask solutions [ rt random-float 30 - random-float 30 fd 2 ]
end
to solve
; let me 0
; let friends []
; let step 0
without-interruption
[
ask problems
[
let me self
let friends []
let step 0
ifelse region
[
ask solutions in-radius region-size
[
set friends lput self friends; ask all nearby solutions to put themselves on the list of friends; lput = put on the list
]
]
[
ask solutions ; this is the "else" part
[
set friends lput self friends; why is this identical to the code above?
]
]
foreach friends
[
set step 0
let this-solution self
repeat problem-number-of-components
[
if not member? step [components-solved] of me
[
if (( hamming-distance [solution-list] of ? ( item step [problem-list] of me )) <= match-level )
[
ask me
[
set number-solved (1 + [number-solved] of me)
set solutions-used lput [solution-list] of ? [solutions-used] of me
set components-solved lput step [components-solved] of me
]
]
]
set step step + 1
]
]
]
]
end
to go
move-problems move-solutions solve plot-problems copy-problem
end
to plot-problems
set-current-plot "Partially and fully solved problems" clear-plot set-plot-x-range 0 problem-number-of-components + 1 set-current-plot-pen "default" let step 0 repeat problem-number-of-components + 1 [ plotxy step count problems with [number-solved = step] set step step + 1 ]
end
to setup-plot
set-current-plot "Partially and fully solved problems" set-plot-y-range 0 number-of-problems set-plot-x-range 0 problem-number-of-components + 1
end
