25 #include <boost/random/uniform_int.hpp>
26 #include <boost/random/uniform_real.hpp>
30 #include "../exceptions.h"
31 #include "../population.h"
32 #include "../problem/base.h"
33 #include "../problem/cstrs_self_adaptive.h"
36 #include "cstrs_self_adaptive.h"
38 namespace pagmo {
namespace algorithm {
51 m_original_algo(original_algo.clone()),m_gen(gen),m_ftol(ftol),m_xtol(xtol)
54 pagmo_throw(value_error,
"number of generations must be nonnegative");
60 m_ftol(algo.m_ftol),m_xtol(algo.m_xtol) {}
85 if(prob_c_dimension < 1) {
86 pagmo_throw(value_error,
"The problem is not constrained and Self-Adaptive is not suitable to solve it");
95 problem::cstrs_self_adaptive prob_new(prob,pop);
98 for(
int k=0; k<m_gen; k++) {
104 prob_new.reset_caches();
105 prob_new.update_penalty_coeff(pop);
119 m_original_algo->evolve(pop_new);
137 std::transform(dummy.begin(), dummy.end(), pop.
get_individual(worst).
cur_x.begin(), dummy.begin(),std::minus<double>());
139 pop_new.set_x(worst,pop.champion().
x);
140 pop_new.set_v(worst,dummy);
154 for(decision_vector::size_type i=0; i<prob_dimension; i++) {
156 dx += std::fabs(tmp[i]);
161 std::cout <<
"Exit condition -- xtol < " << m_xtol << std::endl;
170 std::cout <<
"Exit condition -- ftol < " << m_ftol << std::endl;
177 std::cout <<
"Generation " << k <<
" ***" << std::endl;
178 std::cout <<
" Best global fitness: " << pop.champion().
f << std::endl;
179 std::cout <<
" xtol: " << dx <<
", ftol: " << mah << std::endl;
180 std::cout <<
" xtol: " << dx <<
", ftol: " << mah << std::endl;
190 return m_original_algo->get_name() +
"[Self-Adaptive]";
199 return m_original_algo->clone();
210 m_original_algo = algo.
clone();
219 std::ostringstream s;
220 s <<
"algorithm: " << m_original_algo->get_name() <<
' ';
221 s <<
"\n\tConstraints handled with Self-Adaptive algorithm";
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base algorithm.
std::vector< double > decision_vector
Decision vector type.
const individual_type & get_individual(const size_type &) const
Get constant reference to individual at position n.
bool compare_x(const decision_vector &, const decision_vector &) const
Compare decision vectors.
size_type get_dimension() const
Return global dimension.
base_ptr get_algorithm() const
Get a copy of the internal local algorithm.
decision_vector x
Decision vector.
virtual base_ptr clone() const =0
Clone method.
fitness_vector f
Fitness vector.
bool m_screen_output
Indicates to the derived class whether to print stuff on screen.
std::string human_readable_extra() const
Extra human readable algorithm info.
c_size_type get_c_dimension() const
Return global constraints dimension.
void set_algorithm(const base &)
Set algorithm.
cstrs_self_adaptive(const base &=jde(), int gen=1, double=1e-15, double=1e-15)
Constructor.
container_type::size_type size_type
Population size type.
decision_vector cur_x
Current decision vector.
void evolve(population &) const
Evolve implementation.
constraint_vector::size_type c_size_type
Constraints' size type: the same as pagmo::constraint_vector's size type.
base_ptr clone() const
Clone method.
std::string get_name() const
Algorithm name.
Self-Adaptive Fitness constraints handling meta-algorithm.
decision_vector::size_type size_type
Problem's size type: the same as pagmo::decision_vector's size type.