-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d88fb5b
commit f595006
Showing
2 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using GeneticAlgorithm | ||
|
||
@testset "GeneticAlgorithm" begin | ||
#= | ||
| Find four numbers that add up to 143. | ||
| | ||
| x1 + x2 + x3 + x4 = 143 | ||
| x1=?, x2=?, x3=?, x4=? | ||
=# | ||
|
||
populationSize = 100 | ||
genesLength = 4 | ||
minGene = 0 | ||
maxGene = 143 | ||
|
||
elitePercent = 0.15 | ||
mutationPercent = 0.2 | ||
numOfIterations = 100 | ||
|
||
population = generatePopulation(populationSize, genesLength, minGene, maxGene) | ||
|
||
num_gen, best = geneticAlgorithm(population, | ||
elitePercent, | ||
mutationPercent, | ||
makeCrossoverFunc([1;3]), | ||
numOfIterations) | ||
|
||
@test fitFunction(best) < 0.1 # Test if the absolute error is smaller than 0.1 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
using Test | ||
|
||
@testset "Tests" begin | ||
a = 5 | ||
@test a == 5 | ||
include("genetic_algorithm.jl") | ||
end |