Nemo  2.4.0
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 ()
 
param_t getType ()
 
bool isSet ()
 
bool isBounded ()
 
bool isRequired ()
 
bool isTemporal ()
 
bool hasMultipleArgs ()
 
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
 

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

References _myUpdater.

Member Function Documentation

◆ checkArgumentForExpansion()

string Param::checkArgumentForExpansion ( string  arg)
334 {
335  string expanded;
336 
337  if (arg[0] == '&') { //this is the char indicating an external argument file
338  expanded = getArgumentFromFile(arg);
339  } else
340  expanded = arg;
341 
342  return expanded;
343 }
string getArgumentFromFile(string file)
Definition: param.cc:347

References getArgumentFromFile().

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

+ Here is the caller graph for this function:

◆ getArg()

◆ getArgumentFromFile()

string Param::getArgumentFromFile ( string  file)
348 {
349  StreamParser Parser(tstring::removeFirstCharOf(file, '&').c_str());
350  int dummyCnt;
351  string arg;
352 
353  ifstream EXT(tstring::removeFirstCharOf(file, '&').c_str());
354  if(!EXT) fatal("External parameter file '%s' could not be found!\n", file.c_str());
355  while(Parser.readArguments(EXT, dummyCnt, arg));
356  EXT.close();
357 
358  //add the external file name to the list
359  _externalFile.push_back(file);
360  _hasExternalFile = true;
361 
362  return arg;
363 }
vector< string > _externalFile
External argument file.
Definition: param.h:79
Read parameters from a text buffer.
Definition: paramsparser.h:119
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
145 {return _bounds[i];}

◆ getExternalFiles()

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

◆ 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.
378 {
379  if( isMatrix() && _isSet ){
380 
381  parse_matrix(mat);
382 
383  } else
384  warning("param \"%s\" is not a matrix!\n",_name.c_str());
385 }
void parse_matrix(TMatrix *mat)
Parses the matrix from the argument string.
Definition: param.cc:390
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:171
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 ( )
120 {
121  if (!_hasMultipleArgs) {
122  _multiArgs.clear();
123  _multiArgs.push_back(_arg);
124  }
125  return _multiArgs;
126 }
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
146 {return _myOwner;}

◆ getTemporalArgs()

deque< string > Param::getTemporalArgs ( )
107 {
108  deque< string > args;
109 
110  for(map< unsigned int, string >::iterator tmp_it = _temporalArgs.begin();
111  tmp_it != _temporalArgs.end(); tmp_it++)
112  args.push_back( tmp_it->second );
113 
114  return args;
115 }
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
138 {return _type;}

◆ getUpdater()

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

◆ getUpdatingDates()

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

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
368 {
369  if( !(isMatrix() || _type == STR) && _isSet)
370  return atof(_arg.c_str());
371  else
372  return -1.0;
373 }
@ 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)
462 {
463  if( isMatrix() && _isSet ){
464 
466 
467  } else
468  warning("param \"%s\" is not a (variable) matrix!\n",_name.c_str());
469 }
void parse_variable_matrix(vector< vector< double > > *mat)
Definition: param.cc:473

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

◆ hasMultipleArgs()

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

Referenced by Metapop::setSourceParameters().

+ Here is the caller graph for this function:

◆ isBounded()

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

◆ isMatrix()

◆ isRequired()

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

◆ isSet()

◆ isTemporal()

bool Param::isTemporal ( )
inline
142 {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.
391 {
392  std::vector< std::vector<double> > tmpMat;
393  std::istringstream IN;
394 
395  IN.str(_arg);
396 
397  unsigned int cols = 0;
398  double elmnt;
399  char c;
400 
401 
402  int rows = -1, pos = -1;
403  //we count the number of rows
404  do {
405  pos = _arg.find("{", pos + 1);
406  //message("pos %i, arg %s\n",pos,_arg.c_str());
407  rows++;
408  }while(pos != (int)string::npos);
409  //decrement by 1, the first doesn't count for a row
410  rows--;
411 
412  for(int i = 0; i < rows; i++)
413  tmpMat.push_back( vector<double>() );
414 
415  //remove the first enclosing bracket
416  IN>>c;
417  //then read the rows
418  for(unsigned int i = 0; i < tmpMat.size(); i++) {
419 
420  cols = 0;
421 
422  //read a row enclosed by {...}:
423  while(IN) {
424 
425  //first character:
426  IN>>c;
427 
428  if(c == '{' || c == ',' || c == ';') {
429  //read a row element:
430  IN>>elmnt;
431  cols++;
432  tmpMat[i].push_back(elmnt);
433 
434  } else if(c == '}')
435  //go to next row
436  break;
437  else if(isdigit(c) || c == '.' || c == '-' || c == '+')
438  fatal("param \"%s\": matrix values must be separated by commas, not spaces.\n", _name.c_str());
439 
440  }
441  }
442  //check for matrix coherence:
443  for(unsigned int i = 0; i < tmpMat.size(); i++) {
444  if(tmpMat[i].size() != cols)
445  fatal("%s: not same number of elements in all rows of matrix! (%i, cols %i)\n",_name.c_str(),tmpMat[i].size(),cols);
446  cols = tmpMat[i].size();
447  }
448 
449  //copy to input TMatrix:
450  mat->reset(rows, cols);
451  for(int i = 0; i < rows; ++i)
452  for(unsigned int j = 0; j < cols; ++j)
453  mat->set(i,j,tmpMat[i][j]);
454 
455 
456  tmpMat.clear();
457 }
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)
474 {
475  // std::vector< std::vector<double> > tmpMat;
476  std::istringstream IN;
477 
478  IN.str(_arg);
479 
480  double elmnt;
481  char c;
482 
483  //purge the input matrix:
484  mat->clear();
485 
486  int rows = -1, pos = -1;
487  //we count the number of rows
488  do {
489  pos = _arg.find("{", pos + 1);
490  //message("pos %i, arg %s\n",pos,_arg.c_str());
491  rows++;
492  }while(pos != (int)string::npos);
493  //decrement by 1, the first doesn't count for a row
494  rows--;
495 
496  for(int i = 0; i < rows; i++)
497  mat->push_back( vector<double>() );
498 
499  //remove the first enclosing bracket
500  IN>>c;
501  //then read the rows
502  for(unsigned int i = 0; i < mat->size(); i++) {
503 
504  //read a row enclosed by {...}:
505  while(IN) {
506 
507  //first character:
508  IN>>c;
509 
510  if(c == '{' || c == ',' || c == ';') {
511  //peek ahead to handle empty rows, e.g. {} in {{}{1, 2}}
512  char next;
513  IN >> next;
514  if(next == '}') {
515  break; //empty row or end of row
516  }
517  IN.putback(next);
518  //read a row element:
519  IN>>elmnt;
520  (*mat)[i].push_back(elmnt);
521 
522  } else if(c == '}')
523  //go to next row
524  break;
525  }
526  }
527 }

References _arg.

Referenced by getVariableMatrix().

+ Here is the caller graph for this function:

◆ parseAgeSpecArgument()

bool Param::parseAgeSpecArgument ( const string &  arg)
320 {
321  return true;
322 }

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.

205 {
207  // do some string clean-up:
208  arg = tstring::replaceChar(arg, '\t', ' ');
209  arg = tstring::replaceChar(arg, '\n', ' ');
210  // remove the enclosing parentheses:
211  arg = tstring::removeEnclosingChar(arg, '(', ')');
212 
213  vector< string > args = tstring::splitExcludeEnclosedDelimiters(arg); //split with default delimiter = ','
214 
215  _temporalArgs.clear();
216  _multiArgs.clear();
217 
218 // cout<< "Param::parseArgument: " << endl;
219 //
220 // cout<<" argument string: "<<arg<<endl;
221 
222  for(unsigned int i = 0; i < args.size(); ++i) {
223 
224  // removing any leading white spaces (' ', '\t')
225  args[i] = tstring::removeLeadingWhiteSpace(args[i]);
226 
227 // cout << args[i] << endl;
228 
229  // check for specifiers:
230  if(args[i][0] == '@') {
231 
232  // temporal argument
233  if(args[i][1] == 'g')
234  {
235  if(!parseTemporalArgument(args[i])) return false;
236  }
237 
238  // age-specific argument
239  else if(args[i][1] == 'a')
240  {
241  if(!parseAgeSpecArgument(args[i])) return false;
242  }
243 
244  // error
245  else
246  {
247  return error("parameter \"%s\" has unrecognized specifier in its argument string \"%s\".\n", _name.c_str(), args[i].c_str());
248  }
249 
250  // multiple arguments?
251  } else { // (arg1, arg2, arg3, ...)
252  //values might still be in external files
253  _multiArgs.push_back( checkArgumentForExpansion(args[i]) );
254  }
255  }
256 
257  if(_multiArgs.size() != 0)
258  _hasMultipleArgs = true;
259  else
260  _hasMultipleArgs = false;
261 
262 
263  // deal with temporal arguments:
264  if(_temporalArgs.size() != 0) {
265 
266 // cout << "temporal arg values:\n";
267 // for(map< unsigned int , string >::iterator iter = _temporalArgs.begin();
268 // iter != _temporalArgs.end();
269 // iter++)
270 // cout << iter->first <<" "<< iter->second << endl;
271 
272  if(_myUpdater != 0) {
273 
274  if(_temporalArgs.find(0) != _temporalArgs.end()) {
275  _isTemporal = true;
276  //set the value for the first generation
277  arg = _temporalArgs.find(0)->second;
278  }
279  else {
280  return error("first generation argument value for temporal parameter \"%s\" is missing; no \"@g0\".\n", _name.c_str());
281  }
282 
283  } else {
284  warning("trying to pass a temporal argument to a non temporal parameter (\"%s\").\n", _name.c_str());
285  _isTemporal = false;
286  _temporalArgs.clear();
287  }
288 
289  } else _isTemporal = false;
290 
291 
292  return true;
293 }
bool parseAgeSpecArgument(const string &arg)
Definition: param.cc:319
string checkArgumentForExpansion(string arg)
Definition: param.cc:333
bool parseTemporalArgument(const string &arg)
Definition: param.cc:297
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)
327 {
328  return true;
329 }

◆ parseTemporalArgument()

bool Param::parseTemporalArgument ( const string &  arg)
298 {
299  vector< string > args = tstring::split(arg, ' ', true);
300 
301  if(args.size() != 2) {
302  error("Param::parseTemporalArgument:: missing argument value in \"%s %s\".\n", _name.c_str(), arg.c_str());
303  return false;
304  }
305 
306  unsigned int gen = tstring::str2uint(tstring::removeFirstCharOf(tstring::removeFirstCharOf(args[0], '@'), 'g'));
307 
308  // remove extra white space characters introduced between delimiter and argument value:
309  args[1] = tstring::removeLeadingWhiteSpace(args[1]);
310  args[1] = checkArgumentForExpansion(args[1]);
311 
312  _temporalArgs[gen] = args[1];
313 
314  return true;
315 }
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.

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 }

References _arg, _externalFile, _hasExternalFile, _hasMultipleArgs, _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

131 {
132 // cout << "Param::set ("<<arg<<")\n";
133 
134  _input_arg = arg; //backup the input parameter argument string
135 
136  //remove any remaining leading white-space character
137  while(isspace(arg[0])) {
138  arg.erase(0);
139  }
140 
141  if(arg.size() == 0){
142  errmsg = "argument is empty";
143  return false;
144  }
145  _externalFile.clear(); //ext. file names will be pushed here
146  //check if argument is in an external file, and read it from that file
147  if (arg[0] == '&') {
148  //read the argument from an external file, file name is stored within the call.
149  string expanded = checkArgumentForExpansion(arg);
150  arg = expanded;
151  }
152 
153  if( arg[0] == '(' ) {
154  if( !parseArgument( arg ) ) {
155  errmsg = "could not parse the argument string";
156  return false;
157  }
158  }
159 
160  //integer or decimal:
161  if(_type == INT || _type == DBL) {
163  if(arg[0] != '{') {
164 
165  if(!tstring::isanumber(arg)) {
166  errmsg = "argument is not a number";
167  return false;
168  }
169 
170  double val = tstring::str2dble(arg);
171 
172  if(_isBounded && (val < _bounds[0] || val > _bounds[1]) ){
173  errmsg = "argument is out of bounds";
174  return false;
175  }
176  }
177 
178  //boolean:
179  } else if(_type == BOOL) {
180 
181  if( !tstring::isanumber(arg) ){
182  errmsg = "argument is not a boolean";
183  return false;
184  }
185 
186  } else if(_type == MAT) {
187  if(arg[0] != '{'){
188  errmsg = "argument is not a matrix";
189  return false;
190  }
191  }
192  // else if(_type == P || _type == S): no conditions to check
193 
194  _isSet = (_type == BOOL && tstring::str2int(arg) == 0 ? false : true);
195 
196  //now we set the value of the parameter to the value of the argument read in the file
197  _arg = arg;
198 
199  return true;
200 }
bool parseArgument(string &arg)
Definition: param.cc:204
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
@ DBL
Definition: types.h:77
@ BOOL
Definition: types.h:77
@ INT
Definition: types.h:77

References _arg, _bounds, _externalFile, _input_arg, _isBounded, _isSet, _type, BOOL, checkArgumentForExpansion(), DBL, INT, tstring::isanumber(), 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.

117 {_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
133 {_setAtGeneration = generation;}

◆ setBounds()

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

Sets the bounds.

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

◆ setIsBounded()

void Param::setIsBounded ( bool  value)
inline

Sets the _isBounded flag.

123 {_isBounded = value;}

◆ setIsRequired()

void Param::setIsRequired ( bool  value)
inline

Sets the isRequired flag.

125 {_isRequired = value;}

◆ setIsSet()

void Param::setIsSet ( bool  value)
inline

◆ setName()

void Param::setName ( string  value)
inline

Sets the parameter's name.

115 {_name = value;}

◆ setOwner()

void Param::setOwner ( SimComponent owner)
inline

Sets the pointer to owner.

129 {_myOwner = owner;}

◆ setType()

void Param::setType ( param_t  value)
inline

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

119 {_type = value;}

◆ setUpdater()

void Param::setUpdater ( ParamUpdaterBase updater)
inline

Sets the pointer to the updater object.

131 {_myUpdater = updater;}

◆ show_up()

void Param::show_up ( )

Print state to stdout.

548 {
549  message("%s = %s",_name.c_str(),_arg.c_str());
550  if(_isSet)
551  message(" (set at gen %i)\n",_setAtGeneration);
552  else
553  message(" (not set)\n");
554 }
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.

532 {
533  string error_msg;
534  if(_temporalArgs.find( generation ) != _temporalArgs.end()) {
535  if( !set( _temporalArgs[generation], error_msg ) ){
536  error("could not set \"%s\": %s", _name.c_str(), error_msg.c_str());
537  return false;
538  } else
539  return true;
540  } else
541  error("parameter \"%s\" does not have an argument value for generation %i.\n", _name.c_str(), generation);
542  return false;
543 }
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:130

References _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().

◆ _input_arg

string Param::_input_arg
private

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

Referenced by reset(), and set().

◆ _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.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR