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

Parameters container, implemented in each SimComponent. More...

#include <param.h>

+ Collaboration diagram for ParamSet:

Public Member Functions

 ParamSet ()
 
 ParamSet (const ParamSet &PS)
 
 ~ParamSet ()
 
void reset ()
 Put the container in the unset state, reset each Param it contains. More...
 
void clear ()
 Empties the parameter containers (no delete). More...
 
bool check_consistency ()
 Checks for the status of the required parameters. More...
 
void show_up ()
 print info to stdout. More...
 
void print (ofstream &FILE, bool commentOut=false)
 print all set parameters to the outpout file stream More...
 
int size ()
 Returns the number of parameters contained. More...
 
map< string, Param * > & getAllParams ()
 Returns the complete list of parameters. More...
 
ParamSetoperator= (const ParamSet &PS)
 
Accessors to Param members.
void add_param (Param *param)
 Adds the param argument to the list. More...
 
void add_param (string Name, param_t Type, bool mandatory, bool isBounded, double low_bnd, double up_bnd)
 Adds a new param specified by arguments to the list. More...
 
void add_param (string Name, param_t Type, bool mandatory, bool isBounded, double low_bnd, double up_bnd, ParamUpdaterBase *updater)
 
bool set_param (string Name, string Arg)
 Look for a param named "Name" and try to set it with the "Arg" argument string. More...
 
Paramfind_param (string name)
 Look for a param "name" in its parameters list. More...
 
Paramget_param (string name)
 Look for a param "name" in its parameters list. More...
 
bool has_param (string name)
 Look for a param "name" in its parameters list. More...
 
bool update_param (string Name, unsigned int generation)
 Calls the updating procedure of each of its Param. More...
 
void setName (string value)
 Sets the container's name. More...
 
void setIsRequired (bool value)
 Sets the _isRequired flag meaning this container is mandatory and must be set in order to run a simulation. More...
 
void setOwner (SimComponent *owner)
 Sets the pointer to the SimComponents that owns this set. More...
 
bool isSet ()
 Accessor to the status flag. More...
 
string getName ()
 Name accessor. More...
 
bool isRequired ()
 Accessor to the mandatory flag. More...
 
bool isSet (string name)
 Accessor to the parameters status flag. More...
 
bool isMatrix (string name)
 Check if the parameter "name" is of matrix type. More...
 
bool isTemporal (string name)
 Check if the parameter "name" has temporal arguments. More...
 
string getArg (string name)
 Accessor to the parameters argument string. More...
 
double getValue (string name)
 Accessor the parameters value. More...
 
void getMatrix (string name, TMatrix *mat)
 Accessor to the parameters matrix. More...
 
list< ParamUpdaterBase * > getUpdaters ()
 Collects the parameter updaters from the set of parameters. More...
 

Private Attributes

string _name
 The name of the component. More...
 
bool _isSet
 Flag is true if all mandatory parameters are correctly set from user's input file. More...
 
bool _isRequired
 Flaf is true if component is required (mandatory) to run a simulation (e.g. More...
 
map< string, Param * > _params
 List of parameters indexed by name. More...
 
SimComponent_myOwner
 Pointer to the component that declared this parameter. More...
 

Detailed Description

Parameters container, implemented in each SimComponent.

A SimComponent is added to the set of active components of a simulation only if all its required parameters are set (isSet = true).

Constructor & Destructor Documentation

◆ ParamSet() [1/2]

ParamSet::ParamSet ( )
inline
220: _isSet(0), _isRequired(0), _myOwner(0) { }
SimComponent * _myOwner
Pointer to the component that declared this parameter.
Definition: param.h:216
bool _isRequired
Flaf is true if component is required (mandatory) to run a simulation (e.g.
Definition: param.h:212
bool _isSet
Flag is true if all mandatory parameters are correctly set from user's input file.
Definition: param.h:210

◆ ParamSet() [2/2]

ParamSet::ParamSet ( const ParamSet PS)
535{
536 map<string, Param*>::iterator param;
537
538 if( _params.size() ) {
539 param = _params.begin();
540 while(param != _params.end()) {
541 delete param->second;
542 param++;
543 }
544 _params.clear();
545 }
546 map<string, Param*> PS_params = PS._params;
547 param = PS_params.begin();
548 while(param != PS_params.end()) {
549 _params[param->first] = new Param( *param->second );
550 param++;
551 }
552
553}
map< string, Param * > _params
List of parameters indexed by name.
Definition: param.h:214
string _name
The name of the component.
Definition: param.h:208
This structure stores one parameter, its definition and its string argument.
Definition: param.h:54

References _params.

◆ ~ParamSet()

ParamSet::~ParamSet ( )
559{
560 map<string, Param*>::iterator param = _params.begin();
561 while(param != _params.end()) {
562 delete param->second;
563 param++;
564 }
565}

References _params.

Member Function Documentation

◆ add_param() [1/3]

void ParamSet::add_param ( Param param)
inline

Adds the param argument to the list.

243{_params[param->getName()] = param;}
string getName()
Definition: param.h:137

References _params, and Param::getName().

Referenced by add_param(), SimComponent::add_parameter(), and ParamManager::ParamManager().

+ Here is the caller graph for this function:

◆ add_param() [2/3]

void ParamSet::add_param ( string  Name,
param_t  Type,
bool  mandatory,
bool  isBounded,
double  low_bnd,
double  up_bnd 
)
inline

Adds a new param specified by arguments to the list.

Parameters
Namethe name of the parameter
Typethe type of the parameter
mandatoryspecifies if this parameter is required and must be set for the container to gain the "set" status
isBoundedspecified whether this parameter is bounded
low_bndthe lower value the parameter can take, used if isBounded is true
up_bndthe upper value the parameter can take, used if isBounded is true
254 {add_param(Name, Type, mandatory, isBounded, low_bnd, up_bnd, 0);}
void add_param(Param *param)
Adds the param argument to the list.
Definition: param.h:243

References add_param().

◆ add_param() [3/3]

void ParamSet::add_param ( string  Name,
param_t  Type,
bool  mandatory,
bool  isBounded,
double  low_bnd,
double  up_bnd,
ParamUpdaterBase updater 
)
583{
584 // if(!_name.empty()) Name = _name + "_" + Name; //not yet...
585 Param* param = new Param(Name, Type, mandatory, isBounded, low_bnd, up_bnd, _myOwner, updater);
586 if(updater) updater->addParam(param);
587 _params[Name] = param;
588}
virtual void addParam(Param *param)
Adds a parameter to the stack.
Definition: param.h:343

References _myOwner, _params, and ParamUpdaterBase::addParam().

◆ check_consistency()

bool ParamSet::check_consistency ( )

Checks for the status of the required parameters.

Returns
TRUE if all required parameters are or if nothing is set and the container is not required
670{
671 map<string, Param*>::iterator param = _params.begin();
672 bool isOK = true;
673 bool touched = false;
674 bool ignore = false;
675
676 vector<string> mandatory;
677
678 while(param != _params.end()) {
679
680 //check if all mandatory parameters have been set properly
681 if(param->second->isRequired()) {
682
683 isOK &= param->second->isSet();
684
685 if( !param->second->isSet() ) {
686 //ignore LCE name when not added in life cycle (not wanted) to avoid error messages from inherited classes (composite LCE)
687 //e.g. if breed_disperse is set, all LCE derived from breed_base will be touched but not set and will complain
688 if (_name == param->second->getName()) {
689
690 ignore = true;
691
692 } else
693 mandatory.push_back(param->second->getName());
694 }
695 }
696
697 //check if at least one param has been set
698 touched |= param->second->isSet();
699 param++;
700 }
701 _isSet = isOK;
702
703 // issue warning in case of partial OK, or partial set
704 if( touched && !isOK && !ignore) {
705 warning("Mandatory parameters of component \"%s\" were not properly set.", _name.c_str());
706 warning("This component will not be added to the simulation!");
707 warning("The missing parameters are:\n");
708
709 for(unsigned int i = 0; i < mandatory.size(); ++i)
710 message(">>>> \"%s\"\n", mandatory[i].c_str());
711
712 message("\n");
713
714 for(unsigned int i = 10; i > 0; i--) {
715 message("\rIf you want to abort now, press Ctrl-C, or wait for %is ", i);
716 fflush(stdout);
717 sleep(1);
718 }
719
720 message("\n\n");
721 }
722 //return isOk or check if _isRequired in case no params are set (untouched params)
723 return ( isOK | (!_isRequired));
724}
void warning(const char *str,...)
Definition: output.cc:58
void message(const char *message,...)
Definition: output.cc:40

References _isRequired, _isSet, _name, _params, message(), and warning().

◆ clear()

void ParamSet::clear ( )
inline

Empties the parameter containers (no delete).

227{_params.clear();}

References _params.

◆ find_param()

Param * ParamSet::find_param ( string  name)

Look for a param "name" in its parameters list.

Returns
NULL if no Param with _name = name exists
626{
627 map<string, Param*>::iterator param = _params.find(Name);
628
629 if(param != _params.end())
630 return param->second;
631 else
632 return NULL;
633}

References _params.

◆ get_param()

Param * ParamSet::get_param ( string  name)

Look for a param "name" in its parameters list.

Returns
NULL if no Param with _name = name exists
638{
639 map<string, Param*>::iterator param = _params.find(Name);
640
641 if(param != _params.end())
642 return param->second;
643 else
644 fatal("parameter \"%s\" is not a member of \"%s\".\n", Name.c_str(), _name.c_str());
645 //return NULL;
646 return NULL;
647}
void fatal(const char *str,...)
Definition: output.cc:96

References _name, _params, and fatal().

Referenced by SimComponent::get_parameter(), getArg(), getMatrix(), getValue(), isMatrix(), isSet(), isTemporal(), LCE_StatServiceNotifier::setOccurence(), and update_param().

+ Here is the caller graph for this function:

◆ getAllParams()

map< string, Param * > & ParamSet::getAllParams ( )
inline

Returns the complete list of parameters.

239{return _params;}

References _params.

◆ getArg()

string ParamSet::getArg ( string  name)
inline

Accessor to the parameters argument string.

300{return (get_param(name))->getArg();}
Param * get_param(string name)
Look for a param "name" in its parameters list.
Definition: param.cc:637

References get_param().

Referenced by LCE_Resize::execute(), SimRunner::init(), LCE_Selection_base::set_fit_model(), LCE_Selection_base::set_local_optima(), LCE_Disperse_EvolDisp::setParameters(), LCE_Patch_Extinction::setParameters(), LCE_StatServiceNotifier::setParameters(), TProtoDeletMutations_bitstring::setSelectionParameters(), Metapop::setSourceParameters(), and LCE_Resize::updateParameters().

+ Here is the caller graph for this function:

◆ getMatrix()

◆ getName()

string ParamSet::getName ( )
inline

Name accessor.

290{return _name;}

References _name.

Referenced by SimComponent::get_name().

+ Here is the caller graph for this function:

◆ getUpdaters()

list< ParamUpdaterBase * > ParamSet::getUpdaters ( )

Collects the parameter updaters from the set of parameters.

593{
594 list<ParamUpdaterBase*> updaters;
595 map<string, Param*>::iterator param = _params.begin();
596 for(;param != _params.end(); param++) {
597 if(param->second->getUpdater() != 0)
598 updaters.push_back(param->second->getUpdater());
599 }
600 return updaters;
601}

References _params.

Referenced by SimComponent::loadUpdaters().

+ Here is the caller graph for this function:

◆ getValue()

◆ has_param()

bool ParamSet::has_param ( string  name)

Look for a param "name" in its parameters list.

Returns
false if no Param with _name = name exists, true otherwise
652{
653 map<string, Param*>::iterator param = _params.find(Name);
654
655 return (param != _params.end());
656}

References _params.

Referenced by SimComponent::has_parameter().

+ Here is the caller graph for this function:

◆ isMatrix()

bool ParamSet::isMatrix ( string  name)
inline

Check if the parameter "name" is of matrix type.

296{return (get_param(name))->isMatrix();}

References get_param().

Referenced by LCE_Breed_Disperse::setParameters(), LCE_Resize::setParameters(), and Metapop::setPopulationParameters().

+ Here is the caller graph for this function:

◆ isRequired()

bool ParamSet::isRequired ( )
inline

Accessor to the mandatory flag.

292{return _isRequired;}

References _isRequired.

◆ isSet() [1/2]

◆ isSet() [2/2]

bool ParamSet::isSet ( string  name)
inline

Accessor to the parameters status flag.

294{return (get_param(name))->isSet();}

References get_param().

◆ isTemporal()

bool ParamSet::isTemporal ( string  name)
inline

Check if the parameter "name" has temporal arguments.

298{return (get_param(name))->isTemporal();}

References get_param().

◆ operator=()

ParamSet & ParamSet::operator= ( const ParamSet PS)
729{
730 if(this != &PS) {
731 _name = PS._name;
732 _isSet = PS._isSet;
734
735 map<string, Param*>::iterator param;
736
737 if( _params.size() ) {
738 param = _params.begin();
739 while(param != _params.end()) {
740 delete param->second;
741 param++;
742 }
743 _params.clear();
744 }
745 map<string, Param*> PS_params = PS._params;
746 param = PS_params.begin();
747 while(param != PS_params.end()) {
748 _params[param->first] = new Param( *param->second );
749 param++;
750 }
751 }
752 return *this;
753}

References _isRequired, _isSet, _name, and _params.

◆ print()

void ParamSet::print ( ofstream &  FILE,
bool  commentOut = false 
)

print all set parameters to the outpout file stream

770{
771 map<string, Param*>::iterator paramRec = _params.begin();
772 Param* param;
773
774 while(paramRec != _params.end()) {
775
776 param = paramRec->second;
777
778 if(param->isSet())
779 {
780 if(commentOut)
781 FILE<<"#";
782
783 FILE<<param->getName()<<" "<<param->getArg()<<endl;
784 }
785
786 paramRec++;
787 }
788}
string getArg()
Definition: param.h:138
bool isSet()
Definition: param.h:140

References _params, Param::getArg(), Param::getName(), and Param::isSet().

◆ reset()

void ParamSet::reset ( )

Put the container in the unset state, reset each Param it contains.

570{
571 _isSet = 0;
572 map<string, Param*>::iterator param = _params.begin();
573 while(param != _params.end()) {
574 param->second->reset();
575 param++;
576 }
577}

References _isSet, and _params.

◆ set_param()

bool ParamSet::set_param ( string  Name,
string  Arg 
)

Look for a param named "Name" and try to set it with the "Arg" argument string.

Returns
TRUE if param Name has been found and set with Arg
FALSE otherwise
Parameters
Namethe name of the parameter to find in the list
Argthe argument string as found in the init params
606{
607 map<string, Param*>::iterator param = _params.find(Name);
608 string error_msg;
609
610 if(param == _params.end()) {
611 // error("could not set \"%s\": parameter not found.\n",Name.c_str());
612 //exist silently
613 return false;
614 }
615
616 if( !param->second->set(Arg, error_msg) ) {
617 error("could not set \"%s\": %s.\n", Name.c_str(), error_msg.c_str());
618 return false;
619 } else
620 return true;
621}
int error(const char *str,...)
Definition: output.cc:77

References _params, and error().

Referenced by LCE_Resize::execute().

+ Here is the caller graph for this function:

◆ setIsRequired()

void ParamSet::setIsRequired ( bool  value)
inline

Sets the _isRequired flag meaning this container is mandatory and must be set in order to run a simulation.

284{_isRequired = value;}

References _isRequired.

Referenced by ParamManager::ParamManager(), and SimComponent::set_paramset().

+ Here is the caller graph for this function:

◆ setName()

void ParamSet::setName ( string  value)
inline

Sets the container's name.

282{_name = value;}

References _name.

Referenced by ParamManager::ParamManager(), and SimComponent::set_paramset().

+ Here is the caller graph for this function:

◆ setOwner()

void ParamSet::setOwner ( SimComponent owner)
inline

Sets the pointer to the SimComponents that owns this set.

286{_myOwner = owner;}

References _myOwner.

Referenced by ParamManager::ParamManager(), and SimComponent::set_paramset().

+ Here is the caller graph for this function:

◆ show_up()

void ParamSet::show_up ( )

print info to stdout.

758{
759 message("%s\n",_name.c_str());
760 map<string, Param*>::iterator param = _params.begin();
761 while(param != _params.end()) {
762 param->second->show_up();
763 param++;
764 }
765}

References _name, _params, and message().

◆ size()

int ParamSet::size ( )
inline

Returns the number of parameters contained.

237{return _params.size();}

References _params.

◆ update_param()

bool ParamSet::update_param ( string  Name,
unsigned int  generation 
)

Calls the updating procedure of each of its Param.

661{
662 Param* param = get_param(Name);
663 if(param) return param->update( generation );
664 return false;
665}
bool update(unsigned int generation)
Updates the parameter value at a given generation during the simulation.
Definition: param.cc:502

References get_param(), and Param::update().

Member Data Documentation

◆ _isRequired

bool ParamSet::_isRequired
private

Flaf is true if component is required (mandatory) to run a simulation (e.g.

SimRunner, Metapop).

Referenced by check_consistency(), isRequired(), operator=(), and setIsRequired().

◆ _isSet

bool ParamSet::_isSet
private

Flag is true if all mandatory parameters are correctly set from user's input file.

Referenced by check_consistency(), isSet(), operator=(), and reset().

◆ _myOwner

SimComponent* ParamSet::_myOwner
private

Pointer to the component that declared this parameter.

Referenced by add_param(), and setOwner().

◆ _name

string ParamSet::_name
private

The name of the component.

Referenced by check_consistency(), get_param(), getName(), operator=(), setName(), and show_up().

◆ _params

map<string, Param*> ParamSet::_params
private

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