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

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)
314{
315 string expanded;
316
317 if (arg[0] == '&') { //this is the char indicating an external argument file
318 expanded = getArgumentFromFile(arg);
319 } else
320 expanded = arg;
321
322 return expanded;
323}
string getArgumentFromFile(string file)
Definition: param.cc:327

References getArgumentFromFile().

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

+ Here is the caller graph for this function:

◆ getArg()

string Param::getArg ( )
inline

◆ getArgumentFromFile()

string Param::getArgumentFromFile ( string  file)
328{
329 StreamParser Parser(tstring::removeFirstCharOf(file, '&').c_str());
330 int dummyCnt;
331 string arg;
332
333 ifstream EXT(tstring::removeFirstCharOf(file, '&').c_str());
334 if(!EXT) fatal("External parameter file '%s' could not be found!\n", file.c_str());
335 while(Parser.readArguments(EXT, dummyCnt, arg));
336 EXT.close();
337
338 //add the external file name to the list
339 _externalFile.push_back(file);
340 _hasExternalFile = true;
341
342 return arg;
343}
vector< string > _externalFile
External argument file.
Definition: param.h:80
Read parameters from a text buffer.
Definition: paramsparser.h:120
static string removeFirstCharOf(const string &str, const char c)
Removes the first of a character found in a string.
Definition: tstring.h:319
void fatal(const char *str,...)
Definition: output.cc:96

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

References _bounds.

◆ getExternalFiles()

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

References _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.
358{
359 if( isMatrix() && _isSet ){
360
361 parse_matrix(mat);
362
363 } else
364 warning("param \"%s\" is not a matrix!\n",_name.c_str());
365}
void parse_matrix(TMatrix *mat)
Parses the matrix from the argument string.
Definition: param.cc:370
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:172
void warning(const char *str,...)
Definition: output.cc:58

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

Referenced by LCE_Selection_base::loadFileServices(), Metapop::loadFileServices(), LCE_FileServicesNotifier::loadFileServices(), TProtoBDMI::loadFileServices(), TProtoDeletMutations_bitstring::loadFileServices(), TProtoNeutralGenes::loadFileServices(), TProtoQuanti::loadFileServices(), 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(), TProtoQuanti::setDiallelicMutationModel(), TProtoQuanti::setDominanceParameters(), TProtoDeletMutations_bitstring::setEffectsFromInput(), LCE_Breed_base::setFecundity(), TTProtoWithMap::setGeneticMapParameters(), TTProtoWithMap::setNumLociPerChromosome(), LCE_StatServiceNotifier::setOccurence(), LCE_QuantiModifier::setParameters(), TProtoBDMI::setParameters(), TProtoQuanti::setParameters(), LCE_Breed_Wolbachia::setParameters(), and TProtoDispersal::setRandom().

◆ 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:89

References _arg, _hasMultipleArgs, and _multiArgs.

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

+ Here is the caller graph for this function:

◆ getName()

string Param::getName ( )
inline
137{return _name;}

References _name.

Referenced by ParamSet::add_param(), and ParamSet::print().

+ Here is the caller graph for this function:

◆ getOwner()

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

References _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:84

References _temporalArgs.

Referenced by LCE_StatServiceNotifier::setOccurence().

+ Here is the caller graph for this function:

◆ getType()

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

References _type.

◆ getUpdater()

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

References _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
348{
349 if( !(isMatrix() || _type == STR) && _isSet)
350 return atof(_arg.c_str());
351 else
352 return -1.0;
353}
@ STR
Definition: types.h:78

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

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

+ Here is the caller graph for this function:

◆ getVariableMatrix()

void Param::getVariableMatrix ( vector< vector< double > > *  mat)
440{
441 if( isMatrix() && _isSet ){
442
444
445 } else
446 warning("param \"%s\" is not a (variable) matrix!\n",_name.c_str());
447}
void parse_variable_matrix(vector< vector< double > > *mat)
Definition: param.cc:451

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

Referenced by TTProtoWithMap::setGeneticMapParameters(), LCE_Disperse_EvolDisp::setParameters(), and LCE_Disperse_base::setReducedMatricesBySex().

+ Here is the caller graph for this function:

◆ hasExternalFile()

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

References _hasExternalFile.

◆ hasMultipleArgs()

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

References _hasMultipleArgs.

Referenced by Metapop::setSourceParameters().

+ Here is the caller graph for this function:

◆ isBounded()

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

References _isBounded.

◆ isMatrix()

◆ isRequired()

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

References _isRequired.

◆ isSet()

◆ isTemporal()

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

References _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.
371{
372 std::vector< std::vector<double> > tmpMat;
373 std::istringstream IN;
374
375 IN.str(_arg);
376
377 unsigned int cols = 0;
378 double elmnt;
379 char c;
380
381
382 int rows = -1, pos = -1;
383 //we count the number of rows
384 do {
385 pos = _arg.find("{", pos + 1);
386 //message("pos %i, arg %s\n",pos,_arg.c_str());
387 rows++;
388 }while(pos != (int)string::npos);
389 //decrement by 1, the first doesn't count for a row
390 rows--;
391
392 for(int i = 0; i < rows; i++)
393 tmpMat.push_back( vector<double>() );
394
395 //remove the first enclosing bracket
396 IN>>c;
397 //then read the rows
398 for(unsigned int i = 0; i < tmpMat.size(); i++) {
399
400 cols = 0;
401
402 //read a row enclosed by {...}:
403 while(IN) {
404
405 //first character:
406 IN>>c;
407
408 if(c == '{' || c == ',' || c == ';') {
409 //read a row element:
410 IN>>elmnt;
411 cols++;
412 tmpMat[i].push_back(elmnt);
413
414 } else if(c == '}')
415 //go to next row
416 break;
417
418 }
419 }
420 //check for matrix coherence:
421 for(unsigned int i = 0; i < tmpMat.size(); i++) {
422 if(tmpMat[i].size() != cols)
423 fatal("%s: not same number of elements in all rows of matrix! (%i, cols %i)\n",_name.c_str(),tmpMat[i].size(),cols);
424 cols = tmpMat[i].size();
425 }
426
427 //copy to input TMatrix:
428 mat->reset(rows, cols);
429 for(int i = 0; i < rows; ++i)
430 for(unsigned int j = 0; j < cols; ++j)
431 mat->set(i,j,tmpMat[i][j]);
432
433
434 tmpMat.clear();
435}
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions.
Definition: tmatrix.h:116
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)
452{
453 // std::vector< std::vector<double> > tmpMat;
454 std::istringstream IN;
455
456 IN.str(_arg);
457
458 double elmnt;
459 char c;
460
461 //purge the input matrix:
462 mat->clear();
463
464 int rows = -1, pos = -1;
465 //we count the number of rows
466 do {
467 pos = _arg.find("{", pos + 1);
468 //message("pos %i, arg %s\n",pos,_arg.c_str());
469 rows++;
470 }while(pos != (int)string::npos);
471 //decrement by 1, the first doesn't count for a row
472 rows--;
473
474 for(int i = 0; i < rows; i++)
475 mat->push_back( vector<double>() );
476
477 //remove the first enclosing bracket
478 IN>>c;
479 //then read the rows
480 for(unsigned int i = 0; i < mat->size(); i++) {
481
482 //read a row enclosed by {...}:
483 while(IN) {
484
485 //first character:
486 IN>>c;
487
488 if(c == '{' || c == ',' || c == ';') {
489 //read a row element:
490 IN>>elmnt;
491 (*mat)[i].push_back(elmnt);
492
493 } else if(c == '}')
494 //go to next row
495 break;
496 }
497 }
498}

References _arg.

Referenced by getVariableMatrix().

+ Here is the caller graph for this function:

◆ parseAgeSpecArgument()

bool Param::parseAgeSpecArgument ( const string &  arg)
300{
301 return true;
302}

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.

199{
201 arg = tstring::removeEnclosingChar(arg, '(', ')');
202
203 vector< string > args = tstring::splitExcludeEnclosedDelimiters(arg);
204
205 _temporalArgs.clear();
206 _multiArgs.clear();
207
208// cout<< "Param::parseArgument: " << endl;
209
210
211 for(unsigned int i = 0; i < args.size(); ++i) {
212
213// cout << args[i] << endl;
214 // check for specifiers:
215 if(args[i][0] == '@') {
216 // temporal argument
217 if(args[i][1] == 'g')
218 {
219 if(!parseTemporalArgument(args[i])) return false;
220 }
221 // age-specific argument
222 else if(args[i][1] == 'a')
223 {
224 if(!parseAgeSpecArgument(args[i])) return false;
225 }
226
227 // error
228 else
229 {
230 return("parameter \"%s\" has unrecognized specifier in its argument string \"%s\".\n", _name.c_str(), args[i].c_str());
231 }
232
233 // multiple arguments?
234 } else { // (arg1, arg2, arg3, ...)
235 //values might still be in external files
236 _multiArgs.push_back( checkArgumentForExpansion(args[i]) );
237 }
238 }
239
240 if(_multiArgs.size() != 0)
241 _hasMultipleArgs = true;
242 else
243 _hasMultipleArgs = false;
244
245 // deal with temporal arguments:
246 if(_temporalArgs.size() != 0) {
247
248 //cout << "temporal arg values:\n";
249 // for(map< unsigned int , string >::iterator iter = _temporalArgs.begin();
250 // iter != _temporalArgs.end();
251 // iter++)
252 // cout << iter->first <<" "<< iter->second << endl;
253
254 if(_myUpdater != 0) {
255
256 if(_temporalArgs.find(0) != _temporalArgs.end()) {
257 _isTemporal = true;
258 //set the value for the first generation
259 arg = _temporalArgs.find(0)->second;
260 }
261 else {
262 return error("first generation argument value for temporal parameter \"%s\" is missing; no \"@g0\".\n", _name.c_str());
263 }
264
265 } else {
266 warning("trying to pass a temporal argument to a non temporal parameter (\"%s\").\n", _name.c_str());
267 _isTemporal = false;
268 _temporalArgs.clear();
269 }
270
271 } else _isTemporal = false;
272
273
274 return true;
275}
bool parseAgeSpecArgument(const string &arg)
Definition: param.cc:299
string checkArgumentForExpansion(string arg)
Definition: param.cc:313
bool parseTemporalArgument(const string &arg)
Definition: param.cc:279
static string removeEnclosingChar(const string &str, const char o, const char c, bool allowMissing=false)
Removes characters enclosing a string.
Definition: tstring.h:352
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:155
int error(const char *str,...)
Definition: output.cc:77

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

Referenced by set().

+ Here is the caller graph for this function:

◆ parseSubParamArgument()

bool Param::parseSubParamArgument ( const string &  arg)
307{
308 return true;
309}

◆ parseTemporalArgument()

bool Param::parseTemporalArgument ( const string &  arg)
280{
281 vector< string > args = tstring::split(arg, ' ', true);
282
283 if(args.size() != 2) {
284 error("Param::parseTemporalArgument:: missing argument value in \"%s %s\".\n", _name.c_str(), arg.c_str());
285 return false;
286 }
287
288 unsigned int gen = tstring::str2uint(tstring::removeFirstCharOf(tstring::removeFirstCharOf(args[0], '@'), 'g'));
289
290 args[1] = checkArgumentForExpansion(args[1]);
291
292 _temporalArgs[gen] = args[1]; //still need to process the argument string for replacements!!
293
294 return true;
295}
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:128
static unsigned int str2uint(const string &str)
Converts a string into an unsigned integer.
Definition: tstring.h:51

References _name, _temporalArgs, checkArgumentForExpansion(), error(), tstring::removeFirstCharOf(), 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;
80
81 _multiArgs.clear();
82 _hasMultipleArgs = false;
83
84 _externalFile.clear();
85 _hasExternalFile = false;
86
87 _temporalArgs.clear();
88 _isTemporal = false;
89
90 //also clear the paramUpdater to clear its list of parameters:
91 //if(_myUpdater) _myUpdater->reset(); // NO this leads to segfault at startup!!
92}

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

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

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.

118{_arg = value; _input_arg = value;}

References _arg, and _input_arg.

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
134{_setAtGeneration = generation;}

References _setAtGeneration.

◆ setBounds()

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

Sets the bounds.

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

References _bounds.

◆ setIsBounded()

void Param::setIsBounded ( bool  value)
inline

Sets the _isBounded flag.

124{_isBounded = value;}

References _isBounded.

◆ setIsRequired()

void Param::setIsRequired ( bool  value)
inline

Sets the isRequired flag.

126{_isRequired = value;}

References _isRequired.

◆ setIsSet()

void Param::setIsSet ( bool  value)
inline

Sets the _isSet flag.

122{_isSet = value;}

References _isSet.

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

+ Here is the caller graph for this function:

◆ setName()

void Param::setName ( string  value)
inline

Sets the parameter's name.

116{_name = value;}

References _name.

◆ setOwner()

void Param::setOwner ( SimComponent owner)
inline

Sets the pointer to owner.

130{_myOwner = owner;}

References _myOwner.

◆ setType()

void Param::setType ( param_t  value)
inline

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

120{_type = value;}

References _type.

◆ setUpdater()

void Param::setUpdater ( ParamUpdaterBase updater)
inline

Sets the pointer to the updater object.

132{_myUpdater = updater;}

References _myUpdater.

◆ show_up()

void Param::show_up ( )

Print state to stdout.

519{
520 message("%s = %s",_name.c_str(),_arg.c_str());
521 if(_isSet)
522 message(" (set at gen %i)\n",_setAtGeneration);
523 else
524 message(" (not set)\n");
525}
void message(const char *message,...)
Definition: output.cc:40

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.

503{
504 string error_msg;
505 if(_temporalArgs.find( generation ) != _temporalArgs.end()) {
506 if( !set( _temporalArgs[generation], error_msg ) ){
507 error("could not set \"%s\": %s", _name.c_str(), error_msg.c_str());
508 return false;
509 } else
510 return true;
511 } else
512 error("parameter \"%s\" does not have an argument value for generation %i.\n", _name.c_str(), generation);
513 return false;
514}
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 _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(), isMatrix(), parse_matrix(), parse_variable_matrix(), reset(), set(), setArg(), and show_up().

◆ _bounds

double Param::_bounds[2]
private

The argument value boundaries.

Referenced by getBound(), Param(), set(), and setBounds().

◆ _externalFile

vector< string > Param::_externalFile
private

External argument file.

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

◆ _hasExternalFile

bool Param::_hasExternalFile
private

◆ _hasMultipleArgs

bool Param::_hasMultipleArgs
private

◆ _input_arg

string Param::_input_arg
private

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

Referenced by getArg(), reset(), set(), and setArg().

◆ _isBounded

bool Param::_isBounded
private

Flag telling if the parameter has a bounded argument value.

Referenced by isBounded(), set(), and setIsBounded().

◆ _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.

Referenced by isRequired(), and setIsRequired().

◆ _isSet

bool Param::_isSet
private

Flag set once the parameter has recieved the right argument.

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

◆ _isTemporal

bool Param::_isTemporal
private

Flag telling if this parameter has temporal arguments.

Referenced by isTemporal(), 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.

Referenced by getOwner(), and setOwner().

◆ _myUpdater

ParamUpdaterBase* Param::_myUpdater
private

Pointer to an ParamUpdater object.

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

◆ _name

string Param::_name
private

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

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

◆ _setAtGeneration

unsigned int Param::_setAtGeneration
private

Generation at which the parameter has been set/updated.

Referenced by reset(), setAtGeneration(), 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 getType(), getValue(), isMatrix(), set(), and setType().


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

Generated for Nemo v2.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR