Data update
This commit is contained in:
parent
aec8ed51b6
commit
29a5eea0d4
128 changed files with 1298 additions and 0 deletions
39
Task/Evolutionary-algorithm/ABC/evolutionary-algorithm.abc
Normal file
39
Task/Evolutionary-algorithm/ABC/evolutionary-algorithm.abc
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
PUT "ABCDEFGHIJKLMNOPQRSTUVWXYZ " IN alphabet
|
||||
|
||||
HOW TO RETURN initial.state target:
|
||||
SHARE alphabet
|
||||
PUT "" IN state
|
||||
FOR c IN target: PUT state^choice alphabet IN state
|
||||
RETURN state
|
||||
|
||||
HOW TO RETURN state fitness target:
|
||||
PUT #target IN score
|
||||
FOR i IN {1..#target}:
|
||||
IF state item i = target item i: PUT score-1 IN score
|
||||
RETURN score
|
||||
|
||||
HOW TO RETURN chance mutate state:
|
||||
SHARE alphabet
|
||||
PUT "" IN mutated
|
||||
FOR i IN {1..#state}:
|
||||
SELECT:
|
||||
random < chance: PUT choice alphabet IN next
|
||||
ELSE: PUT state item i IN next
|
||||
PUT mutated^next IN mutated
|
||||
RETURN mutated
|
||||
|
||||
HOW TO EVOLVE TOWARD target:
|
||||
PUT 0.1 IN mutation.rate
|
||||
PUT 100 IN generation.size
|
||||
PUT initial.state target IN state
|
||||
WHILE state fitness target > 0:
|
||||
WRITE (state fitness target)>>2, ": ", state/
|
||||
PUT {} IN next.generation
|
||||
FOR i IN {1..generation.size}:
|
||||
PUT mutation.rate mutate state IN child
|
||||
PUT child fitness target IN score
|
||||
PUT child IN next.generation[score]
|
||||
PUT next.generation[min keys next.generation] IN state
|
||||
WRITE (state fitness target)>>2, ": ", state/
|
||||
|
||||
EVOLVE TOWARD "METHINKS IT IS LIKE A WEASEL"
|
||||
Loading…
Add table
Add a link
Reference in a new issue