32 #ifndef SHARK_ALGORITHMS_DIRECT_SEARCH_OPERATORS_CROSSOVER_SBX_H 33 #define SHARK_ALGORITHMS_DIRECT_SEARCH_OPERATORS_CROSSOVER_SBX_H 41 template<
typename Po
intType>
51 template<
typename Function>
52 void init(
const Function & f ) {
54 if(!f.isConstrained()){
58 else if (f.hasConstraintHandler() && f.getConstraintHandler().isBoxConstrained()) {
60 ConstraintHandler
const& handler =
static_cast<ConstraintHandler const&
>(f.getConstraintHandler());
66 throw SHARKEXCEPTION(
"[SimulatedBinaryCrossover::init] Algorithm does only allow box constraints");
74 template<
typename Indiv
idualType>
79 for(
unsigned int i = 0; i < point1.size(); i++ ) {
81 if( !Rng::coinToss(
m_prob ) )
86 if( point2[i] < point1[i] ) {
95 if( std::abs(y2 - y1) > 1E-7 ) {
99 beta = 1 + 2 * (
m_upper( i ) - y2) / (y2 - y1);
101 beta = 1 + 2 * (y1 -
m_lower( i )) / (y2 - y1);
104 double expp =
m_nc + 1.;
106 double alpha = 2. - std::pow(1.0/beta , expp);
107 double u = Rng::uni( 0., 1. );
109 if( u <= 1. / alpha ) {
111 betaQ = std::pow( alpha, 1.0/expp );
114 alpha = 1. / (2. - alpha);
115 betaQ = std::pow( alpha, 1.0/expp );
121 point1[i] = 0.5 * ((y1 + y2) - betaQ * (y2 - y1));
122 point2[i] = 0.5 * ((y1 + y2) + betaQ * (y2 - y1));
124 if( Rng::coinToss() )
std::swap(point1[i], point2[i]);
140 template<
typename Archive>
141 void serialize( Archive & archive,
const unsigned int version ) {
142 archive & BOOST_SERIALIZATION_NVP(
m_nc );
143 archive & BOOST_SERIALIZATION_NVP(
m_prob );
144 archive & BOOST_SERIALIZATION_NVP(
m_upper );
145 archive & BOOST_SERIALIZATION_NVP(
m_lower );