1 #ifndef GLOBAL_H 2 #define GLOBAL_H 3 4 #include "nlopt-util.h" 5 6 #include <queue> 7 //#include "function.h" 8 #include "tools.h" 9 using namespace std; 10 11 extern "C" int stogo_verbose; 12 13 typedef void dom(RTBox) ; 14 typedef dom* Pdom ; 15 16 typedef double obj(RCRVector) ; 17 typedef obj* Pobj ; 18 19 typedef void grad(RCRVector,RVector&) ; 20 typedef grad* Pgrad ; 21 22 typedef enum { OBJECTIVE_ONLY, GRADIENT_ONLY, OBJECTIVE_AND_GRADIENT } whichO; 23 24 typedef double objgrad(RCRVector,RCRVector,whichO) ; 25 typedef objgrad* Pobjgrad ; 26 27 class GlobalParams { 28 public: 29 #ifdef NLOPT_UTIL_H 30 nlopt_stopping *stop; 31 #else 32 double maxtime; 33 long int maxeval; 34 #endif 35 double eps_cl, mu, rshift; 36 int det_pnts, rnd_pnts; 37 }; 38 39 class Global: public GlobalParams { 40 public: 41 // Problem specification 42 int dim ; 43 Pobj Objective ; 44 Pgrad Gradient ; 45 long int numeval; 46 ObjectiveGradient(RCRVector xy,RVector & grad,whichO which)47 virtual double ObjectiveGradient(RCRVector xy, RVector&grad, whichO which){ 48 ++numeval; 49 switch (which) { 50 case OBJECTIVE_AND_GRADIENT: 51 Gradient(xy, grad); 52 case OBJECTIVE_ONLY: 53 return Objective(xy); 54 case GRADIENT_ONLY: 55 Gradient(xy, grad); 56 } 57 return 0.0; 58 } 59 60 Global(RTBox, Pobj, Pgrad, GlobalParams); 61 // Global& operator=(const Global &); 62 63 void Search(int, RCRVector); 64 void DispMinimizers(); 65 double OneMinimizer(RCRVector); 66 bool NoMinimizers(); 67 void SetDomain(RTBox); 68 void GetDomain(RTBox); 69 double GetMinValue(); 70 void SetMinValue(double); 71 void ClearSolSet(); 72 void AddPoint(RCRVector, double); 73 74 double GetTime(); 75 bool InTime(); 76 77 private: 78 list<Trial> SolSet; 79 list<Trial>::const_iterator titr; 80 priority_queue<TBox> CandSet; 81 priority_queue<TBox> Garbage; 82 83 double fbound; 84 TBox Domain; 85 86 void FillRegular(RTBox, RTBox); 87 void FillRandom(RTBox, RTBox); 88 double NewtonTest(RTBox, int, RCRVector, int*); 89 void ReduceOrSubdivide(RTBox, int, RCRVector); 90 }; 91 #endif 92 93