Fixed 1-based indexing issue thank you discourse
This commit is contained in:
parent
673e28b02c
commit
70de0e7ac8
@ -42,7 +42,7 @@ end
|
|||||||
|
|
||||||
function randRow()
|
function randRow()
|
||||||
# Generate a random row index
|
# Generate a random row index
|
||||||
abs(rand(Int) % size(df, 1))
|
abs(rand(Int) % size(df, 1)) + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
function randomCandidate(n::Integer)
|
function randomCandidate(n::Integer)
|
||||||
@ -57,6 +57,7 @@ end
|
|||||||
|
|
||||||
function main()
|
function main()
|
||||||
# Generate the initial population.
|
# Generate the initial population.
|
||||||
|
println("Entering main.")
|
||||||
pop = generateInitialPopulation(lambda, 4)
|
pop = generateInitialPopulation(lambda, 4)
|
||||||
best = nothing
|
best = nothing
|
||||||
generationNum = 0
|
generationNum = 0
|
||||||
@ -64,6 +65,7 @@ function main()
|
|||||||
parents = nothing
|
parents = nothing
|
||||||
|
|
||||||
while generationNum != GENLIMIT || (best != nothing && fitness(best) != 0)
|
while generationNum != GENLIMIT || (best != nothing && fitness(best) != 0)
|
||||||
|
println("Generation $generationNum")
|
||||||
|
|
||||||
# Assess the fitness of parents
|
# Assess the fitness of parents
|
||||||
for parent in pop
|
for parent in pop
|
||||||
@ -75,17 +77,21 @@ function main()
|
|||||||
|
|
||||||
bestFitness = fitness(best)
|
bestFitness = fitness(best)
|
||||||
|
|
||||||
|
println("Sorting by fitness")
|
||||||
sort!(pop, by = x -> fitness(x))
|
sort!(pop, by = x -> fitness(x))
|
||||||
parents = pop[1:mu]
|
parents = pop[1:mu]
|
||||||
pop = parents
|
pop = parents
|
||||||
|
|
||||||
|
println("Breeding new generation")
|
||||||
|
print("Parents $parents")
|
||||||
for p in parents
|
for p in parents
|
||||||
for i = 1:(lambda/mu)
|
for i = 1:4
|
||||||
|
print("breed")
|
||||||
push!(pop, mutate(p))
|
push!(pop, mutate(p))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
println("Generation $generationNum, best $best, fitness $bestFitness")
|
print("Generation $generationNum, best $best, fitness $bestFitness")
|
||||||
generationNum += 1
|
generationNum += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user