Version: 9.16.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 TypeCode * getTCForInProxy () const
 
virtual TypeCode * getTCForOutProxy () const
 
virtual TypeCode * getTCForAlgoInitProxy () const
 
virtual TypeCode * getTCForAlgoResultProxy () const
 
virtual void initializeProxy (const Any *input)
 
virtual void startProxy ()
 
virtual void takeDecisionProxy ()
 
virtual void finishProxy ()
 
virtual Any * getAlgoResultProxy ()
 
- Public Member Functions inherited from YACS::ENGINE::OptimizerAlgBase
virtual TypeCode * getTCForInProxy () const
 
virtual TypeCode * getTCForOutProxy () const
 
virtual TypeCode * getTCForAlgoInitProxy () const
 
virtual TypeCode * getTCForAlgoResultProxy () const
 
virtual void initializeProxy (const Any *input)
 
virtual void startProxy ()
 
virtual void takeDecisionProxy ()
 
virtual void finishProxy ()
 
virtual Any * getAlgoResultProxy ()
 
virtual void setPool (Pool *pool)
 
virtual void setProc (Proc *proc)
 
virtual Proc * getProc ()
 
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 () const
 

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 TypeCode * getTCForIn () const =0
 returns typecode of type expected as Input. OwnerShip of returned pointer is held by this. More...
 
virtual TypeCode * getTCForOut () const =0
 returns typecode of type expected as Output. OwnerShip of returned pointer is held by this. More...
 
virtual TypeCode * getTCForAlgoInit () const
 returns typecode of type expected for algo initialization. OwnerShip of returned pointer is held by this. More...
 
virtual TypeCode * getTCForAlgoResult () const
 returns typecode of type expected as algo result. OwnerShip of returned pointer is held by this. More...
 
virtual void initialize (const Any *input)
 
virtual void start ()=0
 
virtual void takeDecision ()=0
 Update _pool attribute before performing anything. More...
 
virtual void finish ()
 
virtual Any * getAlgoResult ()
 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
 
- Protected Attributes inherited from YACS::ENGINE::RefCounter
unsigned int _cnt
 

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::~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::PyOptimizerAlgASync ( Pool *  pool)
protected

Definition at line 109 of file PyOptimizerAlg.cxx.

110 : PyOptimizerAlgBase(pool)
111{
112}

Member Function Documentation

◆ finishProxy()

void PyOptimizerAlgASync::finishProxy ( )
virtual

Reimplemented from YACS::ENGINE::PyOptimizerAlgBase.

Definition at line 141 of file PyOptimizerAlg.cxx.

142{
143 terminateSlaveThread();
145}

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

◆ run()

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.

165{
166 GILState gs;
168}
virtual void startToTakeDecision()=0

References startToTakeDecision().

◆ signalMasterAndWait()

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}

◆ start()

void PyOptimizerAlgASync::start ( void  )
protectedvirtual

Implements YACS::ENGINE::OptimizerAlgBase.

Definition at line 147 of file PyOptimizerAlg.cxx.

148{
149 AlternateThread::start();
150}

Referenced by startProxy().

◆ startProxy()

void PyOptimizerAlgASync::startProxy ( )
virtual

Reimplemented from YACS::ENGINE::PyOptimizerAlgBase.

Definition at line 131 of file PyOptimizerAlg.cxx.

132{
133 start();
134}

References start().

◆ startToTakeDecision()

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

◆ takeDecision()

void PyOptimizerAlgASync::takeDecision ( )
protectedvirtual

Update _pool attribute before performing anything.

Implements YACS::ENGINE::OptimizerAlgBase.

Definition at line 152 of file PyOptimizerAlg.cxx.

153{
154 signalSlaveAndWait();
155}

Referenced by takeDecisionProxy().

◆ takeDecisionProxy()

void PyOptimizerAlgASync::takeDecisionProxy ( )
virtual

Reimplemented from YACS::ENGINE::PyOptimizerAlgBase.

Definition at line 136 of file PyOptimizerAlg.cxx.

137{
138 takeDecision();
139}
virtual void takeDecision()
Update _pool attribute before performing anything.

References takeDecision().


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