A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
44
Task/Evolutionary-algorithm/Logo/evolutionary-algorithm.logo
Normal file
44
Task/Evolutionary-algorithm/Logo/evolutionary-algorithm.logo
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
make "target "|METHINKS IT IS LIKE A WEASEL|
|
||||
|
||||
to distance :w
|
||||
output reduce "sum (map.se [ifelse equal? ?1 ?2 [0][1]] :w :target)
|
||||
end
|
||||
|
||||
to random.letter
|
||||
output pick "| ABCDEFGHIJKLMNOPQRSTUVWXYZ|
|
||||
end
|
||||
|
||||
to mutate :parent :rate
|
||||
output map [ifelse random 100 < :rate [random.letter] [?]] :parent
|
||||
end
|
||||
|
||||
make "C 100
|
||||
make "mutate.rate 10 ; percent
|
||||
|
||||
to breed :parent
|
||||
make "parent.distance distance :parent
|
||||
localmake "best.child :parent
|
||||
repeat :C [
|
||||
localmake "child mutate :parent :mutate.rate
|
||||
localmake "child.distance distance :child
|
||||
if greater? :parent.distance :child.distance [
|
||||
make "parent.distance :child.distance
|
||||
make "best.child :child
|
||||
]
|
||||
]
|
||||
output :best.child
|
||||
end
|
||||
|
||||
to progress
|
||||
output (sentence :trials :parent "distance: :parent.distance)
|
||||
end
|
||||
|
||||
to evolve
|
||||
make "parent cascade count :target [lput random.letter ?] "||
|
||||
make "trials 0
|
||||
while [not equal? :parent :target] [
|
||||
make "parent breed :parent
|
||||
print progress
|
||||
make "trials :trials + 1
|
||||
]
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue