1 /* ///////////////////////////////////////////////////////////////////////
2 * File: fopti_ga_traits.h
7 * Brief: The fopti_ga_traits class
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
20 # error fopti_ga_traits.h need be supported by c++.
23 /* ///////////////////////////////////////////////////////////////////////
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
>
41 : public ga_traits_base
<fopti_ga_traits
<C
>, C
>
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
;
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
); }
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(); }
103 /// \name Initialization
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()))
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()))
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());
149 bool_type
is_valid() const
151 return base_type::is_valid();
156 /* ///////////////////////////////////////////////////////////////////////
157 * ::extl::intelligence namespace
159 EXTL_INTELLIGENCE_END_WHOLE_NAMESPACE
161 /* //////////////////////////////////////////////////////////////////// */
162 #endif /* EXTL_INTELLIGENCE_FOPTI_GA_TRAITS_H */
163 /* //////////////////////////////////////////////////////////////////// */