Nemo  2.4.1
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
Param Class Reference

This structure stores one parameter, its definition and its string argument. More...

#include <param.h>

+ Collaboration diagram for Param:

Public Member Functions

 Param (string &Name, param_t Type, bool mandatory, bool bounded, double low_bnd, double up_bnd, SimComponent *owner, ParamUpdaterBase *updater)
 Constructor. More...
 
 Param (const Param &P)
 Copy cstor, provides shallow copy of the parameter definition, do not copy arguments. More...
 
virtual ~Param ()
 
void reset ()
 Clears the _isSet flag and the argument string. More...
 
void setName (string value)
 Sets the parameter's name. More...
 
void setArg (string value)
 Sets the parameter's argument. More...
 
void setType (param_t value)
 Sets the parameter's type (see types.h) More...
 
void setIsSet (bool value)
 Sets the _isSet flag. More...
 
void setIsBounded (bool value)
 Sets the _isBounded flag. More...
 
void setIsRequired (bool value)
 Sets the isRequired flag. More...
 
void setBounds (double low_bnd, double up_bnd)
 Sets the bounds. More...
 
void setOwner (SimComponent *owner)
 Sets the pointer to owner. More...
 
void setUpdater (ParamUpdaterBase *updater)
 Sets the pointer to the updater object. More...
 
void setAtGeneration (unsigned int generation)
 
string getName ()
 
string getArg ()
 
string getInputArg ()
 Returns the original, untouched input argument string (for logging). More...
 
param_t getType ()
 
bool isSet ()
 
bool isBounded ()
 
bool isRequired ()
 
bool isTemporal ()
 
bool hasMultipleArgs ()
 
bool hasPreservedMacro ()
 
void clearPreservedMacro ()
 
bool hasExternalFile ()
 
double getBound (unsigned int i)
 
SimComponentgetOwner ()
 
ParamUpdaterBasegetUpdater ()
 
deque< unsigned int > getUpdatingDates ()
 
deque< string > getTemporalArgs ()
 
vector< string > getMultiArgs ()
 
vector< string > getExternalFiles ()
 
bool set (string arg, string &errmsg)
 Sets the _isSet flag to true and _arg to arg if the arg is of the right type and whithin the bounds. More...
 
bool update (unsigned int generation)
 Updates the parameter value at a given generation during the simulation. More...
 
double getValue ()
 Returns the argument value according to its type. More...
 
bool isMatrix ()
 Checks if the argument is of matrix type. More...
 
void getMatrix (TMatrix *mat)
 Sets the matrix from the argument string if the parameter is set and of matrix type. More...
 
void getVariableMatrix (vector< vector< double > > *mat)
 
void parse_matrix (TMatrix *mat)
 Parses the matrix from the argument string. More...
 
void parse_variable_matrix (vector< vector< double > > *mat)
 
bool parseArgument (string &arg)
 
bool parseTemporalArgument (const string &arg)
 
bool parseAgeSpecArgument (const string &arg)
 
bool parseSubParamArgument (const string &arg)
 
string checkArgumentForExpansion (string arg)
 
string getArgumentFromFile (string file)
 
void show_up ()
 Print state to stdout. More...
 

Private Attributes

string _name
 The name of the parameter as read in the init file. More...
 
string _arg
 The argument string, set by the ParamsParser upon initialization. More...
 
string _input_arg
 The input argument string, kept untouched as a backup for logging. More...
 
param_t _type
 The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h). More...
 
bool _isSet
 Flag set once the parameter has recieved the right argument. More...
 
bool _isBounded
 Flag telling if the parameter has a bounded argument value. More...
 
bool _isRequired
 Flag telling if this parameter is mandatory. More...
 
double _bounds [2]
 The argument value boundaries. More...
 
unsigned int _setAtGeneration
 Generation at which the parameter has been set/updated. More...
 
SimComponent_myOwner
 Pointer to the component that declared this parameter. More...
 
ParamUpdaterBase_myUpdater
 Pointer to an ParamUpdater object. More...
 
vector< string > _externalFile
 External argument file. More...
 
bool _hasExternalFile
 
map< unsigned int, string > _temporalArgs
 The temporal arguments. More...
 
bool _isTemporal
 Flag telling if this parameter has temporal arguments. More...
 
vector< string > _multiArgs
 Multiple arguments. More...
 
bool _hasMultipleArgs
 
bool _hasPreservedMacro
 Flag telling if this parameter's argument holds a macro preserved by the P() macro, whose expansion is deferred until after the random seed has been set. More...
 

Detailed Description

This structure stores one parameter, its definition and its string argument.

Parameters are aggregated into a ParamSet.

Constructor & Destructor Documentation

◆ Param() [1/2]

Param::Param ( string &  Name,
param_t  Type,
bool  mandatory,
bool  bounded,
double  low_bnd,
double  up_bnd,
SimComponent owner,
ParamUpdaterBase updater 
)

Constructor.

Parameters
Namethe name of the parameter as read in the init file
Typethe type of the parameter argument (see types.h), used to convert the argument string into a value
mandatoryspecifies whether this parameter is mandatory for the ParamSet owning it
boundedspecifies whether the values this parameter can take are bounded
low_bndthe lower bound of the parameter value
up_bndthe upper bound
ownerpointer to the SimComponents that owns this parameter
updaterthe param updater object used to update the parameter's state during a simulation
44 : _name(Name),_arg(""),_type(Type),_isSet(0),_isBounded(bounded),_isRequired(mandatory),
47 
48 {
49  _bounds[0] = low_bnd;
50  _bounds[1] = up_bnd;
51 }
bool _hasMultipleArgs
Definition: param.h:89
unsigned int _setAtGeneration
Generation at which the parameter has been set/updated.
Definition: param.h:72
bool _hasPreservedMacro
Flag telling if this parameter's argument holds a macro preserved by the P() macro,...
Definition: param.h:95
bool _isSet
Flag set once the parameter has recieved the right argument.
Definition: param.h:63
param_t _type
The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h).
Definition: param.h:61
bool _isRequired
Flag telling if this parameter is mandatory.
Definition: param.h:68
SimComponent * _myOwner
Pointer to the component that declared this parameter.
Definition: param.h:74
bool _isBounded
Flag telling if the parameter has a bounded argument value.
Definition: param.h:65
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:57
double _bounds[2]
The argument value boundaries.
Definition: param.h:70
ParamUpdaterBase * _myUpdater
Pointer to an ParamUpdater object.
Definition: param.h:76
bool _hasExternalFile
Definition: param.h:80
string _name
The name of the parameter as read in the init file.
Definition: param.h:55
bool _isTemporal
Flag telling if this parameter has temporal arguments.
Definition: param.h:85

References _bounds.

◆ Param() [2/2]

Param::Param ( const Param P)

Copy cstor, provides shallow copy of the parameter definition, do not copy arguments.

References _bounds.

◆ ~Param()

Param::~Param ( )
virtual
68 {
69  if(_myUpdater) delete _myUpdater;
70 }

References _myUpdater.

Member Function Documentation

◆ checkArgumentForExpansion()

string Param::checkArgumentForExpansion ( string  arg)
354 {
355  string expanded;
356 
357  if (arg[0] == '&') { //this is the char indicating an external argument file
358  expanded = getArgumentFromFile(arg);
359  } else
360  expanded = arg;
361 
362  return expanded;
363 }
string getArgumentFromFile(string file)
Definition: param.cc:367

References getArgumentFromFile().

Referenced by parseArgument(), parseTemporalArgument(), and set().

+ Here is the caller graph for this function:

◆ clearPreservedMacro()

void Param::clearPreservedMacro ( )
inline
153 {_hasPreservedMacro = false;}

◆ getArg()

◆ getArgumentFromFile()

string Param::getArgumentFromFile ( string  file)
368 {
369  StreamParser Parser(tstring::removeFirstCharOf(file, '&').c_str());
370  int dummyCnt;
371  string arg;
372 
373  ifstream EXT(tstring::removeFirstCharOf(file, '&').c_str());
374  if(!EXT) fatal("External parameter file '%s' could not be found!\n", file.c_str());
375  while(Parser.readArguments(EXT, dummyCnt, arg));
376  EXT.close();
377 
378  //add the external file name to the list
379  _externalFile.push_back(file);
380  _hasExternalFile = true;
381 
382  return arg;
383 }
vector< string > _externalFile
External argument file.
Definition: param.h:79
Read parameters from a text buffer.
Definition: paramsparser.h:146
static string removeFirstCharOf(const string &str, const char c)
Removes the first of a character found in a string.
Definition: tstring.h:322
void fatal(const char *str,...)
Definition: output.cc:99

References _externalFile, _hasExternalFile, fatal(), StreamParser::readArguments(), and tstring::removeFirstCharOf().

Referenced by checkArgumentForExpansion().

+ Here is the caller graph for this function:

◆ getBound()

double Param::getBound ( unsigned int  i)
inline
155 {return _bounds[i];}

◆ getExternalFiles()

vector< string > Param::getExternalFiles ( )
inline
165 {return _externalFile;}

◆ getInputArg()

string Param::getInputArg ( )
inline

Returns the original, untouched input argument string (for logging).

145 {return _input_arg;}
string _input_arg
The input argument string, kept untouched as a backup for logging.
Definition: param.h:59

Referenced by Metapop::loadPopFromBinarySource(), and ParamSet::print().

+ Here is the caller graph for this function:

◆ getMatrix()

void Param::getMatrix ( TMatrix mat)

Sets the matrix from the argument string if the parameter is set and of matrix type.

Passes the param 'mat' to function Param::parse_matrix.

Parameters
mata TMatrix ptr, mat dimensions and values will be reset to the values read in the init file.
398 {
399  if( isMatrix() && _isSet ){
400 
401  parse_matrix(mat);
402 
403  } else
404  warning("param \"%s\" is not a matrix!\n",_name.c_str());
405 }
void parse_matrix(TMatrix *mat)
Parses the matrix from the argument string.
Definition: param.cc:410
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:181
void warning(const char *str,...)
Definition: output.cc:57

References _isSet, _name, isMatrix(), parse_matrix(), and warning().

Referenced by LCE_Selection_base::loadFileServices(), Metapop::loadFileServices(), TProtoBDMI::loadFileServices(), TProtoDeletMutations_bitstring::loadFileServices(), TProtoNeutralGenes::loadFileServices(), TProtoQuanti::loadFileServices(), LCE_PhenotypeExpression::set_g_value_matrix(), LCE_Patch_Extinction::set_matrix_param(), LCE_Selection_base::set_param_rate_of_change(), LCE_Selection_base::set_sel_model(), LCE_Selection_base::set_std_rate_of_change(), TProtoQuanti::setContinuousMutationModel_full_pleio(), TProtoQuanti::setDiallelicMutationModel(), TProtoQuanti::setDominanceParameters(), TProtoDeletMutations_bitstring::setEffectsFromInput(), TProtoQuanti::setEpistasisParameters(), LCE_Breed_base::setFecundity(), TTProtoWithMap::setGeneticMapParameters(), LCE_FileServicesNotifier::setGenotyperParameters(), TProtoQuanti::setHeritabilityParams(), TProtoQuanti::setInitialValuesParams(), TProtoQuanti::setMutationCorrelation(), TProtoQuanti::setMutationModel_no_pleio(), TProtoQuanti::setMutationModel_var_pleio(), TProtoQuanti::setMutationSigmaFromQuantiMutationVariance(), TProtoQuanti::setMutationSigmaFromQuantiMutationVariance_no_pleio(), TTProtoWithMap::setNumLociPerChromosome(), LCE_StatServiceNotifier::setOccurence(), LCE_Breed_Disperse::setParameters(), LCE_QuantiModifier::setParameters(), TProtoBDMI::setParameters(), LCE_Breed_Wolbachia::setParameters(), TProtoDispersal::setRandom(), LCE_FileServicesNotifier::setSamplingParameters(), LCE_Selection_base::setSelectionOffset(), and LCE_Selection_base::setSelectTraitMapping().

◆ getMultiArgs()

vector< string > Param::getMultiArgs ( )
123 {
124  if (!_hasMultipleArgs) {
125  _multiArgs.clear();
126  _multiArgs.push_back(_arg);
127  }
128  return _multiArgs;
129 }
vector< string > _multiArgs
Multiple arguments.
Definition: param.h:88

References _arg, _hasMultipleArgs, and _multiArgs.

Referenced by LCE_Selection_base::set_sel_model(), LCE_FileServicesNotifier::setGenotyperParameters(), LCE_Selection_base::setParameters(), and Metapop::setSourceParameters().

+ Here is the caller graph for this function:

◆ getName()

string Param::getName ( )
inline

◆ getOwner()

SimComponent* Param::getOwner ( )
inline
156 {return _myOwner;}

◆ getTemporalArgs()

deque< string > Param::getTemporalArgs ( )
110 {
111  deque< string > args;
112 
113  for(map< unsigned int, string >::iterator tmp_it = _temporalArgs.begin();
114  tmp_it != _temporalArgs.end(); tmp_it++)
115  args.push_back( tmp_it->second );
116 
117  return args;
118 }
map< unsigned int, string > _temporalArgs
The temporal arguments.
Definition: param.h:83

References _temporalArgs.

Referenced by LCE_StatServiceNotifier::setOccurence().

+ Here is the caller graph for this function:

◆ getType()

param_t Param::getType ( )
inline
146 {return _type;}

◆ getUpdater()

ParamUpdaterBase* Param::getUpdater ( )
inline
157 {return _myUpdater;}

◆ getUpdatingDates()

deque< unsigned int > Param::getUpdatingDates ( )
97 {
98  deque< unsigned int > dates;
99 
100  for(map< unsigned int, string >::iterator tmp_it = _temporalArgs.begin();
101  tmp_it != _temporalArgs.end(); tmp_it++)
102  dates.push_back( tmp_it->first );
103 
104  return dates;
105 }

References _temporalArgs.

Referenced by LCE_StatServiceNotifier::setOccurence().

+ Here is the caller graph for this function:

◆ getValue()

double Param::getValue ( )

Returns the argument value according to its type.

Returns
-1 if the parameter is not set or not of a the right type
388 {
389  if( !(isMatrix() || _type == STR) && _isSet)
390  return atof(_arg.c_str());
391  else
392  return -1.0;
393 }
@ STR
Definition: types.h:77

References _arg, _isSet, _type, isMatrix(), and STR.

Referenced by LCE_Selection_base::loadFileServices(), Metapop::loadFileServices(), TProtoBDMI::loadFileServices(), TProtoDeletMutations_bitstring::loadFileServices(), TProtoNeutralGenes::loadFileServices(), TProtoQuanti::loadFileServices(), LCE_PhenotypeExpression::set_g_value_matrix(), LCE_Patch_Extinction::set_matrix_param(), LCE_FileServicesNotifier::setGenotyperParameters(), TProtoDispersal::setNonRandom(), and LCE_StatServiceNotifier::setOccurence().

+ Here is the caller graph for this function:

◆ getVariableMatrix()

void Param::getVariableMatrix ( vector< vector< double > > *  mat)
482 {
483  if( isMatrix() && _isSet ){
484 
486 
487  } else
488  warning("param \"%s\" is not a (variable) matrix!\n",_name.c_str());
489 }
void parse_variable_matrix(vector< vector< double > > *mat)
Definition: param.cc:493

References _isSet, _name, isMatrix(), parse_variable_matrix(), and warning().

Referenced by TProtoQuanti::readMatrixFromQuantiMutationMatrix(), TProtoQuanti::setEpistasisParameters(), TTProtoWithMap::setGeneticMapParameters(), LCE_Disperse_EvolDisp::setParameters(), LCE_PhenotypeExpression::setParameters(), and LCE_Disperse_base::setReducedMatricesBySex().

+ Here is the caller graph for this function:

◆ hasExternalFile()

bool Param::hasExternalFile ( )
inline
154 {return _hasExternalFile;}

◆ hasMultipleArgs()

bool Param::hasMultipleArgs ( )
inline
151 {return _hasMultipleArgs;}

Referenced by Metapop::setSourceParameters().

+ Here is the caller graph for this function:

◆ hasPreservedMacro()

bool Param::hasPreservedMacro ( )
inline
152 {return _hasPreservedMacro;}

◆ isBounded()

bool Param::isBounded ( )
inline
148 {return _isBounded;}

◆ isMatrix()

◆ isRequired()

bool Param::isRequired ( )
inline
149 {return _isRequired;}

◆ isSet()

◆ isTemporal()

bool Param::isTemporal ( )
inline
150 {return _isTemporal;}

Referenced by LCE_StatServiceNotifier::setOccurence().

+ Here is the caller graph for this function:

◆ parse_matrix()

void Param::parse_matrix ( TMatrix mat)

Parses the matrix from the argument string.

Parameters
mata TMatrix ptr, mat dimensions and values will be reset to the values read in the init file.
411 {
412  std::vector< std::vector<double> > tmpMat;
413  std::istringstream IN;
414 
415  IN.str(_arg);
416 
417  unsigned int cols = 0;
418  double elmnt;
419  char c;
420 
421 
422  int rows = -1, pos = -1;
423  //we count the number of rows
424  do {
425  pos = _arg.find("{", pos + 1);
426  //message("pos %i, arg %s\n",pos,_arg.c_str());
427  rows++;
428  }while(pos != (int)string::npos);
429  //decrement by 1, the first doesn't count for a row
430  rows--;
431 
432  for(int i = 0; i < rows; i++)
433  tmpMat.push_back( vector<double>() );
434 
435  //remove the first enclosing bracket
436  IN>>c;
437  //then read the rows
438  for(unsigned int i = 0; i < tmpMat.size(); i++) {
439 
440  cols = 0;
441 
442  //read a row enclosed by {...}:
443  while(IN) {
444 
445  //first character:
446  IN>>c;
447 
448  if(c == '{' || c == ',' || c == ';') {
449  //read a row element:
450  IN>>elmnt;
451  cols++;
452  tmpMat[i].push_back(elmnt);
453 
454  } else if(c == '}')
455  //go to next row
456  break;
457  else if(isdigit(c) || c == '.' || c == '-' || c == '+')
458  fatal("param \"%s\": matrix values must be separated by commas, not spaces.\n", _name.c_str());
459 
460  }
461  }
462  //check for matrix coherence:
463  for(unsigned int i = 0; i < tmpMat.size(); i++) {
464  if(tmpMat[i].size() != cols)
465  fatal("%s: not same number of elements in all rows of matrix! (%i, cols %i)\n",_name.c_str(),tmpMat[i].size(),cols);
466  cols = tmpMat[i].size();
467  }
468 
469  //copy to input TMatrix:
470  mat->reset(rows, cols);
471  for(int i = 0; i < rows; ++i)
472  for(unsigned int j = 0; j < cols; ++j)
473  mat->set(i,j,tmpMat[i][j]);
474 
475 
476  tmpMat.clear();
477 }
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions and all elements to 0.
Definition: tmatrix.h:160
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:102

References _arg, _name, fatal(), TMatrix::reset(), and TMatrix::set().

Referenced by getMatrix().

+ Here is the caller graph for this function:

◆ parse_variable_matrix()

void Param::parse_variable_matrix ( vector< vector< double > > *  mat)
494 {
495  // std::vector< std::vector<double> > tmpMat;
496  std::istringstream IN;
497 
498  IN.str(_arg);
499 
500  double elmnt;
501  char c;
502 
503  //purge the input matrix:
504  mat->clear();
505 
506  int rows = -1, pos = -1;
507  //we count the number of rows
508  do {
509  pos = _arg.find("{", pos + 1);
510  //message("pos %i, arg %s\n",pos,_arg.c_str());
511  rows++;
512  }while(pos != (int)string::npos);
513  //decrement by 1, the first doesn't count for a row
514  rows--;
515 
516  for(int i = 0; i < rows; i++)
517  mat->push_back( vector<double>() );
518 
519  //remove the first enclosing bracket
520  IN>>c;
521  //then read the rows
522  for(unsigned int i = 0; i < mat->size(); i++) {
523 
524  //read a row enclosed by {...}:
525  while(IN) {
526 
527  //first character:
528  IN>>c;
529 
530  if(c == '{' || c == ',' || c == ';') {
531  //peek ahead to handle empty rows, e.g. {} in {{}{1, 2}}
532  char next;
533  IN >> next;
534  if(next == '}') {
535  break; //empty row or end of row
536  }
537  IN.putback(next);
538  //read a row element:
539  IN>>elmnt;
540  (*mat)[i].push_back(elmnt);
541 
542  } else if(c == '}')
543  //go to next row
544  break;
545  }
546  }
547 }

References _arg.

Referenced by getVariableMatrix().

+ Here is the caller graph for this function:

◆ parseAgeSpecArgument()

bool Param::parseAgeSpecArgument ( const string &  arg)
340 {
341  return true;
342 }

Referenced by parseArgument().

+ Here is the caller graph for this function:

◆ parseArgument()

bool Param::parseArgument ( string &  arg)

Parse an argument string enclosed in '( )', might hold temporal or multiple values. Might also hold a macro to expand.

224 {
227  // do some string clean-up:
228  arg = tstring::replaceChar(arg, '\t', ' ');
229  arg = tstring::replaceChar(arg, '\n', ' ');
230  // remove the enclosing parentheses:
231  arg = tstring::removeEnclosingChar(arg, '(', ')');
232 
233  vector< string > args = tstring::splitExcludeEnclosedDelimiters(arg); //split with default delimiter = ','
234 
235  _temporalArgs.clear();
236  _multiArgs.clear();
237 
238 // cout<< "Param::parseArgument: " << endl;
239 //
240 // cout<<" argument string: "<<arg<<endl;
241 
242  for(unsigned int i = 0; i < args.size(); ++i) {
243 
244  // removing any leading white spaces (' ', '\t')
245  args[i] = tstring::removeLeadingWhiteSpace(args[i]);
246 
247 // cout << args[i] << endl;
248 
249  // check for specifiers:
250  if(args[i][0] == '@') {
251 
252  // temporal argument
253  if(args[i][1] == 'g')
254  {
255  if(!parseTemporalArgument(args[i])) return false;
256  }
257 
258  // age-specific argument
259  else if(args[i][1] == 'a')
260  {
261  if(!parseAgeSpecArgument(args[i])) return false;
262  }
263 
264  // error
265  else
266  {
267  return error("parameter \"%s\" has unrecognized specifier in its argument string \"%s\".\n", _name.c_str(), args[i].c_str());
268  }
269 
270  // multiple arguments?
271  } else { // (arg1, arg2, arg3, ...)
272  //values might still be in external files
273  _multiArgs.push_back( checkArgumentForExpansion(args[i]) );
274  }
275  }
276 
277  if(_multiArgs.size() != 0)
278  _hasMultipleArgs = true;
279  else
280  _hasMultipleArgs = false;
281 
282 
283  // deal with temporal arguments:
284  if(_temporalArgs.size() != 0) {
285 
286 // cout << "temporal arg values:\n";
287 // for(map< unsigned int , string >::iterator iter = _temporalArgs.begin();
288 // iter != _temporalArgs.end();
289 // iter++)
290 // cout << iter->first <<" "<< iter->second << endl;
291 
292  if(_myUpdater != 0) {
293 
294  if(_temporalArgs.find(0) != _temporalArgs.end()) {
295  _isTemporal = true;
296  //set the value for the first generation
297  arg = _temporalArgs.find(0)->second;
298  }
299  else {
300  return error("first generation argument value for temporal parameter \"%s\" is missing; no \"@g0\".\n", _name.c_str());
301  }
302 
303  } else {
304  warning("trying to pass a temporal argument to a non temporal parameter (\"%s\").\n", _name.c_str());
305  _isTemporal = false;
306  _temporalArgs.clear();
307  }
308 
309  } else _isTemporal = false;
310 
311 
312  return true;
313 }
bool parseAgeSpecArgument(const string &arg)
Definition: param.cc:339
string checkArgumentForExpansion(string arg)
Definition: param.cc:353
bool parseTemporalArgument(const string &arg)
Definition: param.cc:317
static string removeEnclosingChar(const string &str, const char o, const char c, bool allowMissing=false)
Removes characters enclosing a string.
Definition: tstring.h:355
static vector< string > splitExcludeEnclosedDelimiters(const string &str, const char delim=',', const string &encloser="([{\"")
Splits a string into substrings (tokens) delimited by a single character.
Definition: tstring.h:154
static string removeLeadingWhiteSpace(const string &str)
Definition: tstring.h:383
static string replaceChar(const string &str, const char target, const char replacement)
Definition: tstring.h:393
int error(const char *str,...)
Definition: output.cc:78

References _hasMultipleArgs, _isTemporal, _multiArgs, _myUpdater, _name, _temporalArgs, checkArgumentForExpansion(), error(), parseAgeSpecArgument(), parseTemporalArgument(), tstring::removeEnclosingChar(), tstring::removeLeadingWhiteSpace(), tstring::replaceChar(), tstring::splitExcludeEnclosedDelimiters(), and warning().

Referenced by set().

+ Here is the caller graph for this function:

◆ parseSubParamArgument()

bool Param::parseSubParamArgument ( const string &  arg)
347 {
348  return true;
349 }

◆ parseTemporalArgument()

bool Param::parseTemporalArgument ( const string &  arg)
318 {
319  vector< string > args = tstring::split(arg, ' ', true);
320 
321  if(args.size() != 2) {
322  error("Param::parseTemporalArgument:: missing argument value in \"%s %s\".\n", _name.c_str(), arg.c_str());
323  return false;
324  }
325 
326  unsigned int gen = tstring::str2uint(tstring::removeFirstCharOf(tstring::removeFirstCharOf(args[0], '@'), 'g'));
327 
328  // remove extra white space characters introduced between delimiter and argument value:
329  args[1] = tstring::removeLeadingWhiteSpace(args[1]);
330  args[1] = checkArgumentForExpansion(args[1]);
331 
332  _temporalArgs[gen] = args[1];
333 
334  return true;
335 }
static vector< string > split(const string &str, const char delim, bool splitOnce=false)
splits a string into substrings (tokens) delimited by a single character.
Definition: tstring.h:127
static unsigned int str2uint(const string &str)
Converts a string into an unsigned integer.
Definition: tstring.h:50

References _name, _temporalArgs, checkArgumentForExpansion(), error(), tstring::removeFirstCharOf(), tstring::removeLeadingWhiteSpace(), tstring::split(), and tstring::str2uint().

Referenced by parseArgument().

+ Here is the caller graph for this function:

◆ reset()

void Param::reset ( )

Clears the _isSet flag and the argument string.

75 {
76  _input_arg = "",
77  _arg = "";
78  _isSet = 0;
79  _setAtGeneration = 0;
80 
81  _multiArgs.clear();
82  _hasMultipleArgs = false;
83 
84  _externalFile.clear();
85  _hasExternalFile = false;
86 
87  _temporalArgs.clear();
88  _isTemporal = false;
89 
90  _hasPreservedMacro = false;
91 
92 }

References _arg, _externalFile, _hasExternalFile, _hasMultipleArgs, _hasPreservedMacro, _input_arg, _isSet, _isTemporal, _multiArgs, _setAtGeneration, and _temporalArgs.

◆ set()

bool Param::set ( string  arg,
string &  errmsg 
)

Sets the _isSet flag to true and _arg to arg if the arg is of the right type and whithin the bounds.

Called at simulation setup (i.e. generation 0). For parameter update during the simulation, check the Param::update member function.

!a matrix may also be specified!! in that case, we don't check values here

134 {
135 // cout << "Param::set ("<<arg<<")\n";
136 
137  _hasPreservedMacro = false;
138 
139  // A leading MACRO_PRESERVE_TAG marks an argument whose macro(s) were preserved by the P()
140  // macro (see ParamsParser::parseMacroFunctionBlock). Their expansion is deferred until the
141  // random seed has been set, because stochastic macros (rexp, rnorm, ...) draw from the RNG.
142  // Record the deferral, store the still-un-expanded argument, and skip parsing/validation now:
143  // SimRunner::expandPreservedMacros will expand it and call set() again with the resolved value.
144  if(arg[0] == MACRO_PRESERVE_TAG) {
145  arg.erase(0, 1); // strip the sentinel
146  _input_arg = arg; // keep the un-expanded macro string (e.g. "{{c(q(rexp(...)),0)}}")
147  _arg = arg;
148  _hasPreservedMacro = true;
149  _isSet = true; // the parameter is specified; it will be resolved after seeding
150  return true;
151  }
152 
153  _input_arg = arg; //backup the input parameter argument string
154 
155  //remove any remaining leading white-space character
156  while(isspace(arg[0])) {
157  arg.erase(0);
158  }
159 
160  if(arg.size() == 0){
161  errmsg = "argument is empty";
162  return false;
163  }
164  _externalFile.clear(); //ext. file names will be pushed here
165  //check if argument is in an external file, and read it from that file
166  if (arg[0] == '&') {
167  //read the argument from an external file, file name is stored within the call.
168  string expanded = checkArgumentForExpansion(arg);
169  arg = expanded;
170  }
171 
172  if( arg[0] == '(' ) {
173  if( !parseArgument( arg ) ) {
174  errmsg = "could not parse the argument string";
175  return false;
176  }
177  }
178 
179  //integer or decimal:
180  if(_type == INT || _type == DBL) {
182  if(arg[0] != '{') {
183 
184  if(!tstring::isanumber(arg)) {
185  errmsg = "argument is not a number";
186  return false;
187  }
188 
189  double val = tstring::str2dble(arg);
190 
191  if(_isBounded && (val < _bounds[0] || val > _bounds[1]) ){
192  errmsg = "argument is out of bounds";
193  return false;
194  }
195  }
196 
197  //boolean:
198  } else if(_type == BOOL) {
199 
200  if( !tstring::isanumber(arg) ){
201  errmsg = "argument is not a boolean";
202  return false;
203  }
204 
205  } else if(_type == MAT) {
206  if(arg[0] != '{'){
207  errmsg = "argument is not a matrix";
208  return false;
209  }
210  }
211  // else if(_type == P || _type == S): no conditions to check
212 
213  _isSet = (_type == BOOL && tstring::str2int(arg) == 0 ? false : true);
214 
215  //now we set the value of the parameter to the value of the argument read in the file
216  _arg = arg;
217 
218  return true;
219 }
bool parseArgument(string &arg)
Definition: param.cc:223
static double str2dble(const string &str)
Converts a string into a double.
Definition: tstring.h:83
static int str2int(const string &str)
Converts a string into an integer.
Definition: tstring.h:72
static bool isanumber(const string &str)
Check whether the string is a number.
Definition: tstring.h:409
#define MACRO_PRESERVE_TAG
Sentinel char prepended to a parameter value whose macro(s) were preserved by the P() macro and must ...
Definition: paramsparser.h:43
@ DBL
Definition: types.h:77
@ BOOL
Definition: types.h:77
@ INT
Definition: types.h:77

References _arg, _bounds, _externalFile, _hasPreservedMacro, _input_arg, _isBounded, _isSet, _type, BOOL, checkArgumentForExpansion(), DBL, INT, tstring::isanumber(), MACRO_PRESERVE_TAG, MAT, parseArgument(), tstring::str2dble(), and tstring::str2int().

Referenced by update().

+ Here is the caller graph for this function:

◆ setArg()

void Param::setArg ( string  value)
inline

Sets the parameter's argument.

123 {_arg = value; _input_arg = value;}

Referenced by TTProtoWithMap::recordRandomMap(), TProtoDispersal::setParameters(), TTProtoWithMap::setRecombinationMapRandom(), and TProtoDeletMutations_bitstring::write_effects_to_parameter().

+ Here is the caller graph for this function:

◆ setAtGeneration()

void Param::setAtGeneration ( unsigned int  generation)
inline
139 {_setAtGeneration = generation;}

◆ setBounds()

void Param::setBounds ( double  low_bnd,
double  up_bnd 
)
inline

Sets the bounds.

133 {_bounds[0]=low_bnd; _bounds[1]=up_bnd;}

◆ setIsBounded()

void Param::setIsBounded ( bool  value)
inline

Sets the _isBounded flag.

129 {_isBounded = value;}

◆ setIsRequired()

void Param::setIsRequired ( bool  value)
inline

Sets the isRequired flag.

131 {_isRequired = value;}

◆ setIsSet()

void Param::setIsSet ( bool  value)
inline

◆ setName()

void Param::setName ( string  value)
inline

Sets the parameter's name.

121 {_name = value;}

◆ setOwner()

void Param::setOwner ( SimComponent owner)
inline

Sets the pointer to owner.

135 {_myOwner = owner;}

◆ setType()

void Param::setType ( param_t  value)
inline

Sets the parameter's type (see types.h)

125 {_type = value;}

◆ setUpdater()

void Param::setUpdater ( ParamUpdaterBase updater)
inline

Sets the pointer to the updater object.

137 {_myUpdater = updater;}

◆ show_up()

void Param::show_up ( )

Print state to stdout.

574 {
575  message("%s = %s",_name.c_str(),_arg.c_str());
576  if(_isSet)
577  message(" (set at gen %i)\n",_setAtGeneration);
578  else
579  message(" (not set)\n");
580 }
void message(const char *message,...)
Definition: output.cc:39

References _arg, _isSet, _name, _setAtGeneration, and message().

◆ update()

bool Param::update ( unsigned int  generation)

Updates the parameter value at a given generation during the simulation.

552 {
553  string error_msg;
554  if(_temporalArgs.find( generation ) != _temporalArgs.end()) {
555  //_input_arg must remain the original input string throughout the simulation
556  //(it is the untouched backup used for logging); set() overwrites it, so we
557  //save it before the update and restore it after — only _arg should change.
558  string original_input = _input_arg;
559  bool ok = set( _temporalArgs[generation], error_msg );
560  _input_arg = original_input;
561  if( !ok ){
562  error("could not set \"%s\": %s", _name.c_str(), error_msg.c_str());
563  return false;
564  } else
565  return true;
566  } else
567  error("parameter \"%s\" does not have an argument value for generation %i.\n", _name.c_str(), generation);
568  return false;
569 }
bool set(string arg, string &errmsg)
Sets the _isSet flag to true and _arg to arg if the arg is of the right type and whithin the bounds.
Definition: param.cc:133

References _input_arg, _name, _temporalArgs, error(), and set().

Referenced by ParamSet::update_param().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _arg

string Param::_arg
private

The argument string, set by the ParamsParser upon initialization.

Referenced by getMultiArgs(), getValue(), parse_matrix(), parse_variable_matrix(), reset(), set(), and show_up().

◆ _bounds

double Param::_bounds[2]
private

The argument value boundaries.

Referenced by Param(), and set().

◆ _externalFile

vector< string > Param::_externalFile
private

External argument file.

Referenced by getArgumentFromFile(), reset(), and set().

◆ _hasExternalFile

bool Param::_hasExternalFile
private

Referenced by getArgumentFromFile(), and reset().

◆ _hasMultipleArgs

bool Param::_hasMultipleArgs
private

Referenced by getMultiArgs(), parseArgument(), and reset().

◆ _hasPreservedMacro

bool Param::_hasPreservedMacro
private

Flag telling if this parameter's argument holds a macro preserved by the P() macro, whose expansion is deferred until after the random seed has been set.

While set, the stored argument (_input_arg/_arg) is the un-expanded macro string; it is expanded and the parameter re-set by SimRunner::expandPreservedMacros.

Referenced by reset(), and set().

◆ _input_arg

string Param::_input_arg
private

The input argument string, kept untouched as a backup for logging.

Referenced by reset(), set(), and update().

◆ _isBounded

bool Param::_isBounded
private

Flag telling if the parameter has a bounded argument value.

Referenced by set().

◆ _isRequired

bool Param::_isRequired
private

Flag telling if this parameter is mandatory.

A SimComponent with a mandatory parameter in the 'unset' state will not be selected to be part of a running simulation component.

◆ _isSet

bool Param::_isSet
private

Flag set once the parameter has recieved the right argument.

Referenced by getMatrix(), getValue(), getVariableMatrix(), reset(), set(), and show_up().

◆ _isTemporal

bool Param::_isTemporal
private

Flag telling if this parameter has temporal arguments.

Referenced by parseArgument(), and reset().

◆ _multiArgs

vector< string > Param::_multiArgs
private

Multiple arguments.

Referenced by getMultiArgs(), parseArgument(), and reset().

◆ _myOwner

SimComponent* Param::_myOwner
private

Pointer to the component that declared this parameter.

◆ _myUpdater

ParamUpdaterBase* Param::_myUpdater
private

Pointer to an ParamUpdater object.

Referenced by parseArgument(), and ~Param().

◆ _name

string Param::_name
private

The name of the parameter as read in the init file.

Referenced by getMatrix(), getVariableMatrix(), parse_matrix(), parseArgument(), parseTemporalArgument(), show_up(), and update().

◆ _setAtGeneration

unsigned int Param::_setAtGeneration
private

Generation at which the parameter has been set/updated.

Referenced by reset(), and show_up().

◆ _temporalArgs

map< unsigned int, string > Param::_temporalArgs
private

◆ _type

param_t Param::_type
private

The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h).

Referenced by getValue(), and set().


The documentation for this class was generated from the following files:

Generated for Nemo v2.4.1 by  doxygen 1.9.1

Catalogued on GSR