Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed contour plotting, assignment complete
  • Loading branch information
Stephen committed Feb 13, 2018
1 parent 53b7a9e commit 38cc771
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 14 deletions.
Binary file modified BestFitness.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 23 additions & 14 deletions GA.jl
Expand Up @@ -187,7 +187,6 @@ function GA(populationSize::Int, chromosomeSize::Int, fitness_function::Function
end end
clear!(:generations) clear!(:generations)
clear!(:population) clear!(:population)
clear!(:children)
run += 1 run += 1
end end


Expand Down Expand Up @@ -219,27 +218,37 @@ function GA(populationSize::Int, chromosomeSize::Int, fitness_function::Function
quit() quit()
end 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) for (index, gen) in enumerate(bestGenerations)
if (index == 1) || (mod(index,10) == 0) 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 for m in gen
push!(x,m[1]) push!(x,m[1])
push!(y,m[2]) push!(y,m[2])
end end
size = length(x) # Plt the contour plot
z = rand(size,size) contour(xrange,yrange,z)
for i in 1:size # Then plot the scatter underneath
for j in 1:size scatter(x,y)
z[i,j] = fitness_function([x[i],y[j]]) title("Generation $index")
end
end
contour(x,y,z)
savefig("contour_gen$index.png") savefig("contour_gen$index.png")
close() close()
clear!(:x)
clear!(:y)
clear!(:z)
end end
end end


Expand Down
Binary file modified contour_gen1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified contour_gen10.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified contour_gen100.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified contour_gen20.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified contour_gen30.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified contour_gen40.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified contour_gen50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified contour_gen60.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified contour_gen70.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified contour_gen80.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified contour_gen90.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 38cc771

Please sign in to comment.