Helios++
Helios software for LiDAR simulations
BuddingTaskDropper.h
1 #pragma once
2 
3 #include <util/threadpool/TaskDropper.h>
4 
70 template <
71  typename BudType,
72  typename TaskType,
73  typename ThreadPoolType,
74  typename ... TaskArgs
75 >
77  public TaskDropper<TaskType, ThreadPoolType, TaskArgs...>
78 {
79 protected:
80  // *** ATTRIBUTES *** //
81  // ******************** //
91  int delta1;
105  int delta2;
110  char lastSign;
111 
112 public:
113  // *** CONSTRUCTION / DESTRUCTION *** //
114  // ************************************ //
125  int const maxTasks=32,
126  int const delta1=8,
127  int const initDelta1=8,
128  int const delta2=1,
129  char const lastSign=0
130  ):
131  TaskDropper<TaskType, ThreadPoolType, TaskArgs...> (maxTasks),
132  delta1(delta1),
134  delta2(delta2),
136  {}
137  virtual ~BuddingTaskDropper() = default;
138  // *** TASK DROPPER METHODS *** //
139  // ***************************** //
145  inline BudType emptyClone() const {
146  return BudType(
147  this->maxTasks,
148  delta1,
149  initDelta1,
150  delta2,
151  lastSign
152  );
153  }
154 
155  // *** BUDDING METHODS *** //
156  // ************************* //
164  virtual BudType reproduce(char const sign){
165  // Null step size means bud will be a clone
166  if(delta1 == 0){
167  return BudType(
168  this->maxTasks,
169  delta1,
170  initDelta1,
171  delta2,
172  lastSign
173  );
174  }
175 
176  // Configure bud
177  int delta1Bud = delta1;
178  if(lastSign!=0){
179  if(lastSign==sign){
180  delta1Bud += delta2;
181  }
182  else{
183  delta1Bud = initDelta1;
184  }
185  }
186 
187  // Build and return bud
188  return BudType(
189  std::max<int>(1, this->maxTasks + sign * delta1Bud),
190  delta1Bud,
191  initDelta1,
192  delta2,
193  sign
194  );
195  }
196 
211  virtual BudType evolve(
212 #ifdef BUDDING_METRICS
213  bool &debugBuddingMetrics,
214 #endif
215  long &lastIdle,
216  long const idle,
217  long const idleTh=100000,
218  long const idleEps=100000
219  ){
220  if(idle < idleTh){ // No significant idle time
221 #ifdef BUDDING_METRICS
222  debugBuddingMetrics=false;
223 #endif
224  return emptyClone(); // No mutating budding
225  }
226 #ifdef BUDDING_METRICS
227  debugBuddingMetrics=true;
228 #endif
229 
230  // Significant idle time, determine evolving sense (sign)
231  bool const sigChange = std::abs(idle-lastIdle) > idleEps;
232  if(sigChange){ // If significant change
233  char sign = (idle > lastIdle) ? -lastSign : lastSign;
234  if(sign == 0) sign = 1;
235  lastIdle = idle;
236  return reproduce(sign); // Evolve through budding
237  }
238  else{ // If no significant change
239  return reproduce(lastSign);
240  }
241  }
242 
243  // *** GETTERs and SETTERs *** //
244  // ***************************** //
250  virtual inline char getLastSign() const {return lastSign;}
256  virtual inline int getDelta1() const {return delta1;}
263  virtual inline int getInitDelta1() const {return initDelta1;}
269  virtual inline int getDelta2() const {return delta2;}
270 };
The budding task dropper is a task dropper which implements the logic for its own reproduction so bud...
Definition: BuddingTaskDropper.h:78
virtual int getDelta2() const
Obtain the of the budding task dropper.
Definition: BuddingTaskDropper.h:269
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.
Definition: BuddingTaskDropper.h:124
BudType emptyClone() const
Do an empty clone of this budding task dropper. It is, an exact clone but with an empty tasks vector.
Definition: BuddingTaskDropper.h:145
virtual char getLastSign() const
Obtain the last sign of the budding task dropper.
Definition: BuddingTaskDropper.h:250
virtual int getInitDelta1() const
Obtain the init value of of the budding task dropper.
Definition: BuddingTaskDropper.h:263
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.
Definition: BuddingTaskDropper.h:211
int delta1
Magnitude of increase/decrease for max tasks.
Definition: BuddingTaskDropper.h:91
char lastSign
Must be at initial instance but then it should be either or .
Definition: BuddingTaskDropper.h:110
virtual int getDelta1() const
Obtain the of the budding task dropper.
Definition: BuddingTaskDropper.h:256
int delta2
Magnitude of increase/decrease for .
Definition: BuddingTaskDropper.h:105
virtual BudType reproduce(char const sign)
Do the budding reproduction of current task dropper.
Definition: BuddingTaskDropper.h:164
int initDelta1
The initial value of .
Definition: BuddingTaskDropper.h:95
Class which handles tasks dropping. It is, executing and then removing each task when dropping.
Definition: TaskDropper.h:22
size_t maxTasks
Specify the maximum number of tasks before forcing a drop.
Definition: TaskDropper.h:39