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