AlpsHelperFunctions.h
Go to the documentation of this file.
1 /*===========================================================================*
2  * This file is part of the Abstract Library for Parallel Search (ALPS). *
3  * *
4  * ALPS is distributed under the Eclipse Public License as part of the *
5  * COIN-OR repository (http://www.coin-or.org). *
6  * *
7  * Authors: *
8  * *
9  * Yan Xu, Lehigh University *
10  * Ted Ralphs, Lehigh University *
11  * *
12  * Conceptual Design: *
13  * *
14  * Yan Xu, Lehigh University *
15  * Ted Ralphs, Lehigh University *
16  * Laszlo Ladanyi, IBM T.J. Watson Research Center *
17  * Matthew Saltzman, Clemson University *
18  * *
19  * *
20  * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs. *
21  *===========================================================================*/
22 
23 #ifndef AlpsHelperFunctions_h_
24 #define AlpsHelperFunctions_h_
25 
26 #if defined(NF_DEBGU)
27 #include <iostream>
28 #endif
29 #include <cmath>
30 
31 #include "CoinTime.hpp"
32 
33 #include "AlpsTreeNode.h"
34 
35 //#############################################################################
36 
38 class TotalWorkload : public std::unary_function<AlpsTreeNode*, void> {
39 
40  private:
41  double totalLoad_;
42  double incVal_;
43  double rho_;
44 
45  public:
46  TotalWorkload(const double incVal, const double rho)
47  :
48  totalLoad_(0.0),
49  incVal_(incVal),
50  rho_(rho)
51  {}
52 
53  void operator()(AlpsTreeNode*& node) {
54  totalLoad_ += pow(fabs(incVal_ - node->getQuality()), rho_);
55  }
56 
57  double result() const { return totalLoad_; }
58 };
59 
60 //#############################################################################
63 {
64  template<class T>
65  void operator()(const T* ptr) const
66  {
67  delete ptr;
68  }
69 };
70 
71 //#############################################################################
73 inline void AlpsSleep(double sec)
74 {
75  double start = CoinCpuTime();
76  while ( (CoinCpuTime() - start) < sec) { };
77 }
78 #endif
TotalWorkload(const double incVal, const double rho)
double result() const
A functor class used in calulating total workload in a node pool.
void operator()(const T *ptr) const
void operator()(AlpsTreeNode *&node)
void AlpsSleep(double sec)
Delay for the specified seconds.
This class holds one node of the search tree.
Definition: AlpsTreeNode.h:50
static double CoinCpuTime()
Definition: CoinTime.hpp:106
double getQuality() const
Query/set the quality of the node.
Definition: AlpsTreeNode.h:218