All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions | Static Public Attributes | Protected Member Functions
DinverCore::RealSpace Class Reference

Brief description of class still missing. More...

#include <RealSpace.h>

Inheritance diagram for DinverCore::RealSpace:
QGpCoreTools::XMLClass

List of all members.

Public Member Functions

void addCondition (AbstractCondition *c)
ParameteraddParameter (QString name, QString unit, double min, double max, ParameterGrid::Scale scale, double precision)
ParameteraddParameter (Parameter *p)
bool adjustRanges ()
int allParameterCount () const
uint checksum () const
void clearParameters ()
void conditionDiagnostic () const
void humanInfo () const
bool isOk () const
bool isOkDebug () const
bool isOkDebugVerbose () const
bool operator!= (const RealSpace &o) const
bool operator== (const RealSpace &o) const
const Parameterparameter (int index) const
Parameterparameter (int index)
Parameterparameter (QString name)
double possibleCount () const
void printModel ()
 RealSpace ()
void setParameterNamePrefix (const QString &p)
void setVariableParameters ()
const ParametervariableParameter (int index) const
ParametervariableParameter (int index)
int variableParameterCount () const
virtual const QString & xml_tagName () const
virtual ~RealSpace ()

Static Public Attributes

static const QString xmlRealSpaceTag = "RealSpace"

Protected Member Functions

virtual XMLMember xml_member (XML_MEMBER_ARGS)
virtual void xml_polish (XML_POLISH_ARGS)
virtual void xml_writeChildren (XML_WRITECHILDREN_ARGS) const

Detailed Description

Brief description of class still missing.

Full description of class still missing TODO: RealSpace must provide a vector of values directly rather than fetching each parameter individualy


Constructor & Destructor Documentation

{}

Description of destructor still missing

References TRACE.

{
  TRACE;
  qDeleteAll(_allParameters);
  qDeleteAll(_conditions);
}

Member Function Documentation

Parameter * DinverCore::RealSpace::addParameter ( QString  name,
QString  unit,
double  min,
double  max,
ParameterGrid::Scale  scale,
double  precision 
)

Adds one parameter to space

References DinverCore::Parameter::initGrid(), DinverCore::Parameter::name(), DinverCore::Parameter::setMaximum(), DinverCore::Parameter::setMinimum(), DinverCore::Parameter::setName(), DinverCore::Parameter::setPrecision(), DinverCore::Parameter::setScale(), DinverCore::Parameter::setUnit(), and TRACE.

Referenced by Spac3CForward::clone(), DinverDCCore::ParamLayer::depthToParam(), DinverCore::dinver_set_parameter_count(), DinverCore::dinver_set_parameter_count_(), DinverCore::ParamExpressionContext::functionValue(), and DinverDCCore::ParamLayer::valueToParam().

{
  TRACE;
  Parameter * p=new Parameter;
  p->setName(name);
  p->setUnit(unit);
  p->setMinimum(min);
  p->setMaximum(max);
  p->setScale(scale);
  p->setPrecision(precision);
  if(p->initGrid()) {
    if(!_parameterNamePrefix.isEmpty()) {
      p->setName(_parameterNamePrefix+p->name());
    }
    _allParameters.append(p);
    return p;
  } else {
    delete p;
    return 0;
  }
}

Adds one parameter to space

References DinverCore::Parameter::name(), DinverCore::Parameter::setName(), and TRACE.

{
  TRACE;
  if(!_parameterNamePrefix.isEmpty()) {
    p->setName(_parameterNamePrefix+p->name());
  }
  _allParameters.append(p);
  return p;
}

With a big number of parameters, if some range of parameter are not adjusted, it might take a very long time to initialize. Return true if all range are compatible.

References DinverCore::AbstractCondition::adjustRanges(), QGpCoreTools::endl(), DinverCore::Parameter::getRectangularLimits(), DinverCore::Parameter::initGrid(), DinverCore::Parameter::name(), QGpCoreTools::tr(), and TRACE.

Referenced by main(), ThreadLauncher::newThread(), DinverCore::Neighborhood::setThreadCount(), DinverCore::ModelRepository::start(), DinverCore::Neighborhood::start(), and Forward::xml_polish().

{
  TRACE;
  bool modified=true;
  while(modified) {
    modified=false;
    foreach(AbstractCondition * ac, _conditions) {
      if(ac->adjustRanges()) {
        modified=true;
      }
    }
    if(modified) {
      // check validity of modified ranges and re-initialize parameter grid
      bool detectedError=false;
      foreach(Parameter * p, _variableParameters) {
        double minp, maxp;
        p->getRectangularLimits(minp, maxp);
        if(minp>=maxp) {
          App::stream() << tr("%1: conditions require a bad parameter range [%2,%3]")
                    .arg(p->name()).arg(minp).arg(maxp) << endl;
          detectedError=true;
        }
        if(!p->initGrid()) {
          App::stream() << tr("%1: error initializing grid in range [%2,%3]")
                    .arg(p->name()).arg(minp).arg(maxp) << endl;
          detectedError=true;
        }
      }
      if(detectedError) return false;
    }
  }
  return true;
}

Returns a number that uniquely identify this parameterization

References allParameterCount(), TRACE, and variableParameterCount().

Referenced by humanInfo(), DinverCore::ModelSet::importModelsFromReport(), DinverCore::BatchRun::neighborhoodOptimization(), DinverCore::ImportanceSampling::setForward(), and DinverCore::ModelRepository::setStorage().

{
  TRACE;
  int ndVar=variableParameterCount();
  int ndAll=allParameterCount();
  uint sum=0;
  sum+=ndVar;
  sum+=ndAll*ndVar;
  for(int i=0;i<ndVar;i++) {
    sum+=(i+1)*_variableParameters[i]->checksum();
  }
  for(int i=0;i<ndAll;i++) {
    sum+=(i+ndVar+1)*_allParameters[i]->checksum();
  }
  return sum;
}

Removes all parameters

References TRACE.

Referenced by Forward::setParamSpace(), and ModelGenerator::setParamSpace().

{
  TRACE;
  qDeleteAll(_allParameters);
  _allParameters.clear();
  _variableParameters.clear();
  qDeleteAll(_conditions);
  _conditions.clear();
}

Print a diagnostic of current model: does it fit will all conditions?

References DinverCore::Parameter::conditionDiagnostic(), and TRACE.

Referenced by DinverCore::AbstractForward::firstModel().

{
  TRACE;
  foreach(Parameter * p, _allParameters) {
    p->conditionDiagnostic();
  }
}

References checksum(), QGpCoreTools::endl(), DinverCore::Parameter::humanInfo(), QGpCoreTools::tr(), TRACE, and variableParameterCount().

Referenced by main(), ThreadLauncher::newThread(), DinverCore::Neighborhood::start(), and Forward::xml_polish().

{
  TRACE;
  App::stream() << tr( "\n---------------------- List of parameters and conditions\n\n" )
         << tr(" Parameterization checksum           =%1\n").arg(checksum())
         << tr(" Dimension of parameter space        =%1\n").arg(variableParameterCount()) << endl;
  foreach(Parameter * p, _allParameters) {
    p->humanInfo();
  }
}
bool DinverCore::RealSpace::isOk ( ) const [inline]

References DinverCore::Parameter::isOk().

Referenced by DinverCore::AbstractForward::firstModel(), and DinverCore::GridSnoop::optimization().

{
  foreach(Parameter * p, _allParameters) {
    if( !p->isOk()) return false;
  }
  return true;
}
bool DinverCore::RealSpace::isOkDebug ( ) const [inline]

References DinverCore::Parameter::isOkDebug().

Referenced by main(), DinverCore::Neighborhood::setThreadCount(), and DinverCore::ModelRepository::start().

{
  foreach(Parameter * p, _allParameters) {
    if( !p->isOkDebug()) return false;
  }
  return true;
}
{
  for(int i=0; i<_allParameters.count(); i++) {
    if( !_allParameters.at(i)->isOkDebugVerbose()) return false;
  }
  return true;
}
bool DinverCore::RealSpace::operator!= ( const RealSpace o) const [inline]
{return !operator==(o);}
bool DinverCore::RealSpace::operator== ( const RealSpace o) const

References TRACE, and variableParameterCount().

{
  TRACE;
  int nd=variableParameterCount();
  if(nd!=o.variableParameterCount()) return false;
  for(int i=0; i<nd; i++ ) {
    if(_variableParameters[i]->name()!=o._variableParameters[i]->name()) {
      return false;
    }
  }
  return true;
}
const Parameter* DinverCore::RealSpace::parameter ( int  index) const [inline]
Parameter* DinverCore::RealSpace::parameter ( int  index) [inline]
{return _allParameters[index];}

Return parameter with name, if not found return 0

References DinverCore::Parameter::name(), and TRACE.

{
  TRACE;
  foreach(Parameter * p, _allParameters) {
    if(p->name()==name) return p;
  }
  return 0;
}

Returns the total number of possible models

References TRACE, and variableParameterCount().

{
  TRACE;
  int ndVar=variableParameterCount();
  double n=1.0;
  for(int i=0;i<ndVar;i++) {
    n*=_variableParameters[i]->gridCount();
  }
  return n;
}

References QGpCoreTools::endl(), DinverCore::Parameter::name(), DinverCore::Parameter::realValue(), QGpCoreTools::tr(), TRACE, and DinverCore::Parameter::unit().

{
  TRACE;
  foreach(Parameter * p, _allParameters) {
    App::stream() << tr("    %1=%2 %3").arg(p->name()).arg(p->realValue()).arg(p->unit()) << endl;
  }
}
void DinverCore::RealSpace::setParameterNamePrefix ( const QString &  p) [inline]

Referenced by DinverDCCore::Param3DGroundModel::toParameters().

{_parameterNamePrefix=p;}

Fixed and variable parameters are added to space by addParam(). Fixed parameters have their min and max equal. This function defines the effective number of dimensions based on the number of variable parameters.

References QGpCoreTools::endl(), DinverCore::Parameter::getRectangularLimits(), DinverCore::Parameter::name(), DinverCore::Parameter::setMaximum(), DinverCore::Parameter::setMinimum(), DinverCore::Parameter::setRealValue(), QGpCoreTools::tr(), and TRACE.

Referenced by DinverCore::ParamExpressionContext::functionValue(), main(), ThreadLauncher::newThread(), DinverCore::Neighborhood::setThreadCount(), DinverCore::ModelRepository::start(), DinverCore::Neighborhood::start(), Forward::xml_polish(), and xml_polish().

{
  TRACE;
  _variableParameters.clear();
  double minp, maxp;
  foreach(Parameter * p, _allParameters) {
    p->getRectangularLimits(minp, maxp);
    if(minp==maxp) {
      p->setRealValue(minp);
    } else {
      _variableParameters.append(p);
      if(minp > maxp) {
        App::stream() << tr("%1: bad parameter range [%2,%3]").arg(p->name()).arg(minp).arg(maxp) << endl;
        App::stream() << tr("   ---> interval reversed") << endl;
        p->setMinimum(maxp);
        p->setMaximum(minp);
      }
    }
  }
}
const Parameter* DinverCore::RealSpace::variableParameter ( int  index) const [inline]
{return _variableParameters[index];}

Re-implement this function to offer XML restore (children and properties) support to your class.

From tag and map (with contains the attibute value) return a unique identifier under the format of a XMLMember. XMLMember is initialized with 3 types of contructors:

  • An integer: id number of a property
  • A XMLClass * : a child of this object identified by tag
  • Default constructor: error, unknow child or property

Map of attributes can be inspected in this way (can be achived also in xml_setProperty()):

    static const QString tmp("childrenName");
    XMLRestoreAttributeIterator it=map.find(tmp);
    if(it!=map.end()) {
      // found attribute "childrenName"
    }

If the map of attributes is not used:

    Q_UNUSED(attributes);
    if(tag=="x1") return XMLMember(0);
    else if(tag=="y1") return XMLMember(1);
    else if(tag=="x2") return XMLMember(2);
    else if(tag=="y2") return XMLMember(3);
    else return XMLMember(XMLMember::Unknown);

Arithmetic operations + and - apply to XMLMember to avoid confusion of property id numbers between inherited objects. Offset 3 corresponds to the number of properties defined in this object.

    if(tag=="anInteger") return XMLMember(0);
    else if(tag=="aString") return XMLMember(1);
    else if(tag=="aDouble") return XMLMember(2);
    return AbstractLine::xml_member(tag, attributes, context)+3;

For the arguments of this function use Macro XML_MEMBER_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

References TRACE.

{
  TRACE;
  Q_UNUSED(attributes)
  Q_UNUSED(context);
  if(tag=="Param") {
    Parameter * p=new Parameter;
    _allParameters.append(p);
    return XMLMember(p);
  }
  else return XMLMember(XMLMember::Unknown);
}
void DinverCore::RealSpace::xml_polish ( XML_POLISH_ARGS  ) [protected, virtual]

Reimplemented from QGpCoreTools::XMLClass.

References setVariableParameters(), and TRACE.

{
  TRACE;
  Q_UNUSED(context);
  setVariableParameters();
}
virtual const QString& DinverCore::RealSpace::xml_tagName ( ) const [inline, virtual]

Implements QGpCoreTools::XMLClass.

{return xmlRealSpaceTag;}

Reimplemented from QGpCoreTools::XMLClass.

References TRACE, and QGpCoreTools::XMLClass::xml_save().

{
  TRACE;
  foreach(Parameter * p, _allParameters) {
    p->xml_save(s, context);
  }
}

Member Data Documentation

const QString DinverCore::RealSpace::xmlRealSpaceTag = "RealSpace" [static]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines