Skip to content

Commit

Permalink
Working with SMPSO
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnebro committed May 20, 2024
1 parent 6d8bae7 commit ce0763a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
9 changes: 2 additions & 7 deletions examples/NSGAIIAsAnEvolutionaryAlgorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Dates

# NSGA-II algorithm configured from the evolutionary algorithm template
function main()
problem = ZDT1()
problem = ZDT4()

solver::EvolutionaryAlgorithm = EvolutionaryAlgorithm()
solver.name = "NSGA-II"
Expand All @@ -12,24 +12,19 @@ function main()
offspringPopulationSize = 100

solver.solutionsCreation = DefaultSolutionsCreation(problem, populationSize)

solver.evaluation = SequentialEvaluation(problem)

solver.termination = TerminationByEvaluations(25000)

mutation = PolynomialMutation(1.0 / numberOfVariables(problem), 20.0, problem.bounds)
crossover = SBXCrossover(0.9, 20.0, problem.bounds)

"""
mutation = UniformMutation(1.0/numberOfVariables(problem), 20.0, problem.bounds)
crossover = BLXAlphaCrossover(1.0, 0.5, problem.bounds)
"""
crossover = SBXCrossover(0.9, 20.0, problem.bounds)

solver.variation = CrossoverAndMutationVariation(offspringPopulationSize, crossover, mutation)

solver.selection = BinaryTournamentSelection(solver.variation.matingPoolSize, DefaultDominanceComparator())

solver.replacement = RankingAndDensityEstimatorReplacement(DominanceRanking(DefaultDominanceComparator()), CrowdingDistanceDensityEstimator())

startingTime = Dates.now()
Expand Down
5 changes: 3 additions & 2 deletions examples/SMPSOAsPSO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function main()
solver = ParticleSwarmOptimization()
solver.name = "SMPSO"

problem = ZDT4()
problem = kursawe()
swarmSize = 100

solver.solutionsCreation = DefaultSolutionsCreation(problem, swarmSize)
Expand All @@ -24,7 +24,8 @@ function main()

solver.inertiaWeightComputingStrategy = ConstantValueStrategy(0.1)

mutationOperarator = PolynomialMutation(1.0/numberOfVariables(problem), 2.0, bounds(problem))
mutationOperarator = PolynomialMutation(1.0/numberOfVariables(problem), 20.0, bounds(problem))

mutationFrequency = 6
solver.perturbation = FrequencySelectionMutationBasedPerturbation(mutationFrequency, mutationOperarator)

Expand Down
1 change: 0 additions & 1 deletion src/operator/mutation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ struct PolynomialMutation <: MutationOperator
variableBounds::Vector{Bounds{Float64}}
end


function polynomialMutation(x::Vector{T}, mutationOperator::PolynomialMutation)::Vector{T} where {T<:Real}
probability::Real = mutationOperator.probability
distributionIndex::Real = mutationOperator.distributionIndex
Expand Down
8 changes: 8 additions & 0 deletions src/util/comparator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ end
function compare(comparator::DefaultDominanceComparator, x::Vector{T}, y::Vector{T})::Int where {T<:Number}
@assert length(x) == length(y) "The vectors have a different length"

"""
x==y && return 0
all(t->(t[1]≤t[2]), zip(x, y)) && return -1
all(t->(t[1]≤t[2]), zip(y, x)) && return 1
return 0
"""

bestIsSolution1 = 0
bestIsSolution2 = 0

Expand Down

0 comments on commit ce0763a

Please sign in to comment.