Skip to content

Initial implementation of Constrained GlobalOptimisation #33

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: dps/v0.7
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
6 changes: 3 additions & 3 deletions src/IntervalOptimisation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ module IntervalOptimisation
export minimise, maximise,
minimize, maximize,
minimise1d, minimise1d_deriv,
minimise_icp, minimise_icp_constrained
minimise_icp, minimise_icp_constrained, ConstraintCond

include("SortedVectors.jl")
using .SortedVectors

using IntervalArithmetic, IntervalRootFinding, DataStructures, IntervalConstraintProgramming, ForwardDiff

using IntervalArithmetic, DataStructures, IntervalConstraintProgramming, ForwardDiff
using ModelingToolkit

include("optimise.jl")
include("optimise1.jl")
Expand Down
49 changes: 31 additions & 18 deletions src/optimise1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,22 @@ struct IntervalBoxMinimum{N, T<:Real}
minimum::T
end

"""
Datatype to provide constraints to Global Optimisation such as:
```
Constraint(x->(x^2 - 10), -∞..1)
```
"""
struct Constraint{T<:Real}
f::Function
c::Interval{T}
end


Base.isless(a::IntervalBoxMinimum{N, T}, b::IntervalBoxMinimum{N, T}) where {N, T<:Real} = isless(a.minimum, b.minimum)

function minimise_icp(f::Function, x::IntervalBox{N, T}; reltol=1e-3, abstol=1e-3) where {N, T<:Real}
function minimise_icp(f::Function, x::IntervalBox{N, T}, var ; reltol=1e-3, abstol=1e-3) where {N, T<:Real}

Q = binary_minheap(IntervalBoxMinimum{N, T})

global_minimum = ∞

x = icp(f, x, -∞..global_minimum)
variables = []
for i in var append!(variables, Unknown(i)) end

f_op = f(variables...)
C = Contractor(f_op)
x = C(-∞..global_minimum, x)

arg_minima = IntervalBox{N, T}[]

Expand All @@ -125,7 +121,8 @@ function minimise_icp(f::Function, x::IntervalBox{N, T}; reltol=1e-3, abstol=1e-
global_minimum = current_minimum
end

X = icp(f, p.interval, -∞..global_minimum)
C = Contractor(f_op)
X = C(-∞..global_minimum, p.interval)

if diam(p.interval) < abstol
push!(arg_minima, p.interval)
Expand All @@ -141,17 +138,30 @@ function minimise_icp(f::Function, x::IntervalBox{N, T}; reltol=1e-3, abstol=1e-
return lb..global_minimum, arg_minima
end

function minimise_icp_constrained(f::Function, x::IntervalBox{N, T}, constraints::Vector{Constraint{T}} = Vector{Constraint{T}}(); reltol=1e-3, abstol=1e-3) where {N, T<:Real}

struct ConstraintCond{T}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just Constraint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Their might be more than one constraint condition thats why we need to built vector of such conditions.

f ::Operation
c ::Interval{T}
end


function minimise_icp_constrained(f::Function, x::IntervalBox{N,T}, var, constraints::Vector{ConstraintCond{T}} = Vector{ConstraintCond{T}}(); reltol=1e-3, abstol=1e-3) where {N, T<:Real}

Q = binary_minheap(IntervalBoxMinimum{N, T})

global_minimum = ∞

for t in constraints
x = icp(t.f, x, t.c)
C = Contractor(t.f, var)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is expensive to create a Contractor, so this should be done only once for each constraint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right. We should built contractor for each constraint condition only once.

x = C(t.c, x)
end

x = icp(f, x, -∞..global_minimum)
variables = []
for i in var append!(variables, Unknown(i)) end

f_op = f(variables...)
C = Contractor(f_op)
x = C(-∞..global_minimum, x)

arg_minima = IntervalBox{N, T}[]

Expand All @@ -176,10 +186,13 @@ function minimise_icp_constrained(f::Function, x::IntervalBox{N, T}, constraints
global_minimum = current_minimum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this logic is not correct, since there may be no feasible points in p.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes right..!! this required more work need to be done on this case.

end

X = icp(f, p.interval, -∞..global_minimum)
C = Contractor(f_op)
X = C(-∞..global_minimum, p.interval)

for t in constraints
X = icp(t.f, X, t.c)
C = Contractor(t.f, var)
A = Interval(a)
X = C(A, X)
end

if diam(p.interval) < abstol
Expand Down