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