Un algorithme génétique en Julia - partie 8
Voici le programme actuel, qui tient compte de l’utilisation du type
Chromosome
, ajouté dans la partie 7.
Le changement le plus important est l’utilisation d’une fonction anonyme:
On arrive bien à calculer la génération suivante:
julia> include("main.jl")
reproduction (generic function with 1 method)
julia> pop = create_population(8, 20)
8-element Array{Chromosome,1}:
Chromosome([1,0,1,1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1])
Chromosome([0,1,0,0,1,1,1,0,1,0,0,1,0,1,1,0,1,0,0,0])
Chromosome([0,0,1,0,0,1,0,1,0,0,0,0,1,0,0,0,1,0,0,0])
Chromosome([0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,0,0,1,0,0])
Chromosome([1,1,0,1,1,0,0,0,1,1,0,0,0,1,0,1,0,1,0,0])
Chromosome([1,0,1,1,1,1,0,0,1,0,0,0,1,0,0,0,0,1,1,1])
Chromosome([1,1,0,0,1,0,1,0,0,1,0,1,0,1,0,0,1,1,1,1])
Chromosome([0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,0,1,1,1,0])
julia> scores = score(pop)
8-element Array{Int32,1}:
7
9
5
7
9
10
11
10
julia> selection = tournament(scores)
16-element Array{Int32,1}:
2
4
6
1
6
5
8
7
5
7
5
6
8
4
6
6
julia> generation2 = reproduction([], pop, selection)
8-element Array{Chromosome,1}:
Chromosome([0,1,0,0,1,1,1,0,1,1,0,0,0,1,1,0,0,1,0,0])
Chromosome([1,0,1,1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1])
Chromosome([1,0,1,1,1,1,0,0,1,0,0,0,1,0,0,0,0,1,0,0])
Chromosome([0,1,1,0,0,1,1,0,0,1,0,1,0,1,0,0,1,1,1,1])
Chromosome([1,1,0,1,1,0,0,0,1,1,0,0,0,1,0,0,1,1,1,1])
Chromosome([1,1,0,1,1,1,0,0,1,0,0,0,1,0,0,0,0,1,1,1])
Chromosome([0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,0,1,1,0,0])
Chromosome([1,0,1,1,1,1,0,0,1,0,0,0,1,0,0,0,0,1,1,1])
La première version de l’algorithme est bientôt finie…
À demain.
/ / / / / / / / / /