diff --git a/examples/NSGAIIAsAnEvolutionaryAlgorithm.jl b/examples/NSGAIIAsAnEvolutionaryAlgorithm.jl index c34283a..22a2eaf 100644 --- a/examples/NSGAIIAsAnEvolutionaryAlgorithm.jl +++ b/examples/NSGAIIAsAnEvolutionaryAlgorithm.jl @@ -25,8 +25,9 @@ function main() solver.variation = CrossoverAndMutationVariation(offspringPopulationSize, crossover, mutation) solver.selection = BinaryTournamentSelection(solver.variation.matingPoolSize, DefaultDominanceComparator()) - solver.replacement = RankingAndDensityEstimatorReplacement(DominanceRanking(DefaultDominanceComparator()), CrowdingDistanceDensityEstimator()) + solver.replacement = RankingAndDensityEstimatorReplacement(DominanceRanking(DefaultDominanceComparator()), CrowdingDistanceDensityEstimator()) + startingTime = Dates.now() optimize(solver) endTime = Dates.now() diff --git a/examples/NSGAIIWithStandardSettings.jl b/examples/NSGAIIWithStandardSettings.jl index 3c395d2..a871ba7 100644 --- a/examples/NSGAIIWithStandardSettings.jl +++ b/examples/NSGAIIWithStandardSettings.jl @@ -8,6 +8,7 @@ function main() problem = ZDT1() solver::NSGAII = NSGAII() + solver.problem = problem solver.populationSize = 100 solver.termination = TerminationByEvaluations(25000) diff --git a/src/algorithm/evolutionaryAlgorithm.jl b/src/algorithm/evolutionaryAlgorithm.jl index ff836f9..f80e08f 100644 --- a/src/algorithm/evolutionaryAlgorithm.jl +++ b/src/algorithm/evolutionaryAlgorithm.jl @@ -54,7 +54,6 @@ function evolutionaryAlgorithm(ea::EvolutionaryAlgorithm) notify(ea.observable, ea.status) end - foundSolutions = population return foundSolutions end diff --git a/src/component/evolutionaryAlgorithm/replacement.jl b/src/component/evolutionaryAlgorithm/replacement.jl index a7e9ed5..5c4d09e 100644 --- a/src/component/evolutionaryAlgorithm/replacement.jl +++ b/src/component/evolutionaryAlgorithm/replacement.jl @@ -2,7 +2,7 @@ struct MuPlusLambdaReplacement <: Replacement comparator::Comparator end -function replace_(replacement::MuPlusLambdaReplacement, x::Vector{S}, y::Vector{S}) where {S <: Solution} +function replace_(replacement::MuPlusLambdaReplacement, x::Vector{S}, y::Vector{S}) where {S<:Solution} jointVector = vcat(x, y) sort!(jointVector, lt=((a, b) -> compare(replacement.comparator, a, b) <= 0)) return jointVector[1:length(x)] @@ -12,7 +12,7 @@ struct MuCommaLambdaReplacement <: Replacement comparator::Comparator end -function replace_(replacement::MuCommaLambdaReplacement, x::Vector{S}, y::Vector{S}) where {S <: Solution} +function replace_(replacement::MuCommaLambdaReplacement, x::Vector{S}, y::Vector{S}) where {S<:Solution} @assert length(x) >= length(y) "The length of the x vector is lower than the length of the y vector" resultVector = Vector(y) @@ -29,6 +29,7 @@ struct RankingAndDensityEstimatorReplacement <: Replacement RankingAndDensityEstimatorReplacement(ranking, densityEstimator) = new(ranking, densityEstimator, RankingAndCrowdingDistanceComparator()) end + function replace_(replacement::RankingAndDensityEstimatorReplacement, x::Vector{T}, y::Vector{T})::Vector{T} where {T<:Solution} jointVector = vcat(x, y) @@ -41,4 +42,3 @@ function replace_(replacement::RankingAndDensityEstimatorReplacement, x::Vector{ sort!(jointVector, lt=((x, y) -> compare(replacement.rankingAndDensityEstimatorComparator, x, y) < 0)) return jointVector[1:length(x)] end - diff --git a/src/metajul.jl b/src/metajul.jl index cb64fc7..0fd49b7 100644 --- a/src/metajul.jl +++ b/src/metajul.jl @@ -65,7 +65,7 @@ export variate include("component/evolutionaryAlgorithm/variation.jl") export MuCommaLambdaReplacement, MuPlusLambdaReplacement, RankingAndDensityEstimatorReplacement -export replace_ +export replace_ include("component/evolutionaryAlgorithm/replacement.jl") export ConstantValueStrategy diff --git a/src/util/densityEstimator.jl b/src/util/densityEstimator.jl index c54d3ff..f9a5bf4 100644 --- a/src/util/densityEstimator.jl +++ b/src/util/densityEstimator.jl @@ -61,7 +61,7 @@ function compute!(densityEstimator::CrowdingDistanceDensityEstimator, solutions: obj_range_inv = 1 / (maximumObjectiveValue - minimumObjectiveValue) for j in 2:(num_solutions-1) - @inbounds begin + begin distance = (solutions[j+1].objectives[i] - solutions[j-1].objectives[i]) * obj_range_inv distance += getCrowdingDistance(solutions[j]) setCrowdingDistance(solutions[j], distance) diff --git a/src/util/ranking.jl b/src/util/ranking.jl index 9e18a79..0e8021c 100644 --- a/src/util/ranking.jl +++ b/src/util/ranking.jl @@ -50,6 +50,7 @@ function compare(comparator::DominanceRankingComparator, solution1::Solution, so end function compute!(ranking::DominanceRanking, solutions::Array{T}) where {T <: Solution} + ranking.rank = [] solutionsToRank = [solution for solution in solutions] rankCounter = 1