00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "freExhaustiveOptimizerController.h"
00024 #include "freExceptions.h"
00025
00026 namespace FREE
00027 {
00028
00032
00033 DefineParameterMacro(ExhaustiveOptimizerController, StepLength, "StepLength", "Steplength of each step in each direction.");
00034 DefineParameterMacro(ExhaustiveOptimizerController, NumberOfSteps, "NumberOfSteps", "Number of steps in each dimension along each direction. Thus there will be (2*NumberOfSteps)+1 steps in each dimension. One value per parameter.");
00035
00036 ExhaustiveOptimizerController::
00037 ExhaustiveOptimizerController()
00038 {
00039
00040 this->UpdateControllerID(ControllerID::ExhaustiveOptimizerController);
00041 this->m_Description = "Optimizes by an exhaustive search along the specified grid.";
00042 };
00043
00044 void
00045 ExhaustiveOptimizerController::
00046 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00047 const SessionComponentCache* pComponentCache,
00048 bool bRegardOldSetup) const
00049 {
00050 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00051
00052
00053 profile.Parameters().AddParameter(cParam_StepLength,CtrlProfile::Parameter::PVTDouble,cParamDsc_StepLength,1,"1",-1,true);
00054 profile.Parameters().AddParameter(cParam_NumberOfSteps,Parameter::PVTULong,cParamDsc_NumberOfSteps,1,"10",-1,true);
00055 };
00056
00057 ExhaustiveOptimizerController::
00058 ~ExhaustiveOptimizerController()
00059 {
00060 };
00061
00062 void
00063 ExhaustiveOptimizerController::
00064 ActualizeMainComponent(ComponentType* pMainComponent,
00065 SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00066 const unsigned int& iActLevel) const
00067 {
00068 double dStepLength;
00069
00070 try
00071 {
00072 SessionAccessor::GetParameterValue(pComponentCache,cParam_StepLength,dStepLength,0,iActLevel,true);
00073 }
00074 catchAllNPassMacro("Error while retrieving parameter values.");
00075 pMainComponent->SetStepLength(dStepLength);
00076
00077 ComponentType::StepsType steps;
00078
00079 Parameter::Pointer smpSteps = SessionAccessor::GetParameter(pComponentCache,cParam_NumberOfSteps);
00080 if (smpSteps.IsNull()) throwCtrlExceptionMacro("","Error; missing Parameter, cannot get "<<cParam_NumberOfSteps<<".");
00081 if (smpSteps->LayerCount()==0) throwCtrlExceptionMacro("","Error; parameter "<<cParam_NumberOfSteps<<" has no layer. Please check if the setup is valid.");
00082 unsigned int i = iActLevel;
00083 if (i>=smpSteps->LayerCount()) i = smpSteps->LayerCount()-1;
00084 steps = Convert::ParameterLayerToArray<ComponentType::StepsType>(*(smpSteps->GetParameterLayer(i)));
00085 pMainComponent->SetNumberOfSteps(steps);
00086
00087 ParameterArrayType scales = this->GetTransformScales(pComponentCache,iActLevel);
00088 pMainComponent->SetScales(scales);
00089 };
00090
00091 void
00092 ExhaustiveOptimizerController::
00093 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00094 ComponentType* pMainComponent,
00095 SessionComponentCache* pMainComponentCache,
00096 SessionInfo* pSessionInfo,
00097 StatisticDictionary& rDictionary) const
00098 {
00099 Superclass::SetStatisticEntryMainComponent(rStatisticEntry, pMainComponent, pMainComponentCache,
00100 pSessionInfo, rDictionary);
00101 std::string sName = "OptimizerValue";
00102 std::string sIDPath = pMainComponentCache->GetIDPath();
00103 StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath, sName);
00104
00105 if (!pEntry)
00106 {
00107 pEntry = rDictionary.AddValueDefinition(sName, sIDPath, "Current value of the optimizer");
00108 }
00109
00110 rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetCurrentValue()),pEntry->GetRefID());
00111 };
00112
00113 ExhaustiveOptimizerController::MeasuresType
00114 ExhaustiveOptimizerController::
00115 GetCurrentValue(ComponentType* pOptimizer) const
00116 {
00117 MeasuresType values(1);
00118 values.Fill(pOptimizer->GetCurrentValue());
00119 return values;
00120 };
00121
00122 }