00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "freAmoebaSOOptimizerController.h"
00024 #include "freExceptions.h"
00025
00026 namespace FREE
00027 {
00028
00032
00033
00034
00035 DefineParameterMacro(AmoebaSOOptimizerController,AutoInitialSimplex,"AutoInitialSimplex","Determines if the optimizer uses a small default simplex, SimplexDelta will be ignored.");
00036 DefineParameterMacro(AmoebaSOOptimizerController,SimplexDelta,"SimplexDelta","Starting size of the simplex");
00037 DefineParameterMacro(AmoebaSOOptimizerController,ParamConvTolerance,"ParamConvTolerance","Parameter convergence tolerance is the simplex diameter treshold. Optimation stopps if when the simplex diameter and the function convergence falls below their tresholds.");
00038 DefineParameterMacro(AmoebaSOOptimizerController,FunctConvTolerance,"FunctConvTolerance","Function convergence tolerance is the function convergence treshold. Optimation stopps if when the simplex diameter and the function convergence falls below their tresholds.");
00039
00040 AmoebaSOOptimizerController::
00041 AmoebaSOOptimizerController()
00042 {
00043
00044 this->UpdateControllerID(ControllerID::AmoebaSOOptimizerController);
00045 this->m_Description = "Optimizes by an amoeba optimizer (simplex) approach.";
00046 };
00047
00048 void
00049 AmoebaSOOptimizerController::
00050 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00051 const SessionComponentCache* pComponentCache,
00052 bool bRegardOldSetup) const
00053 {
00054 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00055
00056
00057 profile.Parameters().AddParameter(cParam_AutoInitialSimplex,CtrlProfile::Parameter::PVTBool,cParamDsc_AutoInitialSimplex,1,"true",-1,true);
00058 profile.Parameters().AddParameter(cParam_SimplexDelta,CtrlProfile::Parameter::PVTDouble,cParamDsc_SimplexDelta,1,"5",-1,true);
00059 profile.Parameters().AddParameter(cParam_ParamConvTolerance,CtrlProfile::Parameter::PVTDouble,cParamDsc_ParamConvTolerance,1,"1e-8",-1,true);
00060 profile.Parameters().AddParameter(cParam_FunctConvTolerance,CtrlProfile::Parameter::PVTDouble,cParamDsc_FunctConvTolerance,1,"1e-4",-1,true);
00061 profile.Parameters().AddParameter(cParam_Iterations,Parameter::PVTInteger,cParamDsc_Iterations,1,"500",-1,true);
00062 };
00063
00064 long
00065 AmoebaSOOptimizerController::
00066 GetMaxIterationCount(const SessionComponentCache* pComponentCache, unsigned int iResolutionLevel) const
00067 {
00068 if (!pComponentCache) throwCtrlExceptionMacro("","Passed pComponentCache is NULL.");
00069 if (!pComponentCache->SetupIsAssigned()) throwCtrlExceptionMacro("","Cache has no setup assigned.");
00070
00071 long lResult = 1;
00072 SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,lResult);
00073
00074 return lResult;
00075 };
00076
00077 void
00078 AmoebaSOOptimizerController::
00079 ActualizeMainComponent(ComponentType* pMainComponent,
00080 SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00081 const unsigned int& iActLevel) const
00082 {
00083 Superclass::ActualizeMainComponent(pMainComponent, pComponentCache,
00084 pSessionInfo, iActLevel);
00085
00086 bool bAutoSimplex;
00087 ComponentType::ParametersType simplexDelta;
00088 double dParamConvTolerance;
00089 double dFunctConvTolerance;
00090 int iNrOfIterations;
00091
00092 try
00093 {
00094 SessionAccessor::GetParameterValue(pComponentCache,cParam_AutoInitialSimplex,bAutoSimplex);
00095 SessionAccessor::GetParameterValue(pComponentCache,cParam_ParamConvTolerance,dParamConvTolerance);
00096 SessionAccessor::GetParameterValue(pComponentCache,cParam_FunctConvTolerance,dFunctConvTolerance);
00097 SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,iNrOfIterations);
00098 }
00099 catchAllNPassMacro("Error while retrieving parameter values.");
00100
00101 Parameter::Pointer smpParameter = SessionAccessor::GetParameter(pComponentCache,cParam_SimplexDelta);
00102 if (smpParameter.IsNull()) throwExceptionMacro("Missing parameter: " << cParam_SimplexDelta);
00103 simplexDelta = Convert::ParameterLayerToArray<ComponentType::ParametersType>(*(smpParameter->GetParameterLayer(0)));
00104
00105 pMainComponent->SetAutomaticInitialSimplex(bAutoSimplex);
00106 pMainComponent->SetInitialSimplexDelta( simplexDelta );
00107
00108 pMainComponent->SetParametersConvergenceTolerance(dParamConvTolerance);
00109 pMainComponent->SetFunctionConvergenceTolerance(dFunctConvTolerance);
00110 pMainComponent->SetMaximumNumberOfIterations(iNrOfIterations);
00111 };
00112
00113 void
00114 AmoebaSOOptimizerController::
00115 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00116 ComponentType* pMainComponent,
00117 SessionComponentCache* pMainComponentCache,
00118 SessionInfo* pSessionInfo,
00119 StatisticDictionary& rDictionary) const
00120 {
00121 ParameterArrayType parameters = pMainComponent->GetCachedCurrentPosition();
00122
00123 std::string sName = "Position #";
00124 std::string sIDPath = pMainComponentCache->GetIDPath();
00125 std::string sCommment = "Optimizer position. Meaning depends on chosen transformation";
00126 StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath,sName+"0");
00127
00128 if (!pEntry)
00129 {
00130 std::string sName = "Position #";
00131 pEntry = rDictionary.AddValueDefinition(sIDPath,sName+"0", sCommment);
00132 for (unsigned int i = 1; i<parameters.Size(); i++)
00133 {
00134 rDictionary.AddValueDefinition(sIDPath,sName+Convert::ToStr(i),sCommment);
00135 }
00136
00137 rDictionary.AddValueDefinition(sIDPath,"OptimizerValue", "Composed value of the optimizer");
00138 }
00139
00140 for (unsigned int i = 0; i<parameters.Size(); i++)
00141 {
00142 rStatisticEntry.AddValue(Convert::ToStr(parameters.GetElement(i)),pEntry->GetRefID()+i);
00143 }
00144
00145 rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetCurrentValue()),pEntry->GetRefID()+parameters.Size());
00146 };
00147
00148 }