Skip to content

Add unify function to unify roots using intersection and LightGraphs #5

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ julia 0.5

IntervalArithmetic 0.9.1
IntervalRootFinding 0.1
LightGraphs 0.9
10 changes: 8 additions & 2 deletions src/IntervalOptimisation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
module IntervalOptimisation

export minimise, maximise,
minimize, maximize
minimize, maximize,
unify


include("SortedVectors.jl")
using .SortedVectors

using IntervalArithmetic, IntervalRootFinding
using LightGraphs # for unifying intervals

const Interval=IntervalArithmetic.Interval


if !isdefined(:sup)
const sup = supremum
Expand All @@ -21,6 +27,6 @@ end
include("optimise.jl")

const minimize = minimise
const maximize = maximise
const maximize = maximise

end
19 changes: 19 additions & 0 deletions src/optimise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,22 @@ function maximise{T}(f, X::T, tol=1e-3)
bound, minimizers = minimise(x -> -f(x), X, tol)
return -bound, minimizers
end



function unify(minimisers)

n = length(minimisers)
g = Graph(length(minimisers))

for i in 1:n, j in i+1:n
if !isempty(minimisers[i] ∩ minimisers[j])
add_edge!(g, i, j)
end
end

components = LightGraphs.connected_components(g)

return [reduce(union, minimisers[components[i]]) for i in 1:length(components)]

end