Version: 8.3.0
YACS::ENGINE::PyOptimizerAlgASync Class Referenceabstract

Base class to implement in external dynamic lib or external python module in case of a non event oriented optimizer using Python code. More...

#include <PyOptimizerAlg.hxx>

Inheritance diagram for YACS::ENGINE::PyOptimizerAlgASync:
Collaboration diagram for YACS::ENGINE::PyOptimizerAlgASync:

Public Member Functions

virtual ~PyOptimizerAlgASync ()
 
virtual void startProxy ()
 
virtual void takeDecisionProxy ()
 
virtual void finishProxy ()
 
virtual void signalMasterAndWait ()
 Called when optimization has succeed. More...
 
- Public Member Functions inherited from YACS::ENGINE::PyOptimizerAlgBase
virtual ~PyOptimizerAlgBase ()
 
virtual TypeCodegetTCForInProxy () const
 
virtual TypeCodegetTCForOutProxy () const
 
virtual TypeCodegetTCForAlgoInitProxy () const
 
virtual TypeCodegetTCForAlgoResultProxy () const
 
virtual void initializeProxy (const Any *input) throw (Exception)
 
virtual AnygetAlgoResultProxy ()
 
- Public Member Functions inherited from YACS::ENGINE::OptimizerAlgBase
virtual void setPool (Pool *pool)
 
virtual void setProc (Proc *proc)
 
virtual ProcgetProc ()
 
virtual bool hasError () const
 
virtual const std::string & getError () const
 
virtual void setError (const std::string &message)
 
void setNbOfBranches (int nbOfBranches)
 
int getNbOfBranches () const
 
- Public Member Functions inherited from YACS::ENGINE::RefCounter
unsigned int getRefCnt () const
 
void incrRef () const
 
bool decrRef ()
 

Protected Member Functions

 PyOptimizerAlgASync (Pool *pool)
 
virtual void start ()
 
virtual void takeDecision ()
 Update _pool attribute before performing anything. More...
 
virtual void run ()
 
virtual void startToTakeDecision ()=0
 
- Protected Member Functions inherited from YACS::ENGINE::PyOptimizerAlgBase
 PyOptimizerAlgBase (Pool *pool)
 
- Protected Member Functions inherited from YACS::ENGINE::OptimizerAlgBase
 OptimizerAlgBase (Pool *pool)
 
virtual ~OptimizerAlgBase ()
 
virtual TypeCodegetTCForIn () const =0
 returns typecode of type expected as Input. OwnerShip of returned pointer is held by this. More...
 
virtual TypeCodegetTCForOut () const =0
 returns typecode of type expected as Output. OwnerShip of returned pointer is held by this. More...
 
virtual TypeCodegetTCForAlgoInit () const
 returns typecode of type expected for algo initialization. OwnerShip of returned pointer is held by this. More...
 
virtual TypeCodegetTCForAlgoResult () const
 returns typecode of type expected as algo result. OwnerShip of returned pointer is held by this. More...
 
virtual void initialize (const Any *input) throw (Exception)
 
virtual void finish ()
 
virtual AnygetAlgoResult ()
 Called when optimization has succeed. More...
 
- Protected Member Functions inherited from YACS::ENGINE::RefCounter
 RefCounter ()
 
 RefCounter (const RefCounter &other)
 
virtual ~RefCounter ()
 

Additional Inherited Members

- Static Public Attributes inherited from YACS::ENGINE::RefCounter
static unsigned int _totalCnt =0
 
- Protected Attributes inherited from YACS::ENGINE::OptimizerAlgBase
Pool_pool
 
Proc_proc
 
std::string _errorMessage
 
int _nbOfBranches
 

Detailed Description

Base class to implement in external dynamic lib or external python module in case of a non event oriented optimizer using Python code.

Definition at line 57 of file PyOptimizerAlg.hxx.

Constructor & Destructor Documentation

PyOptimizerAlgASync::~PyOptimizerAlgASync ( )
virtual

Definition at line 114 of file PyOptimizerAlg.cxx.

115 {
116  if (getThreadStatus() == AlternateThread::UNEXISTING) return;
117 
118  Py_BEGIN_ALLOW_THREADS;
119  try {
120  // Force the thread termination. We must allow Python threads for that because the
121  // thread cleanup includes some Python cleanup.
122  terminateSlaveThread();
123  } catch (const exception & e) {
124  cerr << "Exception happened in PyOptimizerAlgASync destructor: " << e.what() << endl;
125  } catch (...) {
126  cerr << "Unknown exception happened in PyOptimizerAlgASync destructor." << endl;
127  }
128  Py_END_ALLOW_THREADS;
129 }
PyOptimizerAlgASync::PyOptimizerAlgASync ( Pool pool)
protected

Definition at line 109 of file PyOptimizerAlg.cxx.

110  : PyOptimizerAlgBase(pool)
111 {
112 }

Member Function Documentation

void PyOptimizerAlgASync::finishProxy ( )
virtual

Reimplemented from YACS::ENGINE::PyOptimizerAlgBase.

Definition at line 141 of file PyOptimizerAlg.cxx.

References YACS::ENGINE::PyOptimizerAlgBase::finishProxy().

142 {
143  terminateSlaveThread();
145 }
void PyOptimizerAlgASync::run ( void  )
protectedvirtual

_pool->getCurrentId gives the id at the origin of this call. Perform the job of analysing to know what new jobs to do (_pool->pushInSample) or in case of convergence _pool->destroyAll

Definition at line 164 of file PyOptimizerAlg.cxx.

References startToTakeDecision().

165 {
166  GILState gs;
168 }
void PyOptimizerAlgASync::signalMasterAndWait ( )
virtual

Called when optimization has succeed.

Definition at line 157 of file PyOptimizerAlg.cxx.

158 {
159  Py_BEGIN_ALLOW_THREADS;
160  AlternateThread::signalMasterAndWait();
161  Py_END_ALLOW_THREADS;
162 }
void PyOptimizerAlgASync::start ( void  )
protectedvirtual

Implements YACS::ENGINE::OptimizerAlgBase.

Definition at line 147 of file PyOptimizerAlg.cxx.

Referenced by startProxy().

148 {
149  AlternateThread::start();
150 }
void PyOptimizerAlgASync::startProxy ( )
virtual

Reimplemented from YACS::ENGINE::PyOptimizerAlgBase.

Definition at line 131 of file PyOptimizerAlg.cxx.

References start().

132 {
133  start();
134 }
virtual void YACS::ENGINE::PyOptimizerAlgASync::startToTakeDecision ( )
protectedpure virtual

_pool->getCurrentId gives the id at the origin of this call. Perform the job between 2 'condition->wait()' of analysing to know what new jobs to do (_pool->pushInSample) or in case of convergence _pool->destroyAll WARNING ! 'condition->wait()' must be called before any analyse of Pool.

Referenced by run().

void PyOptimizerAlgASync::takeDecision ( )
protectedvirtual

Update _pool attribute before performing anything.

Implements YACS::ENGINE::OptimizerAlgBase.

Definition at line 152 of file PyOptimizerAlg.cxx.

Referenced by takeDecisionProxy().

153 {
154  signalSlaveAndWait();
155 }
void PyOptimizerAlgASync::takeDecisionProxy ( )
virtual

Reimplemented from YACS::ENGINE::PyOptimizerAlgBase.

Definition at line 136 of file PyOptimizerAlg.cxx.

References takeDecision().

137 {
138  takeDecision();
139 }

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