36 #ifndef SHARK_ALGORITHMS_DIRECT_SEARCH_SMS_EMOA_H 37 #define SHARK_ALGORITHMS_DIRECT_SEARCH_SMS_EMOA_H 64 m_mutator.
m_nm = 20.0;
65 m_crossover.
m_nc = 20.0;
66 m_crossoverProbability = 0.9;
76 return m_crossoverProbability;
80 return m_mutator.
m_nm;
84 return m_crossover.
m_nc;
87 unsigned int mu()
const{
100 return m_selection.indicator();
103 return m_selection.indicator();
107 archive & BOOST_SERIALIZATION_NVP(
m_parents );
108 archive & BOOST_SERIALIZATION_NVP( m_mu );
109 archive & BOOST_SERIALIZATION_NVP(
m_best );
111 archive & BOOST_SERIALIZATION_NVP( m_selection );
112 archive & BOOST_SERIALIZATION_NVP( m_crossover );
113 archive & BOOST_SERIALIZATION_NVP( m_mutator );
114 archive & BOOST_SERIALIZATION_NVP( m_crossoverProbability );
117 archive & BOOST_SERIALIZATION_NVP(
m_parents );
118 archive & BOOST_SERIALIZATION_NVP( m_mu );
119 archive & BOOST_SERIALIZATION_NVP(
m_best );
121 archive & BOOST_SERIALIZATION_NVP( m_selection );
122 archive & BOOST_SERIALIZATION_NVP( m_crossover );
123 archive & BOOST_SERIALIZATION_NVP( m_mutator );
124 archive & BOOST_SERIALIZATION_NVP( m_crossoverProbability );
136 std::vector<SearchPointType>
const& initialSearchPoints
139 std::vector<RealVector> values(initialSearchPoints.size());
140 for(std::size_t i = 0; i != initialSearchPoints.size(); ++i){
141 SHARK_RUNTIME_CHECK(
function.isFeasible(initialSearchPoints[i]),
"Starting point(s) not feasible");
142 values[i] =
function.eval(initialSearchPoints[i]);
145 std::size_t dim =
function.numberOfVariables();
146 RealVector lowerBounds(dim, -1E20);
147 RealVector upperBounds(dim, 1E20);
148 if (
function.hasConstraintHandler() &&
function.getConstraintHandler().isBoxConstrained()) {
150 ConstraintHandler
const& handler =
static_cast<ConstraintHandler const&
>(
function.getConstraintHandler());
152 lowerBounds = handler.
lower();
153 upperBounds = handler.upper();
156 function.hasConstraintHandler() && !
function.getConstraintHandler().isBoxConstrained(),
157 "Algorithm does only allow box constraints" 171 penalizingEvaluator(
function, offspring.begin(), offspring.end() );
179 std::vector<SearchPointType>
const& initialSearchPoints,
180 std::vector<ResultType>
const& functionValues,
181 RealVector
const& lowerBounds,
182 RealVector
const& upperBounds,
186 double crossover_prob
192 m_crossoverProbability = crossover_prob;
196 std::size_t numPoints = 0;
197 if(initialSearchPoints.size()<=
mu){
198 numPoints = initialSearchPoints.size();
199 for(std::size_t i = 0; i != numPoints; ++i){
200 m_parents[i].searchPoint() = initialSearchPoints[i];
201 m_parents[i].penalizedFitness() = functionValues[i];
202 m_parents[i].unpenalizedFitness() = functionValues[i];
206 for(std::size_t i = numPoints; i !=
mu; ++i){
207 std::size_t index =
random::discrete(*mpe_rng, std::size_t(0),initialSearchPoints.size()-1);
208 m_parents[i].searchPoint() = initialSearchPoints[index];
209 m_parents[i].penalizedFitness() = functionValues[index];
210 m_parents[i].unpenalizedFitness() = functionValues[index];
213 for(std::size_t i = 0; i !=
mu; ++i){
219 m_crossover.
init(lowerBounds,upperBounds);
220 m_mutator.
init(lowerBounds,upperBounds);
224 std::vector<IndividualType> offspring(1);
235 for(std::size_t i = 0; i !=
mu(); ++i){
250 IndividualType createOffspring(
251 std::vector<IndividualType>::const_iterator begin,
252 std::vector<IndividualType>::const_iterator end
256 IndividualType mate1( *selection(*mpe_rng, begin, end ) );
257 IndividualType mate2( *selection(*mpe_rng, begin, end) );
260 m_crossover(*mpe_rng, mate1, mate2 );
264 m_mutator(*mpe_rng, mate1 );
267 m_mutator(*mpe_rng, mate2 );
278 double m_crossoverProbability;
279 random::rng_type* mpe_rng;