include("src/Thesis.jl") using .Thesis using Dates using SPICE using LinearAlgebra using PlotlyJS: savefig try furnsh("../../spice_files/naif0012.tls") furnsh("../../spice_files/de430.bsp") catch furnsh("spice_files/naif0012.tls") furnsh("spice_files/de430.bsp") end """ The cost function for the mission """ function easy_cost(m::Union{Mission, Mission_Guess}, C3::Float64, v∞::Float64) norm_mass = (m.start_mass - prop(m)[7]) / m.start_mass norm_C3 = ( m.launch_v∞ ⋅ m.launch_v∞ ) / C3 norm_v∞ = norm(m.phases[end].v∞_in) / v∞ tof = 0.0 for phase in m.phases tof += phase.tof end tof = tof/(20Thesis.year) return 3norm_mass + norm_C3 + tof end sc = Sc("mySat", 200., 3200., 0.00025, 1, 1.0) fuel = 3300. max_c3 = 200. max_v∞ = 500. ideal_launch = DateTime(2024,1,1) launch_window = ideal_launch - Day(365), ideal_launch + Day(365) latest_arrival = ideal_launch + Year(18) println("Max thrust at full bore: $(fuel/(mfr(sc)*Thesis.year)) years") println("Max mission length: $((latest_arrival - launch_window[1]).value/(1000Thesis.year)) years") # Convenience function for these tests Thesis.mbh(fbs) = mbh(fbs, sc, sc.dry_mass + fuel, launch_window, max_c3, max_v∞, latest_arrival, easy_cost, search_patience=10_000, drill_patience=200, verbose=true) function log(m::Mission, archive::Vector{Mission}, planets::Vector{Body}) abbrev = join([ planet.name[1] for planet in planets ]) p = plot(m, title="Best $(abbrev) Trajectory") savefig(p,"archive/$(abbrev).html") store(m, "archive/$(abbrev)") store(archive, "archive/$(abbrev)_archive") end log(_::Nothing, _::Vector{Mission}, _::Vector{Body}) = println("No Mission Found...") planets = [Earth, Mars, Mars, Jupiter, Saturn] best, archive = mbh(planets) log(best, archive, planets) println("Complete!")