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

Class to update the simulation components' state during a simulation. More...

#include <updaterservices.h>

+ Inheritance diagram for UpdaterServices:
+ Collaboration diagram for UpdaterServices:

Public Member Functions

 UpdaterServices ()
 
virtual ~UpdaterServices ()
 
virtual bool init ()
 
virtual void notify ()
 
virtual void notify (unsigned int generation)
 The generation time is passed to the updaters. More...
 
virtual void load (SimComponent *sc)
 Loads the updaters in case a component's parameter has temporal arguments. More...
 
virtual void attach (Handler *H)
 Attach the updater to the stack. More...
 
virtual void reset ()
 Clears the containers. More...
 
void update_params (unsigned int generation)
 Calls the parameters updating procedure. More...
 
void update_components (unsigned int generation)
 Update the components using the functions stored in the updaters. More...
 
bool hasTemporals ()
 Checks if any updater has been uploaded. More...
 
- Public Member Functions inherited from Service
 Service ()
 
virtual ~Service ()
 
virtual bool init ()=0
 Inits internals. More...
 
virtual void notify ()=0
 Notifies all observers to update their state. More...
 
virtual void load (SimComponent *sc)=0
 Interface used by a simulation component to load its obervers onto a service provider. More...
 
virtual void attach (Handler *h)=0
 Adds an observer to the list. More...
 
virtual void reset ()=0
 Clears the observers list. More...
 

Private Attributes

map< unsigned int, list< Param * > > _paramUpdater
 
map< unsigned int, list< ParamUpdaterBase * > > _componentUpdater
 
list< ParamUpdaterBase * > _updaters
 

Detailed Description

Class to update the simulation components' state during a simulation.

It stores the ParamUpdater objects. Each ParamUpdater stores a list of parameters from a SimComponent that use a single updating function from that component. That updating function is called to update the state of the SimComponent that declares it at a given generation during a simulation. When attaching an updater to the UpdaterServices, it is added to the _componentUpdater map and the list of its parameters is stored to the _paramUpdater map. Each map has the generation number at which the parameter/component must be updated as a key. The updaters are attached during the simulation setup (SimRunner::register_component). Each parameter set/simulation component is scanned for the presence of temporal parameters and is asked to add its updaters to the stack. The updaters will appear only once in the _updaters list as they store a single updating function although several parameters may upload the same updater. This allows several parameters to be attached to a single updater and use a single updating function from their simulation component.

The updating procedure is as follows: the parameters are first updated with their temporal argument value at the right generation. The components are then updated by using the function pointers stored in the updaters that will fetch the parameters values and update its state. Those updating functions must be implemented seperately for each component and set of parameters. The default SimComponent::setParameters function may suffice most of the time. That function is called only once and thus will update the component's state at the generations given in input by by the user.

Constructor & Destructor Documentation

◆ UpdaterServices()

UpdaterServices::UpdaterServices ( )
inline
74{ }

◆ ~UpdaterServices()

virtual UpdaterServices::~UpdaterServices ( )
inlinevirtual
75{reset();}
virtual void reset()
Clears the containers.
Definition: updaterservices.cc:61

References reset().

Member Function Documentation

◆ attach()

void UpdaterServices::attach ( Handler H)
virtual

Attach the updater to the stack.

Implements Service.

90{
91 ParamUpdaterBase* PU = dynamic_cast<ParamUpdaterBase*> (H);
92
93 if(!PU) return;
94
95 list< Param* > params = PU->getParams();
96
97 deque< unsigned int > dates;
98
99 for(list<Param*>::const_iterator pit = params.begin();
100 pit != params.end(); pit++) {
101
102 dates = (*pit)->getUpdatingDates();
103
104 for(unsigned int i = 0; i < dates.size(); i++) {
105 _paramUpdater[ dates[i] ].push_back((*pit));
106 _componentUpdater[ dates[i] ].push_back(PU);
107 }
108 }
109
110 _updaters.push_back(PU);
111}
Base class of the ParamUpdater class used to handle the temporal parameter argument values.
Definition: param.h:315
list< Param * > getParams()
Returns the list of parameters.
Definition: param.h:347
list< ParamUpdaterBase * > _updaters
Definition: updaterservices.h:70
map< unsigned int, list< Param * > > _paramUpdater
Definition: updaterservices.h:68
map< unsigned int, list< ParamUpdaterBase * > > _componentUpdater
Definition: updaterservices.h:69

References _componentUpdater, _paramUpdater, _updaters, and ParamUpdaterBase::getParams().

Referenced by SimComponent::loadUpdaters().

+ Here is the caller graph for this function:

◆ hasTemporals()

bool UpdaterServices::hasTemporals ( )
inline

Checks if any updater has been uploaded.

92{return !_paramUpdater.empty();}

References _paramUpdater.

Referenced by SimRunner::init_components().

+ Here is the caller graph for this function:

◆ init()

bool UpdaterServices::init ( )
virtual

Implements Service.

40{
41 //consolidate the lists of updaters by removing the duplicates (if they exist)
42 for(map<unsigned int, list<ParamUpdaterBase*> >::iterator it = _componentUpdater.begin();
43 it != _componentUpdater.end(); it++)
44 it->second.unique();
45
46 for(map<unsigned int, list<Param*> >::iterator it = _paramUpdater.begin();
47 it != _paramUpdater.end(); it++)
48 it->second.unique();
49
50 _updaters.unique();
51
52 for(list<ParamUpdaterBase*>::iterator it = _updaters.begin();
53 it != _updaters.end(); it++)
54 (*it)->init();
55
56 return true;
57}

References _componentUpdater, _paramUpdater, and _updaters.

Referenced by SimRunner::init_components().

+ Here is the caller graph for this function:

◆ load()

void UpdaterServices::load ( SimComponent sc)
virtual

Loads the updaters in case a component's parameter has temporal arguments.

Implements Service.

83{
84 sc->loadUpdaters(this);
85}
virtual void loadUpdaters(UpdaterServices *loader)
Loads the parameters and component updater onto the updater manager.
Definition: simcomponent.h:68

References SimComponent::loadUpdaters().

Referenced by SimRunner::register_component().

+ Here is the caller graph for this function:

◆ notify() [1/2]

virtual void UpdaterServices::notify ( )
inlinevirtual

Implements Service.

78{}

Referenced by LCE_ParamUpdaterNotifier::execute(), and SimRunner::setForFirstGeneration().

+ Here is the caller graph for this function:

◆ notify() [2/2]

void UpdaterServices::notify ( unsigned int  generation)
virtual

The generation time is passed to the updaters.

116{
117 update_params(generation);
118 update_components(generation);
119}
void update_params(unsigned int generation)
Calls the parameters updating procedure.
Definition: updaterservices.cc:123
void update_components(unsigned int generation)
Update the components using the functions stored in the updaters.
Definition: updaterservices.cc:137

References update_components(), and update_params().

◆ reset()

void UpdaterServices::reset ( )
virtual

Clears the containers.

Implements Service.

62{
63 map<unsigned int, list<Param*> >::iterator pit = _paramUpdater.begin();
64
65 for(;pit != _paramUpdater.end(); pit++) {
66 pit->second.clear();
67 }
68 _paramUpdater.clear();
69
70 map<unsigned int, list<ParamUpdaterBase*> >::iterator scit = _componentUpdater.begin();
71
72 for(;scit != _componentUpdater.end(); scit++) {
73 scit->second.clear();
74 }
75 _componentUpdater.clear();
76
77 _updaters.clear();
78}

References _componentUpdater, _paramUpdater, and _updaters.

Referenced by SimRunner::reset_services(), and ~UpdaterServices().

+ Here is the caller graph for this function:

◆ update_components()

void UpdaterServices::update_components ( unsigned int  generation)

Update the components using the functions stored in the updaters.

138{
139 map<unsigned int, list<ParamUpdaterBase*> >::iterator mit = _componentUpdater.find(generation);
140
141 if(mit == _componentUpdater.end()) return;
142
143 for(list<ParamUpdaterBase*>::iterator pit = mit->second.begin();
144 pit != mit->second.end(); pit++)
145 {
146 if( !(*pit)->update(generation) )
147 warning("error while updating component \'%s\' at generation %i.\n",
148 (*pit)->getComponent()->get_name().c_str(), generation);
149 }
150}
void warning(const char *str,...)
Definition: output.cc:58

References _componentUpdater, and warning().

Referenced by notify().

+ Here is the caller graph for this function:

◆ update_params()

void UpdaterServices::update_params ( unsigned int  generation)

Calls the parameters updating procedure.

The map is searched for the occurence of the generation.

124{
125 map<unsigned int, list<Param*> >::iterator mit = _paramUpdater.find(generation);
126
127 if(mit == _paramUpdater.end()) return;
128
129 for(list<Param*>::iterator pit = mit->second.begin();
130 pit != mit->second.end(); pit++)
131 (*pit)->update(generation);
132
133}

References _paramUpdater.

Referenced by notify().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _componentUpdater

map< unsigned int, list< ParamUpdaterBase* > > UpdaterServices::_componentUpdater
private

Referenced by attach(), init(), reset(), and update_components().

◆ _paramUpdater

map< unsigned int, list< Param* > > UpdaterServices::_paramUpdater
private

◆ _updaters

list< ParamUpdaterBase* > UpdaterServices::_updaters
private

Referenced by attach(), init(), and reset().


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