Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnebro committed May 10, 2024
1 parent 064a085 commit 008cca9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
30 changes: 18 additions & 12 deletions notebooks/Defining problems.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "44759988",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ContinuousProblem{Real}(Bounds{Real}[Bounds{Real}(-1000.0, 1000.0)], Function[var\"#222#223\"(), var\"#224#225\"()], Function[], \"Schaffer\")\n"
"ContinuousProblem{Real}(Bounds{Real}[Bounds{Real}(-1000.0, 1000.0)], Function[var\"#9#10\"(), var\"#11#12\"()], Function[], \"Schaffer\")\n"
]
}
],
"source": [
"include(\"../src/continuousProblem.jl\")\n",
"using metajul\n",
"\n",
"schaffer = ContinuousProblem{Real}(\"Schaffer\")\n",
"\n",
Expand Down Expand Up @@ -165,7 +165,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "d496dfdc",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -333,7 +333,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "00ca6da7",
"metadata": {},
"outputs": [],
Expand All @@ -342,15 +342,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.8.0",
"language": "julia",
"name": "julia-1.8"
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.8.0"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
31 changes: 16 additions & 15 deletions src/util/comparator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,30 @@ Compare two numerics vectors `x` and `y` according to the dominance relationship
function compareForDominance(x::Vector{T}, y::Vector{T})::Int where {T<:Number}
@assert length(x) == length(y) "The vectors have a different length"

bestIsSolution1 = false
bestIsSolution2 = false
bestIsSolution1 = 0
bestIsSolution2 = 0

@inbounds for i in 1:length(x)
for i in 1:length(x)
if x[i] != y[i]
if x[i] < y[i]
bestIsSolution1 = true
elseif x[i] > y[i]
bestIsSolution2 = true
bestIsSolution1 = 1
end

# Early exit if both flags are true
if bestIsSolution1 && bestIsSolution2
return 0
if x[i] > y[i]
bestIsSolution2 = 1
end
end
end

if bestIsSolution1
return -1
elseif bestIsSolution2
return 1
result = 0
if bestIsSolution2 < bestIsSolution1
result = -1
elseif bestIsSolution2 > bestIsSolution1
result = 1
else
return 0
result = 0
end

return result
end

function compareForDominance(solution1::Solution, solution2::Solution)::Int
Expand Down
4 changes: 4 additions & 0 deletions test/util/comparatorTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ end
@test compareForDominance([2.0], [1.0]) == 1

@test compareForDominance([1.0, 2.0], [1.0, 1.0]) == 1
@test compareForDominance([2.0, 2.0], [2.0, 1.0]) == 1
@test compareForDominance([1.0, 2.0], [2.0, 1.0]) == 0
@test compareForDominance([1.0, 2.0], [1.0, 2.0]) == 0
@test compareForDominance([1.0, 1.0], [1.0, 2.0]) == -1

@test compareForDominance([1.0,2.0,3.1], [1.0,2.0,3.1]) == 0

Expand Down

0 comments on commit 008cca9

Please sign in to comment.