Skip to content

Commit

Permalink
Add function to file solution.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnebro committed Jan 12, 2024
1 parent 9546b5a commit 34016ce
Show file tree
Hide file tree
Showing 5 changed files with 1,532 additions and 711 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using Dates

# NSGA-II algorithm configured from the evolutionary algorithm template. It incorporates an external archive to store the non-dominated solution found. This archive will be the algorithm output.

problem = zdt3Problem()
problem = zdt2Problem()

solver::EvolutionaryAlgorithm = EvolutionaryAlgorithm()
solver.name = "NSGA-II"
Expand Down
1,150 changes: 789 additions & 361 deletions notebooks/NSGA-II notebook.ipynb

Large diffs are not rendered by default.

1,082 changes: 734 additions & 348 deletions notebooks/NSGA-II with external archive.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/core.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Core structs
# Core types

abstract type Solution end
abstract type Problem{T} end
Expand Down
7 changes: 7 additions & 0 deletions src/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,11 @@ end

function isFeasible(solution::S) where {S<:Solution}
return numberOfViolatedConstraints(solution) == 0
end

function feasibilityRatio(solutions::Vector{S})::Real where {S <: Solution}
@assert length(solutions) > 0 "The solution list is empty"

result = sum(filter(solution -> isFeasible(solution), solutions))
return result / length(solutions)
end

0 comments on commit 34016ce

Please sign in to comment.