25 #include <boost/random/uniform_int.hpp>
26 #include <boost/random/uniform_real.hpp>
27 #include <boost/random/variate_generator.hpp>
28 #include <boost/random/normal_distribution.hpp>
32 #include "../exceptions.h"
33 #include "../population.h"
34 #include "../problem/base.h"
35 #include "../problem/con2uncon.h"
38 #include "cstrs_core.h"
40 namespace pagmo {
namespace algorithm {
62 double ftol,
double xtol):
63 base(),m_original_algo(original_algo.clone()),
64 m_repair_algo(repair_algo.clone()),
65 m_gen(gen),m_repair_frequency(repair_frequency),
66 m_repair_ratio(repair_ratio),m_ftol(ftol),m_xtol(xtol)
72 pagmo_throw(value_error,
"number of generations must be nonnegative");
74 if(repair_frequency < 0) {
75 pagmo_throw(value_error,
"repair frequency must be positive");
77 if((repair_ratio < 0) || (repair_ratio > 1)) {
78 pagmo_throw(value_error,
"repair ratio must be in [0..1]");
84 base(algo),m_original_algo(algo.m_original_algo->clone()),
85 m_repair_algo(algo.m_repair_algo->clone()),m_gen(algo.m_gen),
86 m_repair_frequency(algo.m_repair_frequency),
87 m_repair_ratio(algo.m_repair_ratio),
88 m_ftol(algo.m_ftol),m_xtol(algo.m_xtol)
114 if(prob_c_dimension < 1) {
115 pagmo_throw(value_error,
"The problem is not constrained and CORE is not suitable to solve it");
118 pagmo_throw(value_error,
"The problem is multiobjective and CORE is not suitable to solve it");
139 std::vector<population::size_type> pop_infeasibles;
142 for(
int k=0; k<m_gen; k++) {
144 if(k%m_repair_frequency == 0) {
145 pop_infeasibles.clear();
150 pop_infeasibles.push_back(i);
161 pop.repair(current_individual_idx, m_repair_algo);
172 m_original_algo->evolve(pop_uncon);
185 for(decision_vector::size_type i=0; i<prob_dimension; i++) {
187 dx += std::fabs(tmp[i]);
192 std::cout <<
"Exit condition -- xtol < " << m_xtol << std::endl;
201 std::cout <<
"Exit condition -- ftol < " << m_ftol << std::endl;
208 std::cout <<
"Generation " << k <<
" ***" << std::endl;
209 std::cout <<
" Best global fitness: " << pop.champion().
f << std::endl;
210 std::cout <<
" xtol: " << dx <<
", ftol: " << mah << std::endl;
211 std::cout <<
" xtol: " << dx <<
", ftol: " << mah << std::endl;
220 return m_original_algo->get_name() +
"[CORE]";
229 return m_original_algo->clone();
240 m_original_algo = algo.
clone();
249 return m_repair_algo->clone();
260 m_repair_algo = algo.
clone();
269 std::ostringstream s;
270 s <<
"algorithms: " << m_original_algo->get_name() <<
" ";
271 s <<
"\n\tConstraints handled with CORE algorithm";
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base algorithm.
std::vector< double > decision_vector
Decision vector type.
void evolve(population &) const
Evolve implementation.
const individual_type & get_individual(const size_type &) const
Get constant reference to individual at position n.
bool feasibility_c(const constraint_vector &) const
Test feasibility of constraint vector.
constraint_vector cur_c
Current constraint vector.
CORE constraints handling meta-algorithm.
size_type get_dimension() const
Return global dimension.
Constrained to unconstrained meta-problem.
virtual base_ptr clone() const =0
Clone method.
fitness_vector f
Fitness vector.
base_ptr get_repair_algorithm() const
Get a copy of the internal local repair algorithm.
bool m_screen_output
Indicates to the derived class whether to print stuff on screen.
std::string get_name() const
Algorithm name.
base_ptr get_algorithm() const
Get a copy of the internal local algorithm.
cstrs_core(const base &=jde(1), const base &=jde(1), int=1, int=10, double=1., double=1e-15, double=1e-15)
Constructor.
c_size_type get_c_dimension() const
Return global constraints dimension.
void set_algorithm(const base &)
Set algorithm.
base_ptr clone() const
Clone method.
container_type::size_type size_type
Population size type.
decision_vector cur_x
Current decision vector.
void set_repair_algorithm(const base &)
Set algorithm.
f_size_type get_f_dimension() const
Return fitness dimension.
constraint_vector::size_type c_size_type
Constraints' size type: the same as pagmo::constraint_vector's size type.
std::string human_readable_extra() const
Extra human readable algorithm info.
decision_vector::size_type size_type
Problem's size type: the same as pagmo::decision_vector's size type.