diff --git a/BestFitness.png b/BestFitness.png index 01c4aa3..70df4bd 100644 Binary files a/BestFitness.png and b/BestFitness.png differ diff --git a/GA.jl b/GA.jl index ff151fb..078e668 100644 --- a/GA.jl +++ b/GA.jl @@ -187,7 +187,6 @@ function GA(populationSize::Int, chromosomeSize::Int, fitness_function::Function end clear!(:generations) clear!(:population) - clear!(:children) run += 1 end @@ -219,27 +218,37 @@ function GA(populationSize::Int, chromosomeSize::Int, fitness_function::Function quit() end - # Init x and y z for contour plots - x = y = z = Array{Float64}(0) + + # Pick X and Y range for contour plot based on bounds + xrange = bounds[1][1]:0.01:bounds[1][2] + yrange = bounds[2][1]:0.01:bounds[2][2] + size = length(xrange) + # Init z array for values of fitness function + z = zeros(size,size) + for i in 1:size + for j in 1:size + # Generate a z value for each x and y value + z[i,j] = fitness_function([xrange[i],yrange[j]]) + end + end + # If we are at 1st gen or evry 10th, plot for (index, gen) in enumerate(bestGenerations) if (index == 1) || (mod(index,10) == 0) + # Re-init x and y for the generation + x = Array{Float64}(0) + y = Array{Float64}(0) + # Push x and y to separate arrays for m in gen push!(x,m[1]) push!(y,m[2]) end - size = length(x) - z = rand(size,size) - for i in 1:size - for j in 1:size - z[i,j] = fitness_function([x[i],y[j]]) - end - end - contour(x,y,z) + # Plt the contour plot + contour(xrange,yrange,z) + # Then plot the scatter underneath + scatter(x,y) + title("Generation $index") savefig("contour_gen$index.png") close() - clear!(:x) - clear!(:y) - clear!(:z) end end diff --git a/contour_gen1.png b/contour_gen1.png index c4b7b2f..43748a2 100644 Binary files a/contour_gen1.png and b/contour_gen1.png differ diff --git a/contour_gen10.png b/contour_gen10.png index 5770b31..00a2525 100644 Binary files a/contour_gen10.png and b/contour_gen10.png differ diff --git a/contour_gen100.png b/contour_gen100.png index c3181e5..6188312 100644 Binary files a/contour_gen100.png and b/contour_gen100.png differ diff --git a/contour_gen20.png b/contour_gen20.png index 181a04a..6a54364 100644 Binary files a/contour_gen20.png and b/contour_gen20.png differ diff --git a/contour_gen30.png b/contour_gen30.png index f43d2fe..890ee0a 100644 Binary files a/contour_gen30.png and b/contour_gen30.png differ diff --git a/contour_gen40.png b/contour_gen40.png index 23e7a10..056b86f 100644 Binary files a/contour_gen40.png and b/contour_gen40.png differ diff --git a/contour_gen50.png b/contour_gen50.png index e484f9e..46b03ef 100644 Binary files a/contour_gen50.png and b/contour_gen50.png differ diff --git a/contour_gen60.png b/contour_gen60.png index 4432866..e12a233 100644 Binary files a/contour_gen60.png and b/contour_gen60.png differ diff --git a/contour_gen70.png b/contour_gen70.png index fbc3441..3e6ba0e 100644 Binary files a/contour_gen70.png and b/contour_gen70.png differ diff --git a/contour_gen80.png b/contour_gen80.png index 8b375df..0bd5f7e 100644 Binary files a/contour_gen80.png and b/contour_gen80.png differ diff --git a/contour_gen90.png b/contour_gen90.png index b9bfbbb..2e6d908 100644 Binary files a/contour_gen90.png and b/contour_gen90.png differ