NLP seems to be doing pretty well
This commit is contained in:
@@ -1,36 +1,48 @@
|
||||
@testset "Phase" begin
|
||||
|
||||
using PlotlyJS: savefig
|
||||
|
||||
println("Testing NLP solver")
|
||||
|
||||
# We'll start by testing the mission_guess -> vector function
|
||||
vec = Vector(test_mg)
|
||||
@test typeof(vec) == Vector{Float64}
|
||||
|
||||
# Now we go in the other direction
|
||||
flybys = [ p.planet for p in test_mg.phases ]
|
||||
guess = Mission_Guess(vec, test_mg.sc, test_mg.start_mass, flybys)
|
||||
@test typeof(guess) == Mission_Guess
|
||||
@test guess.sc == test_mg.sc
|
||||
@test guess.start_mass == test_mg.start_mass
|
||||
@test guess.launch_date == test_mg.launch_date
|
||||
@test guess.launch_v∞ == test_mg.launch_v∞
|
||||
@test guess.converged == test_mg.converged
|
||||
for i in 1:length(guess.phases)
|
||||
@test guess.phases[i].planet == test_mg.phases[i].planet
|
||||
@test guess.phases[i].v∞_in == test_mg.phases[i].v∞_in
|
||||
@test guess.phases[i].v∞_out == test_mg.phases[i].v∞_out
|
||||
@test guess.phases[i].tof == test_mg.phases[i].tof
|
||||
@test guess.phases[i].thrust_profile == test_mg.phases[i].thrust_profile
|
||||
end
|
||||
|
||||
# Now we test an example run of the basic "inner function"
|
||||
# Test the optimizer for a one-phase mission
|
||||
# The lambert's solver said this should be pretty valid
|
||||
launch_window = [DateTime(1992,11,1), DateTime(1992,12,1)]
|
||||
latest_arrival = DateTime(1993,6,1)
|
||||
leave, arrive = DateTime(1992,11,19), DateTime(1993,4,1)
|
||||
test_leave = DateTime(1992,11,12)
|
||||
earth_state = state(Earth, leave)
|
||||
venus_state = state(Venus, arrive)
|
||||
v∞_out, v∞_in, tof = Thesis.lamberts(Earth, Venus, leave, arrive)
|
||||
phase = Phase(Venus, v∞_in, v∞_in, tof, zeros(20,3))
|
||||
guess = Mission_Guess(bepi, 12_000., leave, v∞_out, [phase])
|
||||
g = solve_mission(guess)
|
||||
println(g)
|
||||
# We can get the thrust profile and tof pretty wrong and still be ok
|
||||
phase = Phase(Venus, 1.1v∞_in, v∞_in, 0.9*tof, 0.1*ones(20,3))
|
||||
guess = Mission_Guess(bepi, 12_000., test_leave, 0.9*v∞_out, [phase])
|
||||
m = solve_mission(guess, launch_window, latest_arrival, verbose=true)
|
||||
@test typeof(m) == Mission
|
||||
@test m.converged == true
|
||||
|
||||
# Now we can plot the results to check visually
|
||||
p = plot(m, title="NLP Test Solution")
|
||||
savefig(p,"../plots/nlp_test_1_phase.html")
|
||||
|
||||
# Now we can look at a more complicated trajectory
|
||||
flybys = [Earth, Venus, Mars]
|
||||
launch_window = [DateTime(2021,10,1), DateTime(2021,12,1)]
|
||||
latest_arrival = DateTime(2023,1,1)
|
||||
dates = [DateTime(2021,11,1), DateTime(2022,3,27), DateTime(2022,8,28)]
|
||||
phases = Vector{Phase}()
|
||||
launch_v∞, _, tof1 = Thesis.lamberts(flybys[1], flybys[2], dates[1], dates[2])
|
||||
println(launch_v∞)
|
||||
for i in 1:length(dates)-2
|
||||
v∞_out1, v∞_in1, tof1 = Thesis.lamberts(flybys[i], flybys[i+1], dates[i], dates[i+1])
|
||||
v∞_out2, v∞_in2, tof2 = Thesis.lamberts(flybys[i+1], flybys[i+2], dates[i+1], dates[i+2])
|
||||
push!(phases, Phase(flybys[i+1], v∞_in1, v∞_out2, tof1, 0.01*ones(20,3)))
|
||||
end
|
||||
v∞_out, v∞_in, tof = Thesis.lamberts(flybys[end-1], flybys[end], dates[end-1], dates[end])
|
||||
push!(phases, Phase(flybys[end], v∞_in, v∞_in, tof, 0.01*ones(20,3)))
|
||||
# This isn't quite right. V∞ discrepancy is too big
|
||||
guess = Mission_Guess(bepi, 12_000., dates[1], launch_v∞, phases)
|
||||
m = solve_mission(guess, launch_window, latest_arrival, verbose=true)
|
||||
p = plot(m, title="NLP Test Solution (2 Phases)")
|
||||
savefig(p,"../plots/nlp_test_2_phase.html")
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user