#include "itkParticleSwarmOptimizerDOMReader.h"
namespace itk
{
void
ParticleSwarmOptimizerDOMReader::GenerateData( const DOMNodeType* inputdom, const void* )
{
LoggerType* logger = this->GetLogger();
OutputType* output = this->GetOutput();
if ( output == ITK_NULLPTR )
{
logger->Info( "creating the output PSO object ...\n" );
OutputType::Pointer object = OutputType::New();
output = (OutputType*)object;
this->SetOutput( output );
}
else
{
logger->Info( "filling an existing output PSO object ...\n" );
}
try
{
FancyString s;
logger->Info( "reading NumberOfParticles ...\n" );
s = inputdom->GetAttribute("NumberOfParticles");
int nop = 0; s >> nop;
output->SetNumberOfParticles( nop );
logger->Info( "reading MaximumNumberOfIterations ...\n" );
s = inputdom->GetAttribute("MaximumNumberOfIterations");
int noi = 0; s >> noi;
output->SetMaximalNumberOfIterations( noi );
logger->Info( "reading InertiaCoefficient ...\n" );
s = inputdom->GetAttribute("InertiaCoefficient");
double icoef = 0; s >> icoef;
output->SetInertiaCoefficient( icoef );
logger->Info( "reading GlobalCoefficient ...\n" );
s = inputdom->GetAttribute("GlobalCoefficient");
double gcoef = 0; s >> gcoef;
output->SetGlobalCoefficient( gcoef );
logger->Info( "reading PersonalCoefficient ...\n" );
s = inputdom->GetAttribute("PersonalCoefficient");
double pcoef = 0; s >> pcoef;
output->SetPersonalCoefficient( pcoef );
logger->Info( "reading LowerBound ...\n" );
const DOMNode* nodelb = inputdom->GetChildByID( "lower" );
s = nodelb->GetAttribute("value");
std::vector<double> lbound;
s.ToData( lbound );
logger->Info( "reading UpperBound ...\n" );
const DOMNode* nodeub = inputdom->GetChildByID( "upper" );
s = nodeub->GetAttribute("value");
std::vector<double> ubound;
s.ToData( ubound );
for ( size_t i=0; i<lbound.size(); i++ )
{
std::pair<double,double> value;
value.first = lbound[i];
value.second = ubound[i];
bounds.push_back( value );
}
output->SetParameterBounds( bounds );
logger->Info( "reading ParametersConvergenceTolerance ...\n" );
const DOMNode* nodeptols = inputdom->GetChild( "ParametersConvergenceTolerance" );
s = nodeptols->GetTextChild()->GetText();
s.ToData( ptols );
output->SetParametersConvergenceTolerance( ptols );
logger->Info( "reading FunctionConvergenceTolerance ...\n" );
s = inputdom->GetAttribute("FunctionConvergenceTolerance");
double ftol = 0; s >> ftol;
output->SetFunctionConvergenceTolerance( ftol );
logger->Info( "reading ConvergedPercentageToStop ...\n" );
s = inputdom->GetAttribute("ConvergedPercentageToStop");
double stoppercent = 0; s >> stoppercent;
output->SetPercentageParticlesConverged( stoppercent );
}
catch ( const std::ios_base::failure& f )
{
std::string s = f.what();
s.append( "\n" );
logger->Critical( s );
ExceptionObject
e( __FILE__, __LINE__ );
e.SetDescription( f.what() );
}
}
}