Population generation function, adding types to some functions

This commit is contained in:
Jacob Windle 2019-08-15 12:28:41 -04:00
parent 50bff5cabf
commit cb61b910d7

View File

@ -1,6 +1,10 @@
import ExcelReaders
import DataFrames
POPSIZE = 5
mu = 1
lambda = 4
data = ExcelReaders.readxlsheet("./data/nutrional_information_5917.xlsx", "Sheet2", skipstartrows=1)
header = ExcelReaders.readxlsheet("./data/nutrional_information_5917.xlsx", "Sheet2", nrows=1)
@ -21,10 +25,11 @@ end
function breeder(parent)
end
function fitness(candidate)
function fitness(candidate::DataFrames.DataFrame)
sum(+, candidate[:Calories])
end
function search(candidates)
function breed(candidates::Array{DataFrames.DataFrame})
# Truncation selection, top 3 as parents.
# First, check everyone's fitness.
# Then, generate new solutions by selecting parents and breeding
@ -37,8 +42,14 @@ function randRow()
abs(rand(Int) % size(df, 1))
end
function randomCandidate(n)
function randomCandidate(n::Integer)
# Select n random rows from the dataset.
rows = [randRow() for i = 1:n]
df[rows, :]
end
end
function generateInitialPopulation()
[randomCandidate(5) for i = 1:POPSIZE]
end
# search(generateInitialPopulation())