00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "freSetupOptimizationProcessorController.h"
00023
00024 #include "freSetupOptimizationMetricControllerBase.h"
00025 #include "freSetupOptimizationOptimizerControllerBase.h"
00026 #include "freSetupTransformController.h"
00027
00028 namespace FREE
00029 {
00030
00034
00035
00036
00037 DefineParameterMacro(SetupOptimizationProcessorController,Setup,"Setup","Path to the setup that should be optimized. If a path is set, setup will be loaded automatically.");
00038 DefineParameterMacro(SetupOptimizationProcessorController,AdaptationList,"AdaptationList","Path to the adaptation list used as test basis for the optimization process. If a path is set, adaptation list will be loaded automatically.");
00039
00040 SetupOptimizationProcessorController::
00041 SetupOptimizationProcessorController() : ComponentControllerBase<ComponentType>()
00042 {
00043
00044 this->UpdateControllerID(ControllerID::SetupOptimizationProcessorController);
00045 this->m_Description = "Class processing a setup optimization.";
00046 };
00047
00048 void
00049 SetupOptimizationProcessorController::
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_Setup,Parameter::PVTURI,cParamDsc_Setup,1,"");
00058 profile.Parameters().AddParameter(cParam_AdaptationList,Parameter::PVTURI,cParamDsc_AdaptationList,1,"");
00059
00060
00061 profile.SubComponents().AddSubComponent(cComp_MainMetric);
00062 profile.SubComponents().AddSubComponent(cComp_MainTransform);
00063 profile.SubComponents().AddSubComponent(cComp_MainOptimizer);
00064
00065
00066 CtrlProfile::ProfileOption* pOption;
00067
00068 pOption = profile.Requirements().AddRequirement(cComp_MainMetric)->AddProfileOption();
00069 pOption->Inheritance().AddAncestor(ControllerID::SetupOptimizationMetricControllerBase);
00070 pOption->CheckForInheritance();
00071
00072 pOption = profile.Requirements().AddRequirement(cComp_MainTransform)->AddProfileOption();
00073 pOption->Inheritance().AddAncestor(ControllerID::SetupTransformControllerBase);
00074 pOption->CheckForInheritance();
00075
00076 pOption = profile.Requirements().AddRequirement(cComp_MainOptimizer)->AddProfileOption();
00077 pOption->Inheritance().AddAncestor(ControllerID::SetupOptimizationOptimizerControllerBase);
00078 pOption->CheckForInheritance();
00079 };
00080
00081 SetupOptimizationProcessorController::GenericComponentType*
00082 SetupOptimizationProcessorController::
00083 GetSubComponentCasted(ComponentType* pMainComponent, const ComponentID& compID,
00084 SessionComponentCache* pMainComponentCache) const
00085 {
00086 if (compID == cComp_MainMetric) return pMainComponent->GetMetric();
00087 if (compID == cComp_MainTransform) return pMainComponent->GetTransform();
00088 if (compID == cComp_MainOptimizer) return pMainComponent->GetOptimizer();
00089
00090 return ComponentControllerBase<ComponentType>::GetSubComponentCasted(pMainComponent, compID, pMainComponentCache);
00091 };
00092
00093 void
00094 SetupOptimizationProcessorController::
00095 SetSubComponentCasted(GenericComponentType* pSubComponent, ComponentType* pMainComponent,
00096 const ComponentID compID, SessionComponentCache* pMainComponentCache) const
00097 {
00098 if (compID == cComp_MainMetric) pMainComponent->SetMetric(static_cast<SetupOptimizationMetric*>(pSubComponent));
00099 else if (compID == cComp_MainTransform) pMainComponent->SetTransform(static_cast<SetupTransform*>(pSubComponent));
00100 else if (compID == cComp_MainOptimizer) pMainComponent->SetOptimizer(static_cast<SetupOptimizationOptimizer*>(pSubComponent));
00101 else ComponentControllerBase<ComponentType>::SetSubComponentCasted(pSubComponent, pMainComponent, compID, pMainComponentCache);
00102 };
00103
00104 void
00105 SetupOptimizationProcessorController::
00106 ActualizeMainComponent(ComponentType* pMainComponent,
00107 SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00108 const unsigned int& iActLevel) const
00109 {
00110 std::string sSetupFile;
00111 std::string sAdaptationsFile;
00112
00113 try
00114 {
00115 SessionAccessor::GetParameterValue(pComponentCache,cParam_Setup,sSetupFile);
00116 SessionAccessor::GetParameterValue(pComponentCache,cParam_AdaptationList,sAdaptationsFile);
00117 }
00118 catchAllNPassMacro("Error while retrieving parameter values.");
00119
00120 Setup::Pointer smpSetup = Setup::New();
00121
00122 if (!sSetupFile.empty())
00123 {
00124 try
00125 {
00126 smpSetup->LoadFromFile(sSetupFile);
00127 }
00128 catchAllNPassMacro("Unkown error while loading setup for setup optimization processor.");
00129
00130 pMainComponent->SetSetup(smpSetup);
00131 }
00132
00133 Adaptation::AdaptationList::Pointer smpAdaptations = Adaptation::AdaptationList::New();
00134
00135 if (!sAdaptationsFile.empty())
00136 {
00137 try
00138 {
00139 smpAdaptations->LoadFromFile(sAdaptationsFile);
00140 }
00141 catchAllNPassMacro("Unkown error while loading adaptation list for setup optimization processor.");
00142
00143 pMainComponent->SetAdaptationList(smpAdaptations);
00144 }
00145 };
00146
00147 void
00148 SetupOptimizationProcessorController::
00149 BuildFinalization(ComponentSetup* pComponentSetup, SessionComponentCache* pComponentCache) const
00150 {
00151 if (!pComponentCache) throwCtrlExceptionMacro("","Error: component cache is invalid (NULL), cannot finalize the building process.");
00152 if (!pComponentCache->ComponentIsAssigned()) throwCtrlExceptionMacro("","Error: component is missing, cannot finalize the building process.");
00153
00154 ComponentType* pMainComponent = dynamic_cast<ComponentType*>(pComponentCache->Component().GetPointer());
00155
00156 if (!pMainComponent) throwCtrlExceptionMacro("","Error: wrong main component type, cannot finalize the building process.");
00157
00158
00159
00160 pMainComponent->GetMetric()->SetTransform(pMainComponent->GetTransform());
00161 pMainComponent->GetMetric()->SetAdaptationList(pMainComponent->GetAdaptationList());
00162
00163 pMainComponent->GetOptimizer()->SetCostFunction(pMainComponent->GetMetric());
00164 };
00165
00166 void
00167 SetupOptimizationProcessorController::
00168 SetStatisticEntrySubComponents(StatisticEntry& rStatisticEntry, SessionComponentCache* pComponentCache,
00169 SessionInfo* pSessionInfo, StatisticDictionary& rDictionary) const
00170 {
00171 for (unsigned int index=0; index<pComponentCache->SubCaches().Size(); index++)
00172 {
00173 try
00174 {
00175 SessionComponentCache* pSubCache = (pComponentCache->SubCaches()).GetElement(index);
00176
00177 if (!pSubCache) throwCtrlExceptionMacro("","Error cannot set sub components. Sub cache is present but Null. IDPath: "<<pComponentCache->GetIDPath().ToStr()<<"; sub cache index: "<<index);
00178
00179 StatisticEntry::Pointer smpSubEntry = rStatisticEntry.CreateChildEntry();
00180
00181 StatisticEntryDefinition* pSubEntryDef = rDictionary.GetEntryDefinitionByName(pSubCache->GetIDPath(),pSubCache->GetComponentID());
00182 if (!pSubEntryDef)
00183 {
00184 pSubEntryDef = rDictionary.AddEntryDefinition(pSubCache->GetIDPath(),pSubCache->GetComponentID(),pSubCache->GetControllerID(),"sub component information");
00185 }
00186
00187 smpSubEntry->SetRefID(pSubEntryDef->GetRefID());
00188
00189 SessionBuilder::SetStatisticEntry(*smpSubEntry, pSubCache, pSessionInfo);
00190 }
00191 catchAllNPassMacro("Error while setting step statistic of subcomponent.");
00192 }
00193 };
00194
00195 }