Version: 8.3.0
YACS::ENGINE::Pool Class Reference

Pool used to manage the samples of the optimizer loop plugin. More...

#include <Pool.hxx>

Collaboration diagram for YACS::ENGINE::Pool:

Classes

class  ExpData
 

Public Member Functions

int getCurrentId () const
 
AnygetCurrentInSample () const
 
AnygetCurrentOutSample () const
 
AnygetOutSample (int id)
 
void pushInSample (int id, Any *inSample, unsigned char priority=0)
 Push a sample. WARNING inSample ownership is released to current Pool instance (this) ! More...
 
void destroyAll ()
 

Private Member Functions

void destroyCurrentCase ()
 
void checkConsistency () throw (Exception)
 
void setCurrentId (int id) throw (Exception)
 
void putOutSampleAt (int id, Any *outValue) throw (Exception)
 
AnygetNextSampleWithHighestPriority (int &id, unsigned char &priority) const
 
void markIdAsInUse (int id)
 
bool empty () const
 

Private Attributes

std::list< std::pair< int,
ExpData > > 
_container
 
std::list< std::pair< int,
ExpData > >::iterator 
_currentCase
 

Static Private Attributes

static const char MESSAGEFORUNXSTNGID [] ="The id specified not exists. Unable to handle with. Either internal error, or invalid use of Pool from Optimizer Algorithm"
 

Friends

class OptimizerLoop
 

Detailed Description

Pool used to manage the samples of the optimizer loop plugin.

Every sample has an identifier (Id), a priority, an initial value (In) and an evaluation value (Out). The current sample is the sample used by the latest terminated evaluation.

Definition at line 41 of file Pool.hxx.

Member Function Documentation

void Pool::checkConsistency ( ) throw (Exception)
private

This method is typically called by OptimizerNode to check the consistency, that is to say that optimizer algorithm has not corrupted 'this'.

Definition at line 140 of file Pool.cxx.

References _container.

141 {
142  // First check unicity of ids.
143  std::set<int> ids;
144  std::list< std::pair<int, ExpData> >::iterator iter;
145  for(iter=_container.begin();iter!=_container.end();iter++)
146  {
147  std::pair< std::set<int>::iterator, bool > verdict=ids.insert((*iter).first);
148  if(verdict.second)
149  {
150  std::ostringstream what;
151  what << "Id with value : " << (*iter).first << " appears several times.";
152  throw Exception(what.str());
153  }
154  }
155 }
void Pool::destroyAll ( void  )
void Pool::destroyCurrentCase ( )
private

Definition at line 128 of file Pool.cxx.

References _container, and _currentCase.

Referenced by YACS::ENGINE::OptimizerLoop::updateStateOnFinishedEventFrom().

129 {
130  if(!_container.empty())
131  _container.erase(_currentCase);
132 }
bool Pool::empty ( ) const
private

Typically called after takeDecision of OptimizerAlg as been performed. If true is returned, that is to say that convergence has been reached.

Definition at line 247 of file Pool.cxx.

References _container.

Referenced by getCurrentId(), getCurrentInSample(), getCurrentOutSample(), getOutSample(), and YACS::ENGINE::OptimizerLoop::updateStateOnFinishedEventFrom().

248 {
249  return _container.empty();
250 }
int Pool::getCurrentId ( void  ) const

Definition at line 78 of file Pool.cxx.

References _currentCase, and empty().

79 {
80  if(empty())
81  throw YACS::Exception("no current case set in pool");
82  else
83  return _currentCase->first;
84 }
Any * Pool::getCurrentInSample ( ) const

Definition at line 85 of file Pool.cxx.

References empty().

86 {
87  if(empty())
88  throw YACS::Exception("no current case set in pool");
89  else
90  return (*_currentCase).second.inValue();
91 }
Any * Pool::getCurrentOutSample ( ) const

Definition at line 93 of file Pool.cxx.

References empty().

94 {
95  if(empty())
96  throw YACS::Exception("no current case set in pool");
97  else
98  return (*_currentCase).second.outValue();
99 }
Any * Pool::getNextSampleWithHighestPriority ( int &  id,
unsigned char &  priority 
) const
private

This method is typically called by OptimizerNode instance owner of 'this' that wants to launch an another job on one branch.

Returns
: In case there are more jobs to do 2 parameters are returned.
  • id to locate the computation to do.
  • priority attached.
  • value. In case no more jobs are required id and priority stay unchanged and the returned value is equal to 0.

Definition at line 205 of file Pool.cxx.

References _container.

Referenced by YACS::ENGINE::OptimizerLoop::exUpdateState(), YACS::ENGINE::OptimizerLoop::launchMaxOfSamples(), and YACS::ENGINE::OptimizerLoop::updateStateOnFinishedEventFrom().

206 {
207  unsigned char myPriority=0;
208  std::list< std::pair<int, ExpData> >::const_iterator iter,ptToSelected;
209  ptToSelected=_container.end();
210  for(iter=_container.begin();iter!=_container.end();iter++)
211  {
212  if((*iter).second.isLaunchable())
213  if((*iter).second.getPriority()>myPriority || ptToSelected==_container.end())
214  {
215  ptToSelected=iter;
216  myPriority=(*iter).second.getPriority();
217  }
218  }
219  //Search performed. No performing output writings if needed.
220  if(ptToSelected==_container.end())
221  return 0;
222  priority=myPriority;
223  id=(*ptToSelected).first;
224  return (*ptToSelected).second.inValue();
225 }
Any * Pool::getOutSample ( int  id)

Definition at line 101 of file Pool.cxx.

References _container, and empty().

102 {
103  if(empty())
104  throw YACS::Exception("no current case set in pool");
105 
106  std::list< std::pair<int, ExpData> >::iterator iter;
107  for(iter=_container.begin();iter!=_container.end();iter++)
108  if((*iter).first==id)
109  return (*iter).second.outValue();
110  if(iter==_container.end())
111  throw YACS::Exception("no current case set in pool");
112 }
void Pool::markIdAsInUse ( int  id)
private

Typically called after 'this->destroyCurrentCase' 'this->checkConsistency' and 'this->getNextSampleWithHighestPriority' have been called. At this point the case with id id is marked as in use in order to avoid to be used by an another branch of OptimizerNode.

Definition at line 233 of file Pool.cxx.

References _container.

Referenced by YACS::ENGINE::OptimizerLoop::launchMaxOfSamples().

234 {
235  std::list< std::pair<int, ExpData> >::iterator iter;
236  for(iter=_container.begin();iter!=_container.end();iter++)
237  if((*iter).first==id)
238  {
239  (*iter).second.markItAsInUse();
240  break;
241  }
242 }
void Pool::pushInSample ( int  id,
Any inSample,
unsigned char  priority = 0 
)

Push a sample. WARNING inSample ownership is released to current Pool instance (this) !

Definition at line 116 of file Pool.cxx.

References _container, and YACS::ENGINE::RefCounter::decrRef().

117 {
118  std::pair<int, ExpData> eltToAdd(id,Pool::ExpData(inSample,priority));
119  _container.push_back(eltToAdd);
120  inSample->decrRef();
121 }
void Pool::putOutSampleAt ( int  id,
Any outValue 
) throw (Exception)
private

Push a result of case discriminated by id. It also sets the _currentCase pointer on the case discriminated by id. So after this call, the call to setCurrentId with the same id is useless.

Exceptions
Whencase id is not found in 'this'. This is particulary true, if not an internal error, when optimizer algorithm has destroyed a case id different from its id.

Definition at line 181 of file Pool.cxx.

References _container, _currentCase, and MESSAGEFORUNXSTNGID.

Referenced by YACS::ENGINE::OptimizerLoop::updateStateOnFinishedEventFrom().

182 {
183  std::list< std::pair<int, ExpData> >::iterator iter;
184  for(iter=_container.begin();iter!=_container.end();iter++)
185  if((*iter).first==id)
186  {
187  _currentCase=iter;
188  (*iter).second.setOutValue(outValue);
189  break;
190  }
191  if(iter==_container.end())
193 }
void Pool::setCurrentId ( int  id) throw (Exception)
private
Exceptions
Seethe throw case of pushOutSampleAt method.

Definition at line 160 of file Pool.cxx.

References _container, _currentCase, and MESSAGEFORUNXSTNGID.

Referenced by YACS::ENGINE::OptimizerLoop::updateStateOnFinishedEventFrom().

161 {
162  std::list< std::pair<int, ExpData> >::iterator iter;
163  for(iter=_container.begin();iter!=_container.end();iter++)
164  if((*iter).first==id)
165  {
166  _currentCase=iter;
167  break;
168  }
169  if(iter==_container.end())
171 }

Friends And Related Function Documentation

friend class OptimizerLoop
friend

Definition at line 43 of file Pool.hxx.

Member Data Documentation

std::list< std::pair<int, ExpData> > YACS::ENGINE::Pool::_container
private
std::list< std::pair<int, ExpData> >::iterator YACS::ENGINE::Pool::_currentCase
private

Definition at line 67 of file Pool.hxx.

Referenced by destroyCurrentCase(), getCurrentId(), putOutSampleAt(), and setCurrentId().

const char Pool::MESSAGEFORUNXSTNGID ="The id specified not exists. Unable to handle with. Either internal error, or invalid use of Pool from Optimizer Algorithm"
staticprivate

Definition at line 86 of file Pool.hxx.

Referenced by putOutSampleAt(), and setCurrentId().


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