Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration v0.6 #20

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/GeneticAlgorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export Entity,

# -------

abstract Entity
abstract type Entity end

isless(lhs::Entity, rhs::Entity) = lhs.fitness < rhs.fitness

fitness!(ent::Entity, fitness_score) = ent.fitness = fitness_score

# -------

type EntityData
struct EntityData
entity
generation::Int

Expand All @@ -34,7 +34,7 @@ end

# -------

type GAmodel
mutable struct GAmodel
initial_pop_size::Int
gen_num::Int

Expand Down
10 changes: 5 additions & 5 deletions test/equalityga.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import Base.isless

using GeneticAlgorithms

type EqualityMonster <: Entity
mutable struct EqualityMonster <: Entity
abcde::Array
fitness

EqualityMonster() = new(Array(Int, 5), nothing)
EqualityMonster() = new(Array{Int}(5), nothing)
EqualityMonster(abcde) = new(abcde, nothing)
end

Expand Down Expand Up @@ -50,7 +50,7 @@ function crossover(group)
# grab each element from a random parent
num_parents = length(group)
for i in 1:length(group[1].abcde)
parent = (rand(Uint) % num_parents) + 1
parent = (rand(UInt) % num_parents) + 1
child.abcde[i] = group[parent].abcde[i]
end

Expand All @@ -61,8 +61,8 @@ function mutate(ent)
# let's go crazy and mutate 20% of the time
rand(Float64) < 0.8 && return

rand_element = rand(Uint) % 5 + 1
rand_element = rand(UInt) % 5 + 1
ent.abcde[rand_element] = rand(Int) % 43
end

end
end
2 changes: 1 addition & 1 deletion test/testga.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module testga

using GeneticAlgorithms

type TestMonster <: Entity
mutable struct TestMonster <: Entity
genes
fitness

Expand Down