Example #1
0
/// Implementation of the constraint function.
void gtoc5_rendezvous::compute_constraints_impl(constraint_vector &c, const decision_vector &x) const
{
	using namespace kep_toolbox;
	// We set the leg.
	const epoch epoch_i(x[0],epoch::MJD), epoch_f(x[1] + x[0],epoch::MJD);
	array3D v0, r0, vf, rf;
	m_source.eph(epoch_i,r0,v0);
	m_target.eph(epoch_f,rf,vf);
	m_leg.set_leg(epoch_i,sc_state(r0,v0,m_leg.get_spacecraft().get_mass()),x.begin() + 3, x.end(),epoch_f,sc_state(rf,vf,x[2]),ASTRO_MU_SUN);

	// We evaluate the state mismatch at the mid-point. And we use astronomical units to scale them
	m_leg.get_mismatch_con(c.begin(), c.begin() + 7);
	for (int i=0; i<3; ++i) c[i]/=ASTRO_AU;
	for (int i=3; i<6; ++i) c[i]/=ASTRO_EARTH_VELOCITY;
	c[6] /= m_leg.get_spacecraft().get_mass();
	// We evaluate the constraints on the throttles writing on the 7th mismatch constrant (mass is off)
	m_leg.get_throttles_con(c.begin() + 7, c.begin() + 7 + m_n_segments);
}
Example #2
0
/// Implementation of the constraint function.
void earth_planet::compute_constraints_impl(constraint_vector &c, const decision_vector &x) const
{
	// We decode the decision vector into a multiple fly-by trajectory
	trajectory.init_from_full_vector(x.begin(),x.end(),encoding);

	// We evaluate the state mismatch at the mid-point. And we use astronomical units to scale them
	trajectory.evaluate_all_mismatch_con(c.begin(), c.begin() + 7);
	for (int i=0; i<3; ++i) c[i]/=ASTRO_AU;
	for (int i=3; i<6; ++i) c[i]/=ASTRO_EARTH_VELOCITY;

	// We evaluate the constraints on the throttles writing on the 7th mismatch constrant (mass is off)
	trajectory.get_leg(0).get_throttles_con(c.begin() + 6, c.begin() + 6 + n_segments);

	// We evaluate the constraint on the initial launch velocity
	c[6 + n_segments] = (trajectory.evaluate_leg_vinf2_i(0) - vmax*vmax) / ASTRO_EARTH_VELOCITY / ASTRO_EARTH_VELOCITY;

	// We evaluate the linear constraint on the epochs (tf > ti)
	c[7 + n_segments] = trajectory.get_leg(0).get_t_i().mjd2000() - trajectory.get_leg(0).get_t_f().mjd2000();
}