remove \r
[extl.git] / extl / intelligence / ga / rmake_traits_base.h
blob51f75c885b5664926dce98acf0b7fcdef1dc2959
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: rmake_traits_base.h
4 * Created: 08.09.13
5 * Updated: 08.11.02
7 * Brief: The rmake_traits_base class
9 * [<Home>]
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
19 #ifndef __cplusplus
20 # error rmake_traits_base.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 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
47 /// \name Types
48 /// @{
49 public:
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;
59 /// @}
61 /// \name Members
62 /// @{
63 private:
64 random_type* m_prand;
65 /// @}
67 /// \name Attributes
68 /// @{
69 protected:
70 random_type const& rand() const { return *m_prand; }
71 random_type& rand() { return *m_prand; }
72 /// @}
74 /// \name Constructors
75 /// @{
76 public:
77 rmake_traits_base()
78 : m_prand(NULL)
80 /// @}
82 /// \name Methods
83 /// @{
84 public:
85 /// initialization
86 void init(random_type& rand)
88 m_prand = &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));
100 return pop;
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));
112 return pop;
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);
126 /// invariance
127 bool_type is_valid() const
129 if (NULL == m_prand) return e_false_v;
130 return e_true_v;
132 /// @}
134 private:
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 /* //////////////////////////////////////////////////////////////////// */