Nemo  2.4.2
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
43 : _name(Name),_arg(""),_type(Type),_isSet(0),_isBounded(bounded),_isRequired(mandatory),
46 
47 {
48  _bounds[0] = low_bnd;
49  _bounds[1] = up_bnd;
50 }
bool _hasMultipleArgs
Definition: param.h:88
unsigned int _setAtGeneration
Generation at which the parameter has been set/updated.
Definition: param.h:71
bool _hasPreservedMacro
Flag telling if this parameter's argument holds a macro preserved by the P() macro,...
Definition: param.h:94
bool _isSet
Flag set once the parameter has recieved the right argument.
Definition: param.h:62
param_t _type
The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h).
Definition: param.h:60
bool _isRequired
Flag telling if this parameter is mandatory.
Definition: param.h:67
SimComponent * _myOwner
Pointer to the component that declared this parameter.
Definition: param.h:73
bool _isBounded
Flag telling if the parameter has a bounded argument value.
Definition: param.h:64
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:56
double _bounds[2]
The argument value boundaries.
Definition: param.h:69
ParamUpdaterBase * _myUpdater
Pointer to an ParamUpdater object.
Definition: param.h:75
bool _hasExternalFile
Definition: param.h:79
string _name
The name of the parameter as read in the init file.
Definition: param.h:54
bool _isTemporal
Flag telling if this parameter has temporal arguments.
Definition: param.h:84

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
67 {
68  if(_myUpdater) delete _myUpdater;
69 }

References _myUpdater.

Member Function Documentation

◆ checkArgumentForExpansion()

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

References getArgumentFromFile().

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

+ Here is the caller graph for this function:

◆ clearPreservedMacro()

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

◆ getArg()

◆ getArgumentFromFile()

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

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
154 {return _bounds[i];}

◆ getExternalFiles()

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

◆ getInputArg()

string Param::getInputArg ( )
inline

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

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

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.
397 {
398  if( isMatrix() && _isSet ){
399 
400  parse_matrix(mat);
401 
402  } else
403  warning("param \"%s\" is not a matrix!\n",_name.c_str());
404 }
void parse_matrix(TMatrix *mat)
Parses the matrix from the argument string.
Definition: param.cc:409
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:180
void warning(const char *str,...)
Definition: output.cc:56

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 ( )
122 {
123  if (!_hasMultipleArgs) {
124  _multiArgs.clear();
125  _multiArgs.push_back(_arg);
126  }
127  return _multiArgs;
128 }
vector< string > _multiArgs
Multiple arguments.
Definition: param.h:87

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
155 {return _myOwner;}

◆ getTemporalArgs()

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

References _temporalArgs.

Referenced by LCE_StatServiceNotifier::setOccurence().

+ Here is the caller graph for this function:

◆ getType()

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

◆ getUpdater()

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

◆ getUpdatingDates()

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

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
387 {
388  if( !(isMatrix() || _type == STR) && _isSet)
389  return atof(_arg.c_str());
390  else
391  return -1.0;
392 }
@ STR
Definition: types.h:76

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)
481 {
482  if( isMatrix() && _isSet ){
483 
485 
486  } else
487  warning("param \"%s\" is not a (variable) matrix!\n",_name.c_str());
488 }
void parse_variable_matrix(vector< vector< double > > *mat)
Definition: param.cc:492

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
153 {return _hasExternalFile;}

◆ hasMultipleArgs()

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

Referenced by Metapop::setSourceParameters().

+ Here is the caller graph for this function:

◆ hasPreservedMacro()

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

◆ isBounded()

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

◆ isMatrix()

◆ isRequired()

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

◆ isSet()

◆ isTemporal()

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

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

References _arg.

Referenced by getVariableMatrix().

+ Here is the caller graph for this function:

◆ parseAgeSpecArgument()

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

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.

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

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)
346 {
347  return true;
348 }

◆ parseTemporalArgument()

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

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.

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

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

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

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.

122 {_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
138 {_setAtGeneration = generation;}

◆ setBounds()

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

Sets the bounds.

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

◆ setIsBounded()

void Param::setIsBounded ( bool  value)
inline

Sets the _isBounded flag.

128 {_isBounded = value;}

◆ setIsRequired()

void Param::setIsRequired ( bool  value)
inline

Sets the isRequired flag.

130 {_isRequired = value;}

◆ setIsSet()

void Param::setIsSet ( bool  value)
inline

◆ setName()

void Param::setName ( string  value)
inline

Sets the parameter's name.

120 {_name = value;}

◆ setOwner()

void Param::setOwner ( SimComponent owner)
inline

Sets the pointer to owner.

134 {_myOwner = owner;}

◆ setType()

void Param::setType ( param_t  value)
inline

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

124 {_type = value;}

◆ setUpdater()

void Param::setUpdater ( ParamUpdaterBase updater)
inline

Sets the pointer to the updater object.

136 {_myUpdater = updater;}

◆ show_up()

void Param::show_up ( )

Print state to stdout.

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

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.

551 {
552  string error_msg;
553  if(_temporalArgs.find( generation ) != _temporalArgs.end()) {
554  //_input_arg must remain the original input string throughout the simulation
555  //(it is the untouched backup used for logging); set() overwrites it, so we
556  //save it before the update and restore it after — only _arg should change.
557  string original_input = _input_arg;
558  bool ok = set( _temporalArgs[generation], error_msg );
559  _input_arg = original_input;
560  if( !ok ){
561  error("could not set \"%s\": %s", _name.c_str(), error_msg.c_str());
562  return false;
563  } else
564  return true;
565  } else
566  error("parameter \"%s\" does not have an argument value for generation %i.\n", _name.c_str(), generation);
567  return false;
568 }
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:132

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.2 by  doxygen 1.9.1

Catalogued on GSR