freEvolutionaryStrategySOOptimizer.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freEvolutionaryStrategySOOptimizer.cxx,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 
00023 #include "freEvolutionaryStrategySOOptimizer.h"
00024 #include "itkCommand.h"
00025 #include "itkEventObject.h"
00026 
00027 namespace FREE
00028 {
00029 
00033 EvolutionaryStrategySOOptimizer
00034 ::EvolutionaryStrategySOOptimizer()
00035 {
00036   itkDebugMacro("Constructor");
00037 
00038         m_InternalOptimizer = InternalOptimizerType::New();
00039         m_CostFunctionWrapper = ItkSingleValuedCostFunctionWrapper::New();
00040 
00041         m_IterationObserver = IterationObserver::New();
00042         m_IterationNotificationEvent = NotificationEvent<Self>::New(this, &Self::OnOptIteration);
00043         m_IterationObserver->fnOnNotify = m_IterationNotificationEvent;
00044         m_InternalOptimizer->AddObserver(itk::IterationEvent(), m_IterationObserver);
00045 
00046         m_StartObserver = StartObserver::New();
00047         m_StartNotificationEvent = NotificationEvent<Self>::New(this, &Self::OnOptStart);
00048         m_StartObserver->fnOnNotify = m_StartNotificationEvent;
00049         m_InternalOptimizer->AddObserver(itk::StartEvent(), m_StartObserver);
00050 
00051         m_EndObserver = EndObserver::New();
00052         m_EndNotificationEvent = NotificationEvent<Self>::New(this, &Self::OnOptEnd);
00053         m_EndObserver->fnOnNotify = m_EndNotificationEvent;
00054         m_InternalOptimizer->AddObserver(itk::EndEvent(), m_EndObserver);
00055 
00056         m_ChildGenerationObserver = ChildGenerationObserver::New();
00057         m_ChildGenerationNotificationEvent = NotificationEvent<Self>::New(this, &Self::OnChildGen);
00058         m_ChildGenerationObserver->fnOnNotify = m_ChildGenerationNotificationEvent;
00059   m_InternalOptimizer->AddObserver(ES::NewChildGenerationEvent(), m_ChildGenerationObserver);
00060 
00061   m_ChildEvaluationObserver = ChildEvaluationObserver::New();
00062         m_ChildEvaluationNotificationEvent = NotificationEvent<Self>::New(this, &Self::OnChildEval);
00063         m_ChildEvaluationObserver->fnOnNotify = m_ChildEvaluationNotificationEvent;
00064   m_InternalOptimizer->AddObserver(ES::NewChildEvaluationEvent(), m_ChildEvaluationObserver);
00065 
00066   m_CurrentValue = 0;
00067   m_CurrentDecomposedValue.Fill(0.0);
00068 }
00069 
00070 void
00071 EvolutionaryStrategySOOptimizer
00072 ::PrintSelf(std::ostream& os, itk::Indent indent) const
00073 {
00074   Superclass::PrintSelf(os,indent);
00075 
00076   os << indent << "CurrentValue = " << m_CurrentValue << std::endl;
00077   os << indent << "CurrentDecomposedValue = " << m_CurrentDecomposedValue << std::endl;
00078 }
00079 
00080 void
00081 EvolutionaryStrategySOOptimizer
00082 ::StartOptimization( void )
00083 {
00084   m_InternalOptimizer->SetScales(this->GetScales());
00085   m_InternalOptimizer->StartOptimization();
00086 }
00087 
00088 bool
00089 EvolutionaryStrategySOOptimizer
00090 ::IsStoppable() const
00091 {
00092   return true;
00093 };
00094 
00095  
00096 void
00097 EvolutionaryStrategySOOptimizer
00098 ::StopOptimization()
00099 {
00100   m_InternalOptimizer->StopOptimization();
00101 };
00102 
00103 bool
00104 EvolutionaryStrategySOOptimizer
00105 ::IsResumeable() const
00106 {
00107   return true;
00108 };
00109 
00110 void
00111 EvolutionaryStrategySOOptimizer
00112 ::ResumeOptimization()
00113 {
00114   m_InternalOptimizer->ResumeOptimization();
00115 };
00116 
00117 const EvolutionaryStrategySOOptimizer::HeritageMapType&
00118 EvolutionaryStrategySOOptimizer
00119 ::GetRecentParentSelections() const
00120 {
00121   return m_InternalOptimizer->GetRecentParentSelections();
00122 };
00123 
00124 const EvolutionaryStrategySOOptimizer::PopulationPointer&
00125 EvolutionaryStrategySOOptimizer
00126 ::GetRecentPopulationSelections() const
00127 {
00128   return m_InternalOptimizer->GetRecentPopulationSelections();
00129 };
00130 
00131 
00132 const EvolutionaryStrategySOOptimizer::PopulationPointer&
00133 EvolutionaryStrategySOOptimizer
00134 ::GetNewChildren() const
00135 {
00136   return m_InternalOptimizer->GetNewChildren();
00137 };
00138 
00139 
00140 EvolutionaryStrategySOOptimizer::InternalOptimizerType * 
00141 EvolutionaryStrategySOOptimizer
00142 ::GetInternalOptimizer()
00143 {
00144   return m_InternalOptimizer;
00145 }
00146 
00147 void
00148 EvolutionaryStrategySOOptimizer::
00149 OnOptIteration(void* pSender, long threadID)
00150 {
00151         m_CurrentValue = m_InternalOptimizer->GetCurrentCost();
00152         m_CurrentDecomposedValue = m_CostFunction->GetCurrentDecomposedValue();
00153         this->SetCurrentPosition(m_InternalOptimizer->GetCurrentPosition());
00154 
00155         m_BestValue = m_CurrentValue;
00156         m_BestPosition = m_InternalOptimizer->GetCurrentPosition();
00157         
00158         //and pass the signal to the rest of the world
00159         this->InvokeEvent( itk::IterationEvent() );
00160 
00161   m_MeasureMap.clear();
00162 };
00163 
00164 void
00165 EvolutionaryStrategySOOptimizer::
00166 OnOptStart(void* pSender, long threadID)
00167 {
00168   //just pass the signal to the rest of the world
00169   this->InvokeEvent( itk::StartEvent() );
00170 };
00171 
00172 void
00173 EvolutionaryStrategySOOptimizer::
00174 OnOptEnd(void* pSender, long threadID)
00175 {
00176   //just pass the signal to the rest of the world
00177   this->InvokeEvent( itk::EndEvent() );
00178 };
00179 
00180 void
00181 EvolutionaryStrategySOOptimizer::
00182 OnChildGen(void* pSender, long threadID)
00183 {
00184   //just pass the signal to the rest of the world
00185   this->InvokeEvent( ES::NewChildGenerationEvent() );
00186 
00187   const IndividualType* pChild = GetCurrentChild();
00188   if (pChild)
00189   {
00190     std::ostringstream strstream;
00191     pChild->Print(strstream);
00192     this->InvokeEvent( EvaluationProgressObserverEvent(0,strstream.str()) );
00193   }
00194 };
00195 
00196 void
00197 EvolutionaryStrategySOOptimizer::
00198 OnChildEval(void* pSender, long threadID)
00199 {
00200   //Get the decomposed metric value for the child
00201   //so it can be used for the statistics
00202   const IndividualType* pChild = GetCurrentChild();
00203   if (pChild)
00204   {
00205     m_MeasureMap[pChild->GetIndividualID()] = m_CostFunction->GetCurrentDecomposedValue();
00206   }
00207 
00208   //now pass the signal to the rest of the world
00209   this->InvokeEvent( ES::NewChildEvaluationEvent() );
00210 };
00211 
00212 EvolutionaryStrategySOOptimizer::DecomposedMeasureType
00213 EvolutionaryStrategySOOptimizer::
00214 GetDecomposedIndividualValue(const IndividualIDType& rID)
00215 {
00216   return m_MeasureMap[rID];
00217 };
00218 
00219 void
00220 EvolutionaryStrategySOOptimizer::
00221 SetCostFunction( CostFunctionType * costFunction )
00222 {
00223   Superclass::SetCostFunction(costFunction);
00224   m_CostFunctionWrapper->SetWrappedCostFunction(costFunction);
00225   m_InternalOptimizer->SetCostFunction(m_CostFunctionWrapper);
00226 };
00227 
00228 void
00229 EvolutionaryStrategySOOptimizer::
00230 SetMaximize(bool maximize)
00231 {
00232   m_InternalOptimizer->SetMaximize(maximize);
00233 };
00234 
00235 bool
00236 EvolutionaryStrategySOOptimizer::
00237 GetMaximize() const
00238 { 
00239   return m_InternalOptimizer->GetMaximize();
00240 };
00241 
00242 void
00243 EvolutionaryStrategySOOptimizer::
00244 SetInitialPosition (const ParametersType &param)
00245 {
00246   Superclass::SetInitialPosition(param);
00247   m_InternalOptimizer->SetInitialPosition(param);
00248 };
00249 
00250 void
00251 EvolutionaryStrategySOOptimizer::
00252 SetMaximumIteration(unsigned int iMaximumIteration)
00253 {
00254   m_InternalOptimizer->SetMaximumIteration(iMaximumIteration);
00255 };
00256 
00257 const unsigned int
00258 EvolutionaryStrategySOOptimizer::
00259 GetMaximumIteration() const
00260 {
00261   return m_InternalOptimizer->GetMaximumIteration();
00262 };
00263 
00264 void
00265 EvolutionaryStrategySOOptimizer::
00266 SetNumberOfParents(unsigned long iNumberOfParents)
00267 {
00268   m_InternalOptimizer->SetNumberOfParents(iNumberOfParents);
00269 };
00270 
00271 const unsigned long
00272 EvolutionaryStrategySOOptimizer::
00273 GetNumberOfParents() const
00274 {
00275   return m_InternalOptimizer->GetNumberOfParents();
00276 };
00277 
00278 void
00279 EvolutionaryStrategySOOptimizer::
00280 SetNumberOfChildren(unsigned long iNumberOfChildren)
00281 {
00282   m_InternalOptimizer->SetNumberOfChildren(iNumberOfChildren);
00283 };
00284 
00285 const unsigned long
00286 EvolutionaryStrategySOOptimizer::
00287 GetNumberOfChildren() const
00288 {
00289   return m_InternalOptimizer->GetNumberOfChildren();
00290 };
00291 
00292 void
00293 EvolutionaryStrategySOOptimizer::
00294 SetMutateIntitialPopulation(bool bMutateIntitialPopulation)
00295 {
00296   m_InternalOptimizer->SetMutateIntitialPopulation(bMutateIntitialPopulation);
00297 };
00298 
00299 const bool
00300 EvolutionaryStrategySOOptimizer::
00301 GetMutateIntitialPopulation() const
00302 {
00303   return m_InternalOptimizer->GetMutateIntitialPopulation();
00304 };
00305 
00306 
00307 void
00308 EvolutionaryStrategySOOptimizer::
00309 SetThreshold(ObjectiveValueType threshold)
00310 {
00311   m_InternalOptimizer->SetThreshold(threshold);
00312 };
00313 
00314 const EvolutionaryStrategySOOptimizer::ObjectiveValueType
00315 EvolutionaryStrategySOOptimizer::
00316 GetThreshold() const
00317 {
00318   return m_InternalOptimizer->GetThreshold();
00319 };
00320 
00321 void
00322 EvolutionaryStrategySOOptimizer::
00323 SetParentSelector( ParentSelectorType * pParentSelector )
00324 {
00325   m_InternalOptimizer->SetParentSelector(pParentSelector);
00326 };
00327 
00328 const EvolutionaryStrategySOOptimizer::ParentSelectorType*
00329 EvolutionaryStrategySOOptimizer::
00330 GetParentSelector() const
00331 {
00332   return m_InternalOptimizer->GetParentSelector();
00333 };
00334 
00335 EvolutionaryStrategySOOptimizer::ParentSelectorType*
00336 EvolutionaryStrategySOOptimizer::
00337 GetParentSelector()
00338 {
00339   return m_InternalOptimizer->GetParentSelector();
00340 };
00341 
00342 void
00343 EvolutionaryStrategySOOptimizer::
00344 SetRecombinator( RecombinatorType * pRecombinator )
00345 {
00346   m_InternalOptimizer->SetRecombinator(pRecombinator);
00347 };
00348 
00349 const EvolutionaryStrategySOOptimizer::RecombinatorType*
00350 EvolutionaryStrategySOOptimizer::
00351 GetRecombinator() const
00352 {
00353   return m_InternalOptimizer->GetRecombinator();
00354 };
00355 
00356 EvolutionaryStrategySOOptimizer::RecombinatorType*
00357 EvolutionaryStrategySOOptimizer::
00358 GetRecombinator()
00359 {
00360   return m_InternalOptimizer->GetRecombinator();
00361 };
00362 
00363 void
00364 EvolutionaryStrategySOOptimizer::
00365 SetMutation( MutationType * pMutation )
00366 {
00367   m_InternalOptimizer->SetMutation(pMutation);
00368 };
00369 
00370 const EvolutionaryStrategySOOptimizer::MutationType*
00371 EvolutionaryStrategySOOptimizer::
00372 GetMutation() const
00373 {
00374   return m_InternalOptimizer->GetMutation();
00375 };
00376 
00377 EvolutionaryStrategySOOptimizer::MutationType*
00378 EvolutionaryStrategySOOptimizer::
00379 GetMutation()
00380 {
00381   return m_InternalOptimizer->GetMutation();
00382 };
00383 
00384 void
00385 EvolutionaryStrategySOOptimizer::
00386 SetSelection( SelectionType * pSelection )
00387 {
00388   m_InternalOptimizer->SetSelection(pSelection);
00389 };
00390 
00391 const EvolutionaryStrategySOOptimizer::SelectionType*
00392 EvolutionaryStrategySOOptimizer::
00393 GetSelection() const
00394 {
00395   return m_InternalOptimizer->GetSelection();
00396 };
00397 
00398 EvolutionaryStrategySOOptimizer::SelectionType*
00399 EvolutionaryStrategySOOptimizer::
00400 GetSelection()
00401 {
00402   return m_InternalOptimizer->GetSelection();
00403 };
00404 
00405 const EvolutionaryStrategySOOptimizer::PopulationType*
00406 EvolutionaryStrategySOOptimizer::
00407 GetPopulation() const
00408 {
00409   return m_InternalOptimizer->GetPopulation();
00410 };
00411 
00412 EvolutionaryStrategySOOptimizer::PopulationType*
00413 EvolutionaryStrategySOOptimizer::
00414 GetPopulation()
00415 {
00416   return m_InternalOptimizer->GetPopulation();
00417 };
00418 
00419 const EvolutionaryStrategySOOptimizer::IndividualType*
00420 EvolutionaryStrategySOOptimizer::
00421 GetBestIndividualEver() const
00422 {
00423   return m_InternalOptimizer->GetBestIndividualEver();
00424 };
00425 
00426 const EvolutionaryStrategySOOptimizer::IndividualType*
00427 EvolutionaryStrategySOOptimizer::
00428 GetBestIndividual() const
00429 {
00430   return m_InternalOptimizer->GetBestIndividual();
00431 };
00432 
00433 void
00434 EvolutionaryStrategySOOptimizer::
00435 Initialize(const PopulationType& population)
00436 {
00437   m_InternalOptimizer->Initialize(population);
00438   m_MeasureMap.clear();
00439 };
00440 
00441 void
00442 EvolutionaryStrategySOOptimizer::
00443 Initialize()
00444 {
00445   m_InternalOptimizer->Initialize();
00446   m_MeasureMap.clear();
00447 };
00448 
00449 const EvolutionaryStrategySOOptimizer::IndividualType*
00450 EvolutionaryStrategySOOptimizer::
00451 GetCurrentChild() const
00452 {
00453   return m_InternalOptimizer->GetCurrentChild();
00454 };
00455 
00456 EvolutionaryStrategySOOptimizer::IndividualType*
00457 EvolutionaryStrategySOOptimizer::
00458 GetCurrentChild()
00459 {
00460   return m_InternalOptimizer->GetCurrentChild();
00461 };
00462 
00463 } // end namespace FREE
00464 
00465 

Generated at Sat Oct 13 15:54:36 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000