Copy array so we aren't using the same old ref
This commit is contained in:
parent
70de0e7ac8
commit
1e33fcb9cd
@ -39,7 +39,6 @@ function fitness(candidate::DataFrames.DataFrame)
|
|||||||
abs(TARGETCALORIES - sum(+, candidate[:Calories]))
|
abs(TARGETCALORIES - sum(+, candidate[:Calories]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function randRow()
|
function randRow()
|
||||||
# Generate a random row index
|
# Generate a random row index
|
||||||
abs(rand(Int) % size(df, 1)) + 1
|
abs(rand(Int) % size(df, 1)) + 1
|
||||||
@ -80,18 +79,18 @@ function main()
|
|||||||
println("Sorting by fitness")
|
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 = deepcopy(parents)
|
||||||
|
|
||||||
println("Breeding new generation")
|
println("Breeding new generation")
|
||||||
print("Parents $parents")
|
print("Parents $parents")
|
||||||
for p in parents
|
for p in parents
|
||||||
for i = 1:4
|
for i = 1:(lambda/mu)
|
||||||
print("breed")
|
println("breed")
|
||||||
push!(pop, mutate(p))
|
push!(pop, mutate(p))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Generation $generationNum, best $best, fitness $bestFitness")
|
println("Generation $generationNum, best $best, fitness $bestFitness")
|
||||||
generationNum += 1
|
generationNum += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user