00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freEvolutionaryStrategyOptimizer_h
00023 #define __freEvolutionaryStrategyOptimizer_h
00024
00025 #include "freEvolutionaryStrategyOptimizerBase.h"
00026
00027 #include "freESPopulation.h"
00028 #include "freESParentSelectorBase.h"
00029 #include "freESRecombinatorBase.h"
00030 #include "freESMutationBase.h"
00031 #include "freESSelectionBase.h"
00032
00033 namespace FREE
00034 {
00035 namespace ES
00036 {
00037
00039 itkEventMacro( NewChildEvent, itk::AnyEvent );
00040
00042 itkEventMacro( NewChildGenerationEvent, NewChildEvent );
00043
00045 itkEventMacro( NewChildEvaluationEvent, NewChildEvent );
00046
00049 itkEventMacro( InvalidChildEvaluationEvent, NewChildEvent );
00050
00075 template<class TIndividual>
00076 class ITK_EXPORT EvolutionaryStrategyOptimizer:
00077 public EvolutionaryStrategyOptimizerBase
00078 {
00079 public:
00081 typedef EvolutionaryStrategyOptimizer Self ;
00082 typedef EvolutionaryStrategyOptimizerBase Superclass;
00083 typedef itk::SmartPointer<Self> Pointer;
00084 typedef itk::SmartPointer<const Self> ConstPointer;
00085
00087 itkNewMacro(Self);
00088
00090 itkTypeMacro(EvolutionaryStrategyOptimizer, EvolutionaryStrategyOptimizerBase );
00091
00092 typedef TIndividual IndividualType;
00093 typedef typename IndividualType::Pointer IndividualPointer;
00094 typedef typename IndividualType::ObjectiveValueType ObjectiveValueType;
00095 typedef typename IndividualType::IndividualIDType IndividualIDType;
00096 typedef std::vector<IndividualIDType> IndividualSelectionType;
00097 typedef std::map<IndividualIDType,IndividualSelectionType> HeritageMapType;
00098
00100 typedef Population<IndividualType> PopulationType;
00101 typedef typename PopulationType::Pointer PopulationPointer;
00102
00104 typedef itk::SingleValuedCostFunction CostFunctionType;
00105 typedef typename CostFunctionType::Pointer CostFunctionPointer;
00106 typedef typename CostFunctionType::ParametersType CostFunctionParametersType;
00107
00109 typedef ParentSelectorBase<IndividualType> ParentSelectorType;
00110 typedef typename ParentSelectorType::Pointer ParentSelectorPointer;
00111
00113 typedef RecombinatorBase<IndividualType> RecombinatorType;
00114 typedef typename RecombinatorType::Pointer RecombinatorPointer;
00115
00117 typedef MutationBase<IndividualType> MutationType;
00118 typedef typename MutationType::Pointer MutationPointer;
00119
00121 typedef SelectionBase<IndividualType> SelectionType;
00122 typedef typename SelectionType::Pointer SelectionPointer;
00123
00124
00126 itkSetMacro( NumberOfParents, unsigned long );
00127 itkGetConstMacro( NumberOfParents, unsigned long );
00128
00130 itkSetMacro( NumberOfChildren, unsigned long );
00131 itkGetConstMacro( NumberOfChildren, unsigned long );
00132
00133 itkSetMacro( MutateIntitialPopulation, bool );
00134 itkGetConstMacro( MutateIntitialPopulation, bool );
00135
00136 itkSetMacro( Threshold, ObjectiveValueType );
00137 itkGetConstMacro( Threshold, ObjectiveValueType );
00138
00139 virtual void SetParentSelector( ParentSelectorType * pParentSelector );
00140 itkGetConstObjectMacro( ParentSelector, ParentSelectorType );
00141 itkGetObjectMacro( ParentSelector, ParentSelectorType );
00142
00143 virtual void SetRecombinator( RecombinatorType * pRecombinator );
00144 itkGetConstObjectMacro( Recombinator, RecombinatorType );
00145 itkGetObjectMacro( Recombinator, RecombinatorType );
00146
00147 virtual void SetMutation( MutationType * pMutation );
00148 itkGetConstObjectMacro( Mutation, MutationType );
00149 itkGetObjectMacro( Mutation, MutationType );
00150
00151 virtual void SetSelection( SelectionType * pSelection );
00152 itkGetConstObjectMacro( Selection, SelectionType );
00153 itkGetObjectMacro( Selection, SelectionType );
00154
00155 itkGetConstObjectMacro( Population, PopulationType );
00156 itkGetObjectMacro( Population, PopulationType );
00157
00158 itkGetConstObjectMacro( CurrentChild, IndividualType );
00159 itkGetObjectMacro( CurrentChild, IndividualType );
00160
00164 const IndividualType* GetBestIndividualEver() const;
00168 const IndividualType* GetBestIndividual() const;
00169
00178 virtual void Initialize(const PopulationType& population);
00179
00183 virtual void Initialize();
00184
00188 virtual void StartOptimization();
00189
00190 virtual void ResumeOptimization();
00191
00195 const HeritageMapType& GetRecentParentSelections() const;
00196
00199 const PopulationPointer& GetRecentPopulationSelections() const;
00200
00202 const PopulationPointer& GetNewChildren() const;
00203
00204 protected:
00205 EvolutionaryStrategyOptimizer() ;
00206 EvolutionaryStrategyOptimizer(const EvolutionaryStrategyOptimizer&) ;
00207 virtual ~EvolutionaryStrategyOptimizer() ;
00208
00209 void PrintSelf(std::ostream& os, itk::Indent indent) const;
00210
00211 virtual void EvaluatePopulation(PopulationType* pPopulation) const;
00212 virtual void EvaluateIndividual(IndividualType* pIndividual) const;
00213
00214 virtual IndividualPointer FindBestIndividual(PopulationType* pPopulation);
00215
00216 virtual void SetBestIndividual(PopulationType* pPopulation);
00217
00218 virtual CostFunctionParametersType ConvertIndividualToParameter(const IndividualType* pIndividual) const;
00219
00220 private:
00221 ParentSelectorPointer m_ParentSelector;
00222
00223 RecombinatorPointer m_Recombinator;
00224
00225 MutationPointer m_Mutation;
00226
00227 SelectionPointer m_Selection;
00228
00229 PopulationPointer m_Population;
00230
00231 bool m_PopulationIsInitialized;
00232
00233 bool m_MutateIntitialPopulation;
00234
00235 unsigned long m_NumberOfParents;
00236
00237 unsigned long m_NumberOfChildren;
00238
00239 ObjectiveValueType m_Threshold;
00240
00241 mutable HeritageMapType m_ParentSelections;
00242
00243 mutable PopulationPointer m_SelectionVictims;
00244
00245 mutable PopulationPointer m_NewChildren;
00246
00247
00248
00249
00250 mutable IndividualPointer m_CurrentChild;
00251
00252 } ;
00253
00254 }
00255 }
00256
00257 #ifndef ITK_MANUAL_INSTANTIATION
00258 #include "freEvolutionaryStrategyOptimizer.txx"
00259 #endif
00260
00261 #endif