00001 /*===========================================================================* 00002 * This file is part of the Abstract Library for Parallel Search (ALPS). * 00003 * * 00004 * ALPS is distributed under the Common Public License as part of the * 00005 * COIN-OR repository (http://www.coin-or.org). * 00006 * * 00007 * Authors: * 00008 * * 00009 * Yan Xu, Lehigh University * 00010 * Ted Ralphs, Lehigh University * 00011 * * 00012 * Conceptual Design: * 00013 * * 00014 * Yan Xu, Lehigh University * 00015 * Ted Ralphs, Lehigh University * 00016 * Laszlo Ladanyi, IBM T.J. Watson Research Center * 00017 * Matthew Saltzman, Clemson University * 00018 * * 00019 * * 00020 * Copyright (C) 2001-2007, Lehigh University, Yan Xu, and Ted Ralphs. * 00021 *===========================================================================*/ 00022 00023 #ifndef AlpsHelperFunctions_h_ 00024 #define AlpsHelperFunctions_h_ 00025 00026 #if defined(NF_DEBGU) 00027 #include <iostream> 00028 #endif 00029 #include <cmath> 00030 00031 #include "CoinTime.hpp" 00032 00033 #include "AlpsTreeNode.h" 00034 00035 //############################################################################# 00036 00038 class TotalWorkload : public std::unary_function<AlpsTreeNode*, void> { 00039 00040 private: 00041 double totalLoad_; 00042 double incVal_; 00043 double rho_; 00044 00045 public: 00046 TotalWorkload(const double incVal, const double rho) 00047 : 00048 totalLoad_(0.0), 00049 incVal_(incVal), 00050 rho_(rho) 00051 {} 00052 00053 void operator()(AlpsTreeNode*& node) { 00054 totalLoad_ += pow(fabs(incVal_ - node->getQuality()), rho_); 00055 } 00056 00057 double result() const { return totalLoad_; } 00058 }; 00059 00060 //############################################################################# 00062 struct DeletePtrObject 00063 { 00064 template<class T> 00065 void operator()(const T* ptr) const 00066 { 00067 delete ptr; 00068 } 00069 }; 00070 00071 //############################################################################# 00073 inline void AlpsSleep(double sec) 00074 { 00075 double start = CoinCpuTime(); 00076 while ( (CoinCpuTime() - start) < sec) { }; 00077 } 00078 #endif