|
Nemo
2.2.0
|
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. | |
| Param (const Param &P) | |
| Copy cstor, provides shallow copy of the parameter definition, do not copy arguments. | |
| virtual | ~Param () |
| void | reset () |
| Clears the _isSet flag and the argument string. | |
| void | setName (string value) |
| Sets the parameter's name. | |
| void | setArg (string value) |
| Sets the parameter's argument. | |
| void | setType (param_t value) |
| Sets the parameter's type (see types.h) | |
| void | setIsSet (bool value) |
| Sets the _isSet flag. | |
| void | setIsBounded (bool value) |
| Sets the _isBounded flag. | |
| void | setBounds (double low_bnd, double up_bnd) |
| Sets the bounds. | |
| void | setOwner (SimComponent *owner) |
| Sets the pointer to owner. | |
| void | setUpdater (ParamUpdaterBase *updater) |
| Sets the pointer to the updater object. | |
| void | setAtGeneration (unsigned int generation) |
| string | getName () |
| string | getArg () |
| param_t | getType () |
| bool | isSet () |
| bool | isBounded () |
| bool | isRequired () |
| double | getBound (unsigned int i) |
| SimComponent * | getOwner () |
| ParamUpdaterBase * | getUpdater () |
| deque< unsigned int > | getUpdatingDates () |
| deque< string > | getTemporalArgs () |
| 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. | |
| bool | update (unsigned int generation) |
| Updates the parameter value at a given generation during the simulation. | |
| double | getValue () |
| Returns the argument value according to its type. | |
| bool | isMatrix () |
| Checks if the argument is of matrix type. | |
| void | getMatrix (TMatrix *mat) |
| Sets the matrix from the argument string if the parameter is set and of matrix type. | |
| void | parse_matrix (TMatrix *mat) |
| Parses the matrix from the argument string. | |
| bool | parseArgument (string &arg) |
| bool | parseTemporalArgument (const string &arg) |
| bool | parseAgeSpecArgument (const string &arg) |
| bool | parseSubParamArgument (const string &arg) |
| void | show_up () |
| Print state to stdout. | |
Private Attributes | |
| string | _name |
| The name of the parameter as read in the init file. | |
| string | _arg |
| The argument string, set by the ParamsParser upon initialization. | |
| param_t | _type |
| The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h). | |
| bool | _isSet |
| Flag set once the parameter has recieved the right argument. | |
| bool | _isBounded |
| Flag telling if the parameter has a bounded argument value. | |
| bool | _isRequired |
| Flag telling if this parameter is mandatory. | |
| double | _bounds [2] |
| The argument value boundaries. | |
| unsigned int | _setAtGeneration |
| Generation at which the parameter has been set/updated. | |
| SimComponent * | _myOwner |
| Pointer to the component that declared this parameter. | |
| ParamUpdaterBase * | _myUpdater |
| Pointer to an ParamUpdater object. | |
| map< string, Param * > | _subParams |
| map< unsigned int, string > | _temporalArgs |
| The temporal arguments. | |
| bool | _isTemporal |
This structure stores one parameter, its definition and its string argument.
Parameters are aggregated into a ParamSet.
| Param::Param | ( | string & | Name, |
| param_t | Type, | ||
| bool | mandatory, | ||
| bool | bounded, | ||
| double | low_bnd, | ||
| double | up_bnd, | ||
| SimComponent * | owner, | ||
| ParamUpdaterBase * | updater | ||
| ) |
Constructor.
| Name | the name of the parameter as read in the init file |
| Type | the type of the parameter argument (see types.h), used to convert the argument string into a value |
| mandatory | specifies whether this parameter is mandatory for the ParamSet owning it |
| bounded | specifies whether the values this parameter can take are bounded |
| low_bnd | the lower bound of the parameter value |
| up_bnd | the upper bound |
| owner | pointer to the SimComponents that owns this parameter |
| updater | the param updater object used to update the parameter's state during a simulation |
Definition at line 41 of file param.cc.
References _bounds.
: _name(Name),_arg(""),_type(Type),_isSet(0),_isBounded(bounded),_isRequired(mandatory),_setAtGeneration(0), _myOwner(owner), _myUpdater(updater) { _bounds[0] = low_bnd; _bounds[1] = up_bnd; }
| Param::Param | ( | const Param & | P | ) |
Copy cstor, provides shallow copy of the parameter definition, do not copy arguments.
Definition at line 53 of file param.cc.
References _bounds.
: _name(P._name),_arg(P._arg),_type(P._type),_isSet(P._isSet),_isBounded(P._isBounded), _isRequired(P._isRequired),_setAtGeneration(P._setAtGeneration),_myOwner(P._myOwner), _myUpdater(0) { _bounds[0] = P._bounds[0]; _bounds[1] = P._bounds[1]; }
| Param::~Param | ( | ) | [virtual] |
Definition at line 64 of file param.cc.
References _myUpdater.
{
if(_myUpdater) delete _myUpdater;
}
| string Param::getArg | ( | ) | [inline] |
Definition at line 125 of file param.h.
Referenced by LCE_Breed_base::setFecundity(), and BinaryDataSaver::setParameters().
{return _arg;}
| double Param::getBound | ( | unsigned int | i | ) | [inline] |
| 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.
| mat | a TMatrix ptr, mat dimensions and values will be reset to the values read in the init file. |
Definition at line 257 of file param.cc.
References _isSet, _name, isMatrix(), parse_matrix(), and warning().
Referenced by LCE_Selection_base::set_sel_model().
{
if( isMatrix() && _isSet ){
parse_matrix(mat);
} else
warning("param \"%s\" is not a matrix!\n",_name.c_str());
}
| string Param::getName | ( | ) | [inline] |
| SimComponent* Param::getOwner | ( | ) | [inline] |
| deque< string > Param::getTemporalArgs | ( | ) |
Definition at line 93 of file param.cc.
References _temporalArgs.
{
deque< string > args;
for(map< unsigned int, string >::iterator tmp_it = _temporalArgs.begin();
tmp_it != _temporalArgs.end(); tmp_it++)
args.push_back( tmp_it->second );
return args;
}
| ParamUpdaterBase* Param::getUpdater | ( | ) | [inline] |
Definition at line 132 of file param.h.
{return _myUpdater;}
| deque< unsigned int > Param::getUpdatingDates | ( | ) |
Definition at line 80 of file param.cc.
References _temporalArgs.
{
deque< unsigned int > dates;
for(map< unsigned int, string >::iterator tmp_it = _temporalArgs.begin();
tmp_it != _temporalArgs.end(); tmp_it++)
dates.push_back( tmp_it->first );
return dates;
}
| double Param::getValue | ( | ) |
Returns the argument value according to its type.
Definition at line 247 of file param.cc.
References _arg, _isSet, _type, isMatrix(), and STR.
Referenced by TProtoNeutralGenes::loadFileServices(), and TProtoDeletMutations_bitstring::loadFileServices().
| bool Param::isBounded | ( | ) | [inline] |
Definition at line 128 of file param.h.
{return _isBounded;}
| bool Param::isMatrix | ( | ) | [inline] |
Checks if the argument is of matrix type.
Definition at line 151 of file param.h.
References MAT.
Referenced by getMatrix(), and getValue().
| bool Param::isRequired | ( | ) | [inline] |
Definition at line 129 of file param.h.
{return _isRequired;}
| bool Param::isSet | ( | ) | [inline] |
Definition at line 127 of file param.h.
Referenced by LCE_Resize::execute(), TProtoNeutralGenes::loadFileServices(), TProtoDeletMutations_bitstring::loadFileServices(), LCE_Selection_base::set_sel_model(), LCE_Breed_base::setFecundity(), LCE_Breed_base::setMatingSystem(), BinaryDataSaver::setParameters(), TProtoNeutralGenes::setParameters(), TProtoDeletMutations_bitstring::setParameters(), LCE_Breed_Wolbachia::setParameters(), LCE_Selection_base::setSelectionMatrix(), TProtoDeletMutations_bitstring::setSelectionParameters(), and LCE_Resize::updateParameters().
{return _isSet;}
| void Param::parse_matrix | ( | TMatrix * | mat | ) |
Parses the matrix from the argument string.
| mat | a TMatrix ptr, mat dimensions and values will be reset to the values read in the init file. |
Definition at line 270 of file param.cc.
References _arg, _name, fatal(), TMatrix::reset(), and TMatrix::set().
Referenced by getMatrix().
{
std::vector< std::vector<double>* > tmpMat;
std::istringstream IN;
IN.str(_arg);
unsigned int cols = 0;
double elmnt;
char c;
int rows = -1, pos = -1;
//we count the number of rows
do {
pos = _arg.find("{", pos + 1);
//message("pos %i, arg %s\n",pos,_arg.c_str());
rows++;
}while(pos != (int)string::npos);
//decrement by 1, the first doesn't count for a row
rows--;
for(int i = 0; i < rows; i++)
tmpMat.push_back( new vector<double>);
//remove the first enclosing bracket
IN>>c;
//then read the rows
for(unsigned int i = 0; i < tmpMat.size(); i++) {
cols = 0;
//read a row enclosed by {...}:
while(IN) {
//first character:
IN>>c;
if(c == '{' || c == ',' || c == ';') {
//read a row element:
IN>>elmnt;
cols++;
tmpMat[i]->push_back(elmnt);
} else if(c == '}')
//go to next row
break;
}
}
//check for matrix coherence:
for(unsigned int i = 0; i < tmpMat.size(); i++) {
if(tmpMat[i]->size() != cols)
fatal("%s: not same number of elements in all rows of matrix! (%i, cols %i)\n",_name.c_str(),tmpMat[i]->size(),cols);
cols = tmpMat[i]->size();
}
//copy to input TMatrix:
mat->reset(rows, cols);
for(int i = 0; i < rows; ++i)
for(unsigned int j = 0; j < cols; ++j)
mat->set(i,j,(*tmpMat[i])[j]);
}
| bool Param::parseAgeSpecArgument | ( | const string & | arg | ) |
| bool Param::parseArgument | ( | string & | arg | ) |
Definition at line 155 of file param.cc.
References _isTemporal, _myUpdater, _name, _temporalArgs, error(), parseAgeSpecArgument(), parseSubParamArgument(), parseTemporalArgument(), tstring::removeEnclosingChar(), tstring::splitExcludeEnclosedDelimiters(), and warning().
Referenced by set().
{
arg = tstring::removeEnclosingChar(arg, '(', ')');
vector< string > args = tstring::splitExcludeEnclosedDelimiters(arg);
_temporalArgs.clear();
// _ageSpecArgs.clear();
// _subParams.clear();
// cout<< "Param::parseArgument:" << endl;
for(unsigned int i = 0; i < args.size(); ++i) {
//cout << args[i] << endl;
if(args[i][0] == '@') {
if(args[i][1] == 'g') if(!parseTemporalArgument(args[i])) return false;
else if(args[i][1] == 'a') if(!parseAgeSpecArgument(args[i])) return false;
else {
error("parameter \"%s\"'s argument string \"%s\" has unrecognized specifier.\n", _name.c_str(), args[i].c_str());
return false;
}
} else
parseSubParamArgument(args[i]);
}
if(_temporalArgs.size() != 0) {
//cout << "temporal arg values:\n";
// for(map< unsigned int , string >::iterator iter = _temporalArgs.begin();
// iter != _temporalArgs.end();
// iter++)
// cout << iter->first <<" "<< iter->second << endl;
if(_myUpdater != 0) {
if(_temporalArgs.find(0) != _temporalArgs.end()) {
_isTemporal = true;
//set the value for the first generation
arg = _temporalArgs.find(0)->second;
}
else {
error("first generation argument value for temporal parameter \"%s\" is missing; no \"@g0\".\n", _name.c_str());
return false;
}
} else {
warning("trying to pass a temporal argument to a non temporal parameter (\"%s\").\n", _name.c_str());
_isTemporal = false;
_temporalArgs.clear();
}
} else _isTemporal = false;
return true;
}
| bool Param::parseSubParamArgument | ( | const string & | arg | ) |
| bool Param::parseTemporalArgument | ( | const string & | arg | ) |
Definition at line 215 of file param.cc.
References _name, _temporalArgs, error(), tstring::removeFirstCharOf(), tstring::split(), and tstring::str2uint().
Referenced by parseArgument().
{
vector< string > args = tstring::split(arg, ' ', true);
if(args.size() != 2) {
error("Param::parseTemporalArgument:: missing argument value in \"%s %s\".\n", _name.c_str(), arg.c_str());
return false;
}
unsigned int gen = tstring::str2uint(tstring::removeFirstCharOf(tstring::removeFirstCharOf(args[0], '@'), 'g'));
_temporalArgs[gen] = args[1];
return true;
}
| void Param::reset | ( | ) |
Clears the _isSet flag and the argument string.
Definition at line 71 of file param.cc.
References _arg, _isSet, and _setAtGeneration.
{
_arg = "";
_isSet = 0;
_setAtGeneration = 0;
}
| 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
Definition at line 106 of file param.cc.
References _arg, _bounds, _isBounded, _isSet, _type, BOOL, DBL, INT, tstring::isanumber(), MAT, parseArgument(), tstring::str2dble(), and tstring::str2int().
{
//cout << "Param::set ("<<arg<<")\n";
if( arg[0] == '(' )
if( !parseArgument( arg ) ) {
errmsg = "could not parse the argument string";
return false;
}
//integer or decimal:
if(_type == INT || _type == DBL) {
if(arg[0] != '{') {
if(!tstring::isanumber(arg)) {
errmsg = "argument is not a number";
return false;
}
double val = tstring::str2dble(arg);
if(_isBounded && (val < _bounds[0] || val > _bounds[1]) ){
errmsg = "argument is out of bounds";
return false;
}
}
//boolean:
} else if(_type == BOOL) {
if( !tstring::isanumber(arg) ){
errmsg = "argument is not a boolean";
return false;
}
} else if(_type == MAT) {
if(arg[0] != '{'){
errmsg = "argument is not a matrix";
return false;
}
}
// else if(_type == P || _type == S): no conditions to check
_isSet = (_type == BOOL && tstring::str2int(arg) == 0 ? false : true);
_arg = arg;
return true;
}
| void Param::setArg | ( | string | value | ) | [inline] |
| void Param::setAtGeneration | ( | unsigned int | generation | ) | [inline] |
Definition at line 121 of file param.h.
{_setAtGeneration = generation;}
| void Param::setBounds | ( | double | low_bnd, |
| double | up_bnd | ||
| ) | [inline] |
| void Param::setIsBounded | ( | bool | value | ) | [inline] |
| void Param::setIsSet | ( | bool | value | ) | [inline] |
| void Param::setName | ( | string | value | ) | [inline] |
| void Param::setOwner | ( | SimComponent * | owner | ) | [inline] |
| void Param::setType | ( | param_t | value | ) | [inline] |
| void Param::setUpdater | ( | ParamUpdaterBase * | updater | ) | [inline] |
Sets the pointer to the updater object.
Definition at line 119 of file param.h.
{_myUpdater = updater;}
| void Param::show_up | ( | ) |
| bool Param::update | ( | unsigned int | generation | ) |
Updates the parameter value at a given generation during the simulation.
Definition at line 336 of file param.cc.
References _name, _temporalArgs, and error().
{
string error_msg;
if(_temporalArgs.find( generation ) != _temporalArgs.end()) {
if( !set( _temporalArgs[generation], error_msg ) ){
error("could not set \"%s\": %s", _name.c_str(), error_msg.c_str());
return false;
} else
return true;
} else
error("parameters \"%s\" does not have an argument value for generation %i.\n", _name.c_str(), generation);
return false;
}
string Param::_arg [private] |
The argument string, set by the ParamsParser upon initialization.
Definition at line 57 of file param.h.
Referenced by getValue(), parse_matrix(), reset(), set(), and show_up().
double Param::_bounds[2] [private] |
bool Param::_isBounded [private] |
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.
bool Param::_isSet [private] |
Flag set once the parameter has recieved the right argument.
Definition at line 61 of file param.h.
Referenced by getMatrix(), getValue(), reset(), set(), and show_up().
bool Param::_isTemporal [private] |
Definition at line 79 of file param.h.
Referenced by parseArgument().
SimComponent* Param::_myOwner [private] |
ParamUpdaterBase* Param::_myUpdater [private] |
Pointer to an ParamUpdater object.
Definition at line 74 of file param.h.
Referenced by parseArgument(), and ~Param().
string Param::_name [private] |
The name of the parameter as read in the init file.
Definition at line 55 of file param.h.
Referenced by getMatrix(), parse_matrix(), parseArgument(), parseTemporalArgument(), show_up(), and update().
unsigned int Param::_setAtGeneration [private] |
map<string, Param*> Param::_subParams [private] |
map< unsigned int, string > Param::_temporalArgs [private] |
The temporal arguments.
Definition at line 78 of file param.h.
Referenced by getTemporalArgs(), getUpdatingDates(), parseArgument(), parseTemporalArgument(), and update().
param_t Param::_type [private] |
The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h).
Definition at line 59 of file param.h.
Referenced by getValue(), and set().
1.7.5.1 -- Nemo is hosted by