using SNOW export solve_phase struct Result converged::Bool info::Symbol sol::Matrix{Float64} end """ This function will take a single phase (so an initial state, and a final state) and an initial guess to the thrust profile and use an NLP solver to find the nearest thrust profile to that initial guess that satisfies the final state condition """ function solve_phase( start::Vector{Float64}, final::Vector{Float64}, craft::Sc, tof::Float64, x0::Matrix{Float64}, primary::Body=Sun; tol=1e-8, verbose::Bool=false ) n = size(x0)[1] function f!(g,x) try g[1:6] .= prop(reshape(x,(n,3)), start, craft, tof, primary)[2][1:6] return 1. catch e if isa(e,LaGuerreConway_Error) || isa(e, Mass_Error) || isa(e, PropOne_Error) return 10_000. else rethrow end end end lower_x = -1 * ones(3n) upper_x = ones(3n) num_constraints = 6 filename = "ipopt_"*string(rand(UInt)) ipopt_options = Dict("constr_viol_tol" => tol, "acceptable_constr_viol_tol" => 1e-4, "max_iter" => 10_000, "max_cpu_time" => 30., "print_level" => 0, "output_file" => filename) options = Options(solver=IPOPT(ipopt_options), derivatives=ForwardAD()) x, _, info = minimize(f!, vec(x0), num_constraints, lower_x, upper_x, final[1:6], final[1:6], options) rm(filename) if info in [:Solve_Succeeded, :Solved_To_Acceptable_Level] return Result(true, info, reshape(x,(n,3))) else if verbose println(info) end return Result(false, info, x0) end end