Monotonic Basin Hopping is started

This commit is contained in:
Connor
2021-08-25 23:41:44 -06:00
parent db883187a1
commit 850f05ce38
7 changed files with 107 additions and 13 deletions

View File

@@ -9,4 +9,5 @@ module Thesis
include("./laguerre-conway.jl")
include("./propagator.jl")
include("./find_closest.jl")
include("./monotonic_basin_hopping.jl")
end

View File

@@ -1,18 +1,20 @@
using NLsolve
export nlp_solve
function treat_inputs(x::AbstractVector)
n::Int = length(x)/3
reshape(x,(3,n))'
end
function single_shoot(start::Vector{Float64},
final::Vector{Float64},
craft::Sc,
μ::Float64,
t0::Float64,
tf::Float64,
x0::AbstractVector,
tol=1e-6)
function nlp_solve(start::Vector{Float64},
final::Vector{Float64},
craft::Sc,
μ::Float64,
t0::Float64,
tf::Float64,
x0::AbstractVector;
tol=1e-6)
n::Int = length(x0)/3
function f!(F,x)
@@ -20,6 +22,6 @@ function single_shoot(start::Vector{Float64},
F[7:3n] .= 0.
end
return nlsolve(f!, x0, ftol=tol, autodiff=:forward, iterations=10_000)
return nlsolve(f!, x0, ftol=tol, autodiff=:forward, iterations=1_000)
end

View File

@@ -0,0 +1,56 @@
function perturb(x::AbstractVector, n::Int)
perturb_vector = 0.02 * rand(Float64, (3n)) .- 0.01
return x + perturb_vector
end
function mass_better(x_star::AbstractVector,
x_current::AbstractVector,
start::AbstractVector,
final::AbstractVector,
craft::Sc,
μ::AbstractFloat,
t0::AbstractFloat,
tf::AbstractFloat)
mass_star = prop(treat_inputs(x_star), start, craft, μ, tf-t0)[2]
mass_current = prop(treat_inputs(x_current), start, craft, μ, tf-t0)[2]
return mass_star > mass_current
end
function mbh(start::AbstractVector,
final::AbstractVector,
craft::Sc,
μ::AbstractFloat,
t0::AbstractFloat,
tf::AbstractFloat,
n::Int,
num_iters::Int=10,
tol=1e-6)
i::Int = 0
archive = []
x_star = nlp_solve(start, final, craft, μ, t0, tf, rand(Float64,(3n)), tol=tol)
while converged(x_star) == false
x_star = nlp_solve(start, final, craft, μ, t0, tf, rand(Float64,(3n)), tol=tol)
end
x_current = x_star
push!(archive, x_current)
while i < num_iters
x_star = nlp_solve(start, final, craft, μ, t0, tf, perturb(x_current.zero,n), tol=tol)
if converged(x_star) && mass_better(x_star.zero, x_current.zero, start, final, craft, μ, t0, tf)
x_current = x_star
push!(archive, x_star)
else
while converged(x_star) == false
x_star = nlp_solve(start, final, craft, μ, t0, tf, rand(Float64,(3n)), tol=tol)
end
if mass_better(x_star.zero, x_current.zero, start, final, craft, μ, t0, tf)
x_current = x_star
push!(archive, x_star)
end
end
i += 1
end
return x_current, archive
end