Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use R*-Tree for Pareto frontier #107

Merged
merged 9 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ os:
- linux
- osx
julia:
- 0.7
- 1.0
- nightly
matrix:
Expand Down
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
julia 0.7
julia 1.0.3
StatsBase
Distributions
SpatialIndexing 0.1
Compat
CPUTime
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
environment:
matrix:
- julia_version: 0.7
- julia_version: 1.0
- julia_version: latest

Expand Down
4 changes: 4 additions & 0 deletions src/BlackBoxOptim.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module BlackBoxOptim

using Distributions, StatsBase, Random, LinearAlgebra, Printf, Distributed, Compat
using SpatialIndexing
using Printf: @printf, @sprintf
using Compat: String, view

Expand Down Expand Up @@ -91,6 +92,8 @@ module Utils
include("utilities/halton_sequence.jl")
end

const SI = SpatialIndexing

include("search_space.jl")
include("parameters.jl")
include("fitness.jl")
Expand All @@ -102,6 +105,7 @@ include("frequency_adaptation.jl")

include("fit_individual.jl")
include("archive.jl")
include("archives/dominance_cone.jl")
include("archives/epsbox_archive.jl")

include("genetic_operators/genetic_operator.jl")
Expand Down
47 changes: 47 additions & 0 deletions src/archives/dominance_cone.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Set of points in fitness space that Pareto-dominate (`MIN` is `true`) or
are dominated by (`MIN` is `false`) the given point `pt`.

The point `pt` itself is not part of its `DominanceCone`.

If the goal is to maximize each individual fitness component
(i.e. `is_minimizing(fs::FitnessScheme) == false`), the cone of
Pareto-dominating points should use `MIN = false` and Pareto-dominated points
should use `MIN = true`.
"""
struct DominanceCone{F,N,MIN} <: SI.Region{F,N}
pt::NTuple{N,F}

function DominanceCone{MIN}(pt::NTuple{N,F}) where {F,N,MIN}
(MIN isa Bool) || throw(ArgumentError("MIN should be true or false (got $MIN)"))
new{F,N,MIN}(pt)
end
end

is_minimizing(a::DominanceCone{<:Any,<:Any,MIN}) where MIN = MIN

# function to help define contains/intersects for all MIN values
# rely on constant propagation of lt for efficient compilation
isordered(lt::Bool, a::Number, b::Number) = lt ? a < b : a > b

@generated SI.contains(a::DominanceCone{F,N,MIN}, b::NTuple{N,F}) where {F,N,MIN} =
quote
isordered(MIN, a.pt[1], b[1]) && return false
anylt = isordered(MIN, b[1], a.pt[1])
@inbounds Base.Cartesian.@nexprs $(N-1) i -> begin
isordered(MIN, a.pt[i+1], b[i+1]) && return false
anylt || (anylt = isordered(MIN, b[i+1], a.pt[i+1]))
end
return anylt
end

SI.contains(a::DominanceCone, b::SI.Point) = SI.contains(a, b.coord)
SI.intersects(a::DominanceCone, b::SI.Point) = SI.contains(a, b)

SI.contains(a::DominanceCone, b::SI.Rect) =
SI.contains(a, is_minimizing(a) ? b.high : b.low)
Base.in(a::SI.Region, b::DominanceCone) = SI.contains(b, a)

SI.intersects(a::DominanceCone, b::SI.Rect) =
SI.contains(a, is_minimizing(a) ? b.low : b.high)
SI.intersects(a::SI.Rect, b::DominanceCone) = SI.intersects(b, a)
Loading