Helios++
Helios software for LiDAR simulations
BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs > Class Template Reference

The budding task dropper is a task dropper which implements the logic for its own reproduction so buds (children) are modified depending on the difference between last idle time length and current idle time length. More...

#include <BuddingTaskDropper.h>

Inheritance diagram for BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs >:
Collaboration diagram for BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs >:

Public Member Functions

 BuddingTaskDropper (int const maxTasks=32, int const delta1=8, int const initDelta1=8, int const delta2=1, char const lastSign=0)
 Default constructor for the budding task dropper. More...
 
BudType emptyClone () const
 Do an empty clone of this budding task dropper. It is, an exact clone but with an empty tasks vector. More...
 
virtual BudType reproduce (char const sign)
 Do the budding reproduction of current task dropper. More...
 
virtual BudType evolve (long &lastIdle, long const idle, long const idleTh=100000, long const idleEps=100000)
 Create the bud of current budding task dropper according to the defined evolutive criteria. More...
 
virtual char getLastSign () const
 Obtain the last sign of the budding task dropper. More...
 
virtual int getDelta1 () const
 Obtain the \(\Delta_1\) of the budding task dropper. More...
 
virtual int getInitDelta1 () const
 Obtain the init value of \(Delta_1\) of the budding task dropper. More...
 
virtual int getDelta2 () const
 Obtain the \(\Delta_2\) of the budding task dropper. More...
 
- Public Member Functions inherited from TaskDropper< TaskType, ThreadPoolType, TaskArgs... >
 TaskDropper (size_t const maxTasks=32)
 Default constructor for TaskDropper. More...
 
virtual bool add (shared_ptr< TaskType > task)
 Add a task to the TaskDropper. More...
 
virtual bool add (shared_ptr< TaskType > task, TaskArgs ... args)
 Like TaskDropper::add but for tasks with arguments. More...
 
virtual bool add (ThreadPoolType &pool, shared_ptr< TaskType > task)
 Like TaskDropper::add but running the drop method in parallel through a callback from given thread pool. More...
 
virtual char tryAdd (ThreadPoolType &pool, shared_ptr< TaskType > task)
 Like TaskDropper::add(ThreadPoolType &, shared_ptr<TaskType>) but supporting non-blocking calls. More...
 
virtual void drop ()
 Drop all tasks, one after another. More...
 
virtual void drop (TaskArgs ... args)
 Drop all tasks with arguments, one after another. More...
 
virtual void drop (ThreadPoolType &pool)
 A callback for TaskDropper::drop but using a thread pool to be executed in parallel. More...
 
virtual bool tryDrop (ThreadPoolType &pool)
 Like drop(ThreadPoolType &) but supporting non blocking calls. More...
 
TaskDropper emptyClone () const
 Do an empty clone of this task dropper. It is, an exact clone but with an empty tasks vector. More...
 
virtual void operator() ()
 Void functor operator calling drop method to be compatible with thread pools. More...
 
virtual void operator() (TaskArgs ... args)
 Functor operator with arguments calling drop method with arguments which can be used by thread pools. More...
 
virtual size_t getMaxTasks () const
 Get current maximum tasks limit. More...
 
virtual void setMaxTasks (size_t const maxTasks)
 Set new maximum tasks limit. More...
 
virtual shared_ptr< TaskType > popTask ()
 Pop a task from vector of tasks. More...
 

Protected Attributes

int delta1
 Magnitude of increase/decrease for max tasks. More...
 
int initDelta1
 The initial value of \(\Delta_1\).
 
int delta2
 Magnitude of increase/decrease for \(\Delta_1\). More...
 
char lastSign
 Must be \(0\) at initial instance but then it should be either \(1\) or \(-1\).
 
- Protected Attributes inherited from TaskDropper< TaskType, ThreadPoolType, TaskArgs... >
std::vector< shared_ptr< TaskType > > tasks
 Tasks to be dropped as a whole. More...
 
size_t maxTasks
 Specify the maximum number of tasks before forcing a drop. More...
 

Additional Inherited Members

- Protected Member Functions inherited from TaskDropper< TaskType, ThreadPoolType, TaskArgs... >
virtual void doTask (TaskType &task)
 Execute a task with no arguments. More...
 
virtual void doTask (TaskType &task, TaskArgs ... args)
 Execute a task with corresponding arguments. More...
 

Detailed Description

template<typename BudType, typename TaskType, typename ThreadPoolType, typename ... TaskArgs>
class BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs >

The budding task dropper is a task dropper which implements the logic for its own reproduction so buds (children) are modified depending on the difference between last idle time length and current idle time length.

The responsibility of measuring idle time lengths lies outside this class scope. A budding task dropper implements the logic of how to work with idle times, but it does not provide a mechanism to do such measurements.

To understand how budding task dropper works, let \(\epsilon\) be the minimum magnitude of a measurement so any measurement \(<\epsilon\) will be discarded. Let \(\tau\) be the threshold defining the significance of a measurement and let \(\Delta_1\) and \(\Delta_2\) be the parameters defining the behavior of a budding task dropper. Notice the \(\Delta_1\) of the source budding task dropper (the first one, which has no father) will be noted as \(\Delta_0\). Also, let \(t_a\) be the last idle time length and \(t_b\) be the current idle time length. Thus, if \(B_a\) is the parent budding task dropper and \(B_b\) is the child budding task dropper, the last can be defined as:

\[ B_b \approx \left\{\begin{array}{lll} B_a &,& t_b < \tau \\ r\left(B_a, {\mathrm{sgn}(t_a-t_b)s}\right) &,& t_b \geq \tau \land \left\vert{t_a-t_b}\right\vert > \epsilon \\ r\left(B_a, s\right) &,& t_b \geq \tau \land \left\vert{t_a-t_b}\right\vert \leq \epsilon \\ \end{array}\right. \]

Where \(B_b \approx B_a\) means \(B_b\) is exactly equal to \(B_a\) except for the vector of tasks. On the other hand, let \(m\) be the chunk size (max tasks) and \(s\) be the sign of \(B_a\) so the reproduce function \(r\) can be defined as:

\[ r\left(B_a, s^{'}\right) = r\left(\left[\begin{array}{c} m \\ \Delta_1 \\ \Delta_2 \\ s \end{array}\right], s^{'}\right) = B_b = \left[\begin{array}{l} m^{'} \\ \Delta_1^{'} \\ \Delta_2^{'} \\ s^{'} \end{array}\right] = \left[\begin{array}{c} m + s^{'} \delta\left({\Delta_1}, s, s^{'}\right) \\ \delta\left({\Delta_1}, s, s^{'}\right) \\ \Delta_2, \\ s{'} \end{array}\right] \]

Finally, \(\delta(\Delta_1, s, s^{'})\) works as follows:

\[ \delta\left({\Delta_1, s, s^{'}}\right) = \left\{\begin{array}{lll} \Delta_1 + \Delta_2 &,& s=s^{'} \\ \Delta_0 &,& s \neq s^{'} \end{array}\right. \]

Template Parameters
BudTypeType of bud. Classes extending budding task dropper should specify themselves as the bud type.
See also
TaskDropper
BuddingTaskDropper::evolve
BuddingTaskDropper::reproduce

Constructor & Destructor Documentation

◆ BuddingTaskDropper()

template<typename BudType , typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs >::BuddingTaskDropper ( int const  maxTasks = 32,
int const  delta1 = 8,
int const  initDelta1 = 8,
int const  delta2 = 1,
char const  lastSign = 0 
)
inline

Default constructor for the budding task dropper.

Parameters
stepSizeMagnitude of increase/decrease in max tasks
stepFactorScale ratio for consecutive step sizes
lastSignValue of last sign. For the first instance of a chain of buds, its last sign will also be the first sign of the chain
See also
TaskDropper::maxTasks
TaskDropper

Member Function Documentation

◆ emptyClone()

template<typename BudType , typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
BudType BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs >::emptyClone ( ) const
inline

Do an empty clone of this budding task dropper. It is, an exact clone but with an empty tasks vector.

Returns
Empty clone of this budding task dropper

◆ evolve()

template<typename BudType , typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual BudType BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs >::evolve ( long &  lastIdle,
long const  idle,
long const  idleTh = 100000,
long const  idleEps = 100000 
)
inlinevirtual

Create the bud of current budding task dropper according to the defined evolutive criteria.

Parameters
lastIdleThe last idle time length. It will be modified if a significant change occurs so the new last idle time is the one given as current idle time.
idleCurrent idle time length, it is the one which comes after last idle time length
idleThThreshold defining used to define whether a measurement is significant or not
idleEpsMinimum magnitude of a measurement so those below it will be discarded
Returns
Bud satisfying evolution criteria

◆ getDelta1()

template<typename BudType , typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual int BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs >::getDelta1 ( ) const
inlinevirtual

Obtain the \(\Delta_1\) of the budding task dropper.

Returns
\(\Delta_1\) of budding task dropper
See also
BuddingTaskDropper::delta1

◆ getDelta2()

template<typename BudType , typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual int BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs >::getDelta2 ( ) const
inlinevirtual

Obtain the \(\Delta_2\) of the budding task dropper.

Returns
\(\Delta_2\) of budding task dropper
See also
BuddingTaskDropper::delta2

◆ getInitDelta1()

template<typename BudType , typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual int BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs >::getInitDelta1 ( ) const
inlinevirtual

Obtain the init value of \(Delta_1\) of the budding task dropper.

Returns
Init value of \(Delta_1\) of budding task dropper
See also
BuddingTaskDropper::initDelta1

◆ getLastSign()

template<typename BudType , typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual char BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs >::getLastSign ( ) const
inlinevirtual

Obtain the last sign of the budding task dropper.

Returns
Last sign of budding task dropper
See also
BuddingTaskDropper::lastSign

◆ reproduce()

template<typename BudType , typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
virtual BudType BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs >::reproduce ( char const  sign)
inlinevirtual

Do the budding reproduction of current task dropper.

Template Parameters
BudTypeType of child
Parameters
signSign defining the evolutionary sense of the reproduction operation
Returns
Bud child of current budding task dropper

Member Data Documentation

◆ delta1

template<typename BudType , typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
int BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs >::delta1
protected

Magnitude of increase/decrease for max tasks.

\[ \Delta_1 \]

See also
BuddingTaskDropper::delta2

◆ delta2

template<typename BudType , typename TaskType , typename ThreadPoolType , typename ... TaskArgs>
int BuddingTaskDropper< BudType, TaskType, ThreadPoolType, TaskArgs >::delta2
protected

Magnitude of increase/decrease for \(\Delta_1\).

\[ \Delta_2 \]

See also
BuddingTaskDropper:delta1

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