30 #include <keplerian_toolbox/astro_constants.h>
33 #include "../exceptions.h"
41 namespace pagmo {
namespace problem {
60 gtoc_2::gtoc_2(
int ast1,
int ast2,
int ast3,
int ast4,
int n_seg,
objective obj):
61 base(12 * n_seg + 15,0,1,7 * 4 + n_seg * 4 + 1, n_seg * 4 + 1, 1E-3),
62 m_n_seg(n_seg),m_spacecraft(1500.,.1,4000.),m_obj(obj)
65 pagmo_throw(value_error,
"invalid number of segments");
67 m_asteroids.push_back(planet::gtoc2(910));
68 m_asteroids.push_back(planet::gtoc2(ast1));
69 m_asteroids.push_back(planet::gtoc2(ast2));
70 m_asteroids.push_back(planet::gtoc2(ast3));
71 m_asteroids.push_back(planet::gtoc2(ast4));
73 for (
int i = 0; i < 4; ++i) {
74 m_legs.push_back(leg());
75 m_legs.back().set_spacecraft(m_spacecraft);
76 m_legs.back().set_mu(1.32712440018e20);
77 m_legs.back().set_throttles_size(n_seg);
80 int asteroid_groups[4] = {m_asteroids[1].get_group(), m_asteroids[2].get_group(),
81 m_asteroids[3].get_group(), m_asteroids[4].get_group()};
82 std::sort(asteroid_groups,asteroid_groups + 4);
83 if (std::unique(asteroid_groups,asteroid_groups + 4) - asteroid_groups != 4) {
84 pagmo_throw(value_error,
"asteroids must belong to different groups");
86 if (std::find(asteroid_groups,asteroid_groups + 4,5) != asteroid_groups + 4) {
87 pagmo_throw(value_error,
"the Earth cannot appear in the list of asteroids");
91 lb_v.push_back(57023.5);
92 ub_v.push_back(64693.5);
94 for (
int i = 0; i < 3; ++i) {
100 ub_v.push_back(90.0000001);
104 ub_v.push_back(3600);
106 for (
int i = 0; i < 4; ++i) {
108 ub_v.push_back(1500);
111 for (
int i = 0; i < 3; ++i) {
112 lb_v.push_back(-3.5);
116 for (
int i = 0; i < 12 * n_seg; ++i) {
136 f[0] = (std::accumulate(x.begin() + 1,x.begin() + 8,0.) * ASTRO_DAY2YEAR);
139 f[0] = - x[11] / (std::accumulate(x.begin() + 1,x.begin() + 8,0.) * ASTRO_DAY2YEAR);
147 double initial_mass = m_spacecraft.get_mass();
148 double final_mass = x[8];
150 for (
int i = 0; i < 4; ++i) {
152 epoch start(std::accumulate(x.begin(),x.begin() + 2 * i + 1, 0.),epoch::MJD),
153 end(std::accumulate(x.begin(),x.begin() + 2 * i + 2, 0.),epoch::MJD);
155 m_legs[i].set_t_i(start);
156 m_legs[i].set_t_f(end);
158 m_asteroids[i].eph(start,r,v);
161 for (
int j = 0; j < 3; ++j) {
162 v[j] += x[12 + j] * 1000;
165 m_legs[i].set_x_i(sc_state(r,v,initial_mass));
167 for (
int j = 0; j < m_n_seg; ++j) {
168 m_legs[i].set_throttles(j,get_nth_throttle(j,x.begin() + 15 + 3 * i * m_n_seg,start,end));
171 m_asteroids[i + 1].eph(end,r,v);
172 m_legs[i].set_x_f(sc_state(r,v,final_mass));
174 initial_mass = final_mass;
177 final_mass = x[9 + i];
181 for (
int i = 0; i < 4; ++i) {
182 m_legs[i].get_mismatch_con(c.begin() + 7 * i, c.begin() + 7 * (i + 1));
184 for (
int j = 0; j < 3; ++j) {
185 c[7 * i + j] /= ASTRO_AU;
186 c[7 * i + j + 3] /= ASTRO_EARTH_VELOCITY;
191 for (
int i = 0; i < 4; ++i) {
192 m_legs[i].get_throttles_con(c.begin() + 28 + i * m_n_seg, c.begin() + 28 + (i + 1) * m_n_seg);
195 c.back() = (x[12] * x[12] + x[13] * x[13] + x[14] * x[14] - 3.5 * 3.5) / (ASTRO_EARTH_VELOCITY * ASTRO_EARTH_VELOCITY) * 1000000;
211 std::ostringstream oss;
212 oss <<
"\n\tAsteroid Sequence:\t\t\t";
213 for (
int i =1 ; i< 5; ++i ) oss << m_asteroids[i].
get_name() <<
" ";
224 std::ostringstream s;
228 s <<
"Final Mass: " << x[11] <<
" Kg" << std::endl;
229 s <<
"Total Time: " << std::accumulate(x.begin() + 1,x.begin() + 8,0.) * ASTRO_DAY2YEAR <<
" Years" << std::endl;
230 s <<
"Objective Function: " << x[11] / ( std::accumulate(x.begin() + 1,x.begin() + 8,0.) * ASTRO_DAY2YEAR ) <<
" Kg/Years" << std::endl;
231 for (
int i=0; i<4;++i) s << this->m_legs[i] << std::endl;
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
std::vector< double > decision_vector
Decision vector type.
std::string get_name() const
Implementation of the sparsity structure: automated detection.
void objfun_impl(fitness_vector &, const decision_vector &) const
Objective function implementation.
GTOC_2 Low-Thrust Multiple Asteroid Randezvous Problem.
objective
The objective function can be defined as final mass, final time or mass/time.
std::vector< double > fitness_vector
Fitness vector type.
c_size_type get_c_dimension() const
Return global constraints dimension.
std::vector< double > constraint_vector
Constraint vector type.
base_ptr clone() const
Clone method.
gtoc_2(int=815, int=300, int=110, int=47, int=10, objective=MASS_TIME)
Constructor.
void set_bounds(const decision_vector &, const decision_vector &)
Bounds setter from pagmo::decision_vector.
std::string pretty(const std::vector< double > &x) const
A pretty description of the chromosome.
void compute_constraints_impl(constraint_vector &, const decision_vector &) const
Implementation of constraint computation.
std::string human_readable_extra() const
Extra information in human readable format.