remove \r
[extl.git] / extl / intelligence / ga / fopti / fopti_ga_traits.h
blob8de05d6c204294f04fa49afcf337b8964752e94a
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: fopti_ga_traits.h
4 * Created: 08.10.07
5 * Updated: 08.11.07
7 * Brief: The fopti_ga_traits class
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 #ifndef EXTL_INTELLIGENCE_FOPTI_GA_TRAITS_H
14 #define EXTL_INTELLIGENCE_FOPTI_GA_TRAITS_H
16 /*!\file fopti_ga_traits.h
17 * \brief The fopti_ga_traits class
19 #ifndef __cplusplus
20 # error fopti_ga_traits.h need be supported by c++.
21 #endif
23 /* ///////////////////////////////////////////////////////////////////////
24 * Includes
26 #include "prefix.h"
28 /* ///////////////////////////////////////////////////////////////////////
29 * ::extl::intelligence namespace
31 EXTL_INTELLIGENCE_BEGIN_WHOLE_NAMESPACE
33 /*!\brief fopti_ga_traits class
35 * \param C The ga_config type
37 * \ingroup extl_group_intelligence
39 template<typename_param_k C>
40 class fopti_ga_traits
41 : public ga_traits_base<fopti_ga_traits<C>, C>
43 /// \name Types
44 /// @{
45 public:
46 typedef ga_traits_base<fopti_ga_traits<C>, C> base_type;
47 typedef fopti_ga_traits class_type;
48 typedef typename_type_k base_type::config_type config_type;
49 typedef typename_type_k base_type::size_type size_type;
50 typedef typename_type_k base_type::bool_type bool_type;
51 typedef typename_type_k base_type::index_type index_type;
52 typedef typename_type_k base_type::int_type int_type;
53 typedef typename_type_k base_type::float_type float_type;
54 typedef typename_type_k base_type::random_type random_type;
55 typedef typename_type_k base_type::population_type population_type;
56 typedef typename_type_k base_type::individual_type individual_type;
57 typedef typename_type_k base_type::selection_traits_type selection_traits_type;
58 typedef typename_type_k base_type::crossover_traits_type crossover_traits_type;
59 typedef typename_type_k base_type::fitness_traits_type fitness_traits_type;
60 typedef typename_type_k base_type::rmake_traits_type rmake_traits_type;
61 typedef typename_type_k individual_type::scopes_type scopes_type;
62 typedef typename_type_k individual_type::scope_type scope_type;
63 typedef typename_type_k fitness_traits_type::penalty_traits_type penalty_traits_type;
64 typedef typename_type_k penalty_traits_type::constraints_type constraints_type;
65 typedef typename_type_k fitness_traits_type::func_traits_type func_traits_type;
66 typedef typename_type_k func_traits_type::func_type func_type;
67 /// @}
69 /// \name Members
70 /// @{
71 private:
72 scopes_type m_scopes;
73 /// @}
75 /// \name Attributes
76 /// @{
77 public:
78 float_type fvalue(individual_type const& idl) { return func_traits().fvalue(idl); }
80 func_type const& func() const { return func_traits().func(); }
81 func_type& func() { return func_traits().func(); }
82 void func(func_type const& func) { func_traits().func(func); }
84 scopes_type const& scopes() const { return m_scopes; }
85 scopes_type& scopes() { return m_scopes; }
86 void scopes(scopes_type const& sps) { m_scopes = sps; }
88 constraints_type const& constraints() const { return penalty_traits().constraints(); }
89 constraints_type& constraints() { return penalty_traits().constraints(); }
90 void constraints(constraints_type const& cons) { penalty_traits().constraints(cons); }
91 /// @}
93 /// \name Traits
94 /// @{
95 private:
96 func_traits_type const& func_traits() const { return this->fitness_traits().func_traits(); }
97 func_traits_type& func_traits() { return this->fitness_traits().func_traits(); }
99 penalty_traits_type const& penalty_traits() const { return this->fitness_traits().penalty_traits(); }
100 penalty_traits_type& penalty_traits() { return this->fitness_traits().penalty_traits(); }
101 /// @}
103 /// \name Initialization
104 /// @{
105 public:
106 /// initialize individual
107 void init_individual(individual_type& idl)
109 base_type::init_individual(idl);
111 /// initialize rmake_traits
112 void init_rmake_traits()
114 this->rmake_traits().init(this->rand(), scopes());
116 /// initialize fitness_traits
117 void init_fitness_traits()
119 if (!(this->rmake_traits().is_valid()))
120 init_rmake_traits();
121 this->fitness_traits().init(this->rmake_traits());
123 /// initialize crossover_traits
124 void init_crossover_traits()
126 this->crossover_traits().init(this->rand());
128 /// initialize mutation_traits
129 void init_mutation_traits()
131 this->mutation_traits().init(this->rand(), scopes());
133 /// initialize local_search_traits
134 void init_local_search_traits()
136 if (!(this->rmake_traits().is_valid()))
137 init_rmake_traits();
138 if (!(this->fitness_traits().is_valid()))
139 init_fitness_traits();
141 this->local_search_traits().init(this->rand(), this->rmake_traits(), this->fitness_traits());
143 /// @}
145 /// \name Methods
146 /// @{
147 public:
148 /// invariance
149 bool_type is_valid() const
151 return base_type::is_valid();
153 /// @}
156 /* ///////////////////////////////////////////////////////////////////////
157 * ::extl::intelligence namespace
159 EXTL_INTELLIGENCE_END_WHOLE_NAMESPACE
161 /* //////////////////////////////////////////////////////////////////// */
162 #endif /* EXTL_INTELLIGENCE_FOPTI_GA_TRAITS_H */
163 /* //////////////////////////////////////////////////////////////////// */