Built the population member gen function
This commit is contained in:
@@ -20,5 +20,6 @@ module Thesis
|
||||
include("./inner_loop/monotonic_basin_hopping.jl")
|
||||
include("./inner_loop/phase.jl")
|
||||
include("./inner_loop/inner_loop.jl")
|
||||
include("./outer_loop.jl")
|
||||
|
||||
end
|
||||
|
||||
@@ -47,9 +47,9 @@ function inner_loop(launch_date::DateTime,
|
||||
thrust_profiles = []
|
||||
|
||||
for phase in phases
|
||||
planet1_state = [spkssb(ids[phase.from_planet], time, "J2000"); 0.0]
|
||||
planet1_state = [spkssb(ids[phase.from_planet], time, "ECLIPJ2000"); 0.0]
|
||||
time += phase.time_of_flight
|
||||
planet2_state = [spkssb(ids[phase.to_planet], time, "J2000"); 0.0]
|
||||
planet2_state = [spkssb(ids[phase.to_planet], time, "ECLIPJ2000"); 0.0]
|
||||
start = planet1_state + [0., 0., 0., phase.v∞_outgoing..., start_mass]
|
||||
final = planet2_state + [0., 0., 0., phase.v∞_incoming..., start_mass]
|
||||
println(start)
|
||||
|
||||
63
julia/src/outer_loop.jl
Normal file
63
julia/src/outer_loop.jl
Normal file
@@ -0,0 +1,63 @@
|
||||
using Random, Dates
|
||||
|
||||
export gen_decision_vector
|
||||
|
||||
"""
|
||||
Returns a random date between two dates
|
||||
"""
|
||||
function gen_date(date_range::Vector{DateTime})
|
||||
l0, lf = date_range
|
||||
l0 + Dates.Millisecond(floor(rand()*(lf-l0).value))
|
||||
end
|
||||
|
||||
"""
|
||||
Returns a random amount of time in a range
|
||||
"""
|
||||
function gen_period(date_range::Vector{DateTime})
|
||||
l0, lf = date_range
|
||||
Dates.Millisecond(floor(rand()*(lf-l0).value))
|
||||
end
|
||||
|
||||
"""
|
||||
So ideally, this should generate a nice random decision vector, given the constraints.
|
||||
Everything that you need to produce a vector of phases
|
||||
|
||||
Start with an empty vector of the right size
|
||||
You need:
|
||||
- launch_date
|
||||
- 3 components v∞_out for Earth
|
||||
- and then up to four flybys which contain:
|
||||
- a planet
|
||||
- three components v∞_in
|
||||
- turning angle (in ecliptic)
|
||||
- tof to planet
|
||||
and finally, the ending planet is held fixed
|
||||
"""
|
||||
function gen_decision_vector(launch_range::Vector{DateTime},
|
||||
target::String,
|
||||
arrival_deadline::DateTime)
|
||||
phases = Vector{Phase}()
|
||||
launch_date = gen_date(launch_range)
|
||||
v∞_out = 20rand(Float64,3) .- 10.
|
||||
|
||||
# Generate the planets (or null flybys)
|
||||
planets = [ ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"];
|
||||
repeat(["None"],8) ] # Just as likely to get a planet as no flyby
|
||||
long_flybys = [ "Earth"; filter(x -> x != "None", rand(planets, 4)); target ]
|
||||
# This will cut the flybys off if the target shows up early
|
||||
flybys = long_flybys[1:findfirst(x->x==target, long_flybys)]
|
||||
|
||||
time = launch_date
|
||||
for i in 1:length(flybys)-1
|
||||
v∞_in = 20rand(Float64,3) .- 10. # Generate the v∞_in components
|
||||
tof = gen_period([time,arrival_deadline])
|
||||
time += tof
|
||||
push!(phases,Phase(flybys[i],flybys[i+1], tof.value/1000, v∞_out, v∞_in))
|
||||
v∞_out_base = rand(Float64,3) .- 0.5
|
||||
v∞_out = norm(v∞_in) * v∞_out_base/norm(v∞_out_base)
|
||||
end
|
||||
|
||||
return phases
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user