Skip to content

Commit

Permalink
Update DividedRectangles.jl - Added Function Tim Reccomended
Browse files Browse the repository at this point in the history
  • Loading branch information
Aero-Spec authored Sep 22, 2024
1 parent 660e2c7 commit 90def36
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/DividedRectangles.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module DividedRectangles

export optimize
export optimize, direct

# Structure to store information about each rectangle
struct DirectRectangle
Expand Down Expand Up @@ -54,8 +54,8 @@ function divide(rect::DirectRectangle, g)
return smaller_rectangles
end

# Main function that runs the DIRECT optimization algorithm
function optimize(f, a::Vector{Float64}, b::Vector{Float64}; max_iterations::Int = 100, min_radius::Float64 = 1e-5)
# Function that returns all the rectangles
function direct(f, a::Vector{Float64}, b::Vector{Float64}; max_iterations::Int = 100, min_radius::Float64 = 1e-5)
g = x -> f(x .* (b .- a) .+ a)
n = length(a)
initial_center = fill(0.5, n)
Expand All @@ -71,6 +71,13 @@ function optimize(f, a::Vector{Float64}, b::Vector{Float64}; max_iterations::Int
end
end

return rectangles
end

# Main function that runs the DIRECT optimization algorithm and returns the best design
function optimize(f, a::Vector{Float64}, b::Vector{Float64}; max_iterations::Int = 100, min_radius::Float64 = 1e-5)
rectangles = direct(f, a, b, max_iterations=max_iterations, min_radius=min_radius)

best_value, best_rect_index = findmin(r.value for r in rectangles)
best_rect = rectangles[best_rect_index]
return best_rect.center .* (b .- a) .+ a
Expand Down

0 comments on commit 90def36

Please sign in to comment.