Version: 9.16.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 ()
 
void setCurrentId (int id)
 
void putOutSampleAt (int id, Any *outValue)
 
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

◆ checkConsistency()

void Pool::checkConsistency ( )
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 139 of file Pool.cxx.

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

References _container.

◆ destroyAll()

void Pool::destroyAll ( void  )

◆ destroyCurrentCase()

void Pool::destroyCurrentCase ( )
private

Definition at line 127 of file Pool.cxx.

128{
129 if(!_container.empty())
131}
std::list< std::pair< int, ExpData > >::iterator _currentCase
Definition: Pool.hxx:67

References _container, and _currentCase.

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

◆ empty()

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 246 of file Pool.cxx.

247{
248 return _container.empty();
249}

References _container.

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

◆ getCurrentId()

int Pool::getCurrentId ( void  ) const

Definition at line 78 of file Pool.cxx.

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

References _currentCase, and empty().

Referenced by SalomeEventLoop::get().

◆ getCurrentInSample()

Any * Pool::getCurrentInSample ( ) const

Definition at line 85 of file Pool.cxx.

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

References empty().

◆ getCurrentOutSample()

Any * Pool::getCurrentOutSample ( ) const

Definition at line 93 of file Pool.cxx.

94{
95 if(empty())
96 throw YACS::Exception("no current case set in pool");
97 else
98 return (*_currentCase).second.outValue();
99}

References empty().

Referenced by SalomeEventLoop::get().

◆ getNextSampleWithHighestPriority()

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 204 of file Pool.cxx.

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

References _container.

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

◆ getOutSample()

Any * Pool::getOutSample ( int  id)

Definition at line 101 of file Pool.cxx.

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 throw YACS::Exception("no current case set in pool");
111}

References _container, and empty().

◆ markIdAsInUse()

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 232 of file Pool.cxx.

233{
234 std::list< std::pair<int, ExpData> >::iterator iter;
235 for(iter=_container.begin();iter!=_container.end();iter++)
236 if((*iter).first==id)
237 {
238 (*iter).second.markItAsInUse();
239 break;
240 }
241}

References _container.

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

◆ pushInSample()

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 115 of file Pool.cxx.

116{
117 std::pair<int, ExpData> eltToAdd(id,Pool::ExpData(inSample,priority));
118 _container.push_back(eltToAdd);
119 inSample->decrRef();
120}

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

Referenced by SalomeEventLoop::put().

◆ putOutSampleAt()

void Pool::putOutSampleAt ( int  id,
Any outValue 
)
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 180 of file Pool.cxx.

181{
182 std::list< std::pair<int, ExpData> >::iterator iter;
183 for(iter=_container.begin();iter!=_container.end();iter++)
184 if((*iter).first==id)
185 {
186 _currentCase=iter;
187 (*iter).second.setOutValue(outValue);
188 break;
189 }
190 if(iter==_container.end())
192}
static const char MESSAGEFORUNXSTNGID[]
Definition: Pool.hxx:86

References _container, _currentCase, and MESSAGEFORUNXSTNGID.

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

◆ setCurrentId()

void Pool::setCurrentId ( int  id)
private
Exceptions
Seethe throw case of pushOutSampleAt method.

Definition at line 159 of file Pool.cxx.

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

References _container, _currentCase, and MESSAGEFORUNXSTNGID.

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

Friends And Related Function Documentation

◆ OptimizerLoop

friend class OptimizerLoop
friend

Definition at line 43 of file Pool.hxx.

Member Data Documentation

◆ _container

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

◆ _currentCase

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().

◆ MESSAGEFORUNXSTNGID

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: