1 /* ///////////////////////////////////////////////////////////////////////
2 * File: rmake_traits_base.h
7 * Brief: The rmake_traits_base class
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 #ifndef EXTL_INTELLIGENCE_GA_RMAKE_TRAITS_BASE_H
14 #define EXTL_INTELLIGENCE_GA_RMAKE_TRAITS_BASE_H
16 /*!\file rmake_traits_base.h
17 * \brief The rmake_traits_base class
20 # error rmake_traits_base.h need be supported by c++.
23 /* ///////////////////////////////////////////////////////////////////////
28 /* ///////////////////////////////////////////////////////////////////////
29 * ::extl::intelligence namespace
31 EXTL_INTELLIGENCE_BEGIN_WHOLE_NAMESPACE
33 /*!\brief rmake_traits_base class
35 * \param Pop The population type
36 * \param Rand The random type
37 * \param Pt The probability_traits type
39 * \ingroup extl_group_intelligence
41 template< typename_param_k D
42 , typename_param_k Pop
43 , typename_param_k Rand
45 class rmake_traits_base
50 typedef D derived_type
;
51 typedef Pop population_type
;
52 typedef typename_type_k
population_type::individual_type individual_type
;
53 typedef typename_type_k
individual_type::size_type size_type
;
54 typedef typename_type_k
individual_type::bool_type bool_type
;
55 typedef typename_type_k
individual_type::float_type float_type
;
56 typedef typename_type_k
individual_type::index_type index_type
;
57 typedef typename_type_k
individual_type::int_type int_type
;
58 typedef Rand random_type
;
70 random_type
const& rand() const { return *m_prand
; }
71 random_type
& rand() { return *m_prand
; }
74 /// \name Constructors
86 void init(random_type
& rand
)
90 /// randomly make population
91 population_type
& rmake(population_type
& pop
)
93 EXTL_ASSERT(derive().is_valid());
95 size_type pop_n
= pop
.size();
96 for (index_type i
= 0; i
< pop_n
; ++i
)
98 rmake(pop
.individual(i
));
102 /// randomly make population at hand
103 population_type
& rmake_at_hand(population_type
& pop
)
105 EXTL_ASSERT(derive().is_valid());
107 size_type pop_n
= pop
.size();
108 for (index_type i
= 0; i
< pop_n
; ++i
)
110 rmake_at_hand(pop
.individual(i
));
114 /// randomly make individual
115 individual_type
& rmake(individual_type
& idl
)
117 EXTL_ASSERT(derive().is_valid());
118 return derive().do_rmake(idl
);
120 /// randomly make individual at hand
121 individual_type
& rmake_at_hand(individual_type
& idl
)
123 EXTL_ASSERT(derive().is_valid());
124 return derive().do_rmake_at_hand(idl
);
127 bool_type
is_valid() const
129 if (NULL
== m_prand
) return e_false_v
;
135 derived_type
const& derive() const { return static_cast<derived_type
const&>(*this); }
136 derived_type
& derive() { return static_cast<derived_type
&>(*this); }
140 /* ///////////////////////////////////////////////////////////////////////
141 * ::extl::intelligence namespace
143 EXTL_INTELLIGENCE_END_WHOLE_NAMESPACE
145 /* //////////////////////////////////////////////////////////////////// */
146 #endif /* EXTL_INTELLIGENCE_GA_RMAKE_TRAITS_BASE_H */
147 /* //////////////////////////////////////////////////////////////////// */