Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

annotation.h

Go to the documentation of this file.
00001 // Annotation implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2001-2003 Hermann Schichl
00004 //
00005 // This file is part of the COCONUT API.  This library
00006 // is free software; you can redistribute it and/or modify it under the
00007 // terms of the Library GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // Library GNU General Public License for more details.
00015 
00016 // As a special exception, you may use this file as part of a free software
00017 // library without restriction.  Specifically, if other files instantiate
00018 // templates or use macros or inline functions from this file, or you compile
00019 // this file and link it with other files to produce an executable, this
00020 // file does not by itself cause the resulting executable to be covered by
00021 // the Library GNU General Public License.  This exception does not however
00022 // invalidate any other reasons why the executable file might be covered by
00023 // the Library GNU General Public License.
00024 
00027 #ifndef _ANNOTATION_H_
00028 #define _ANNOTATION_H_
00029 
00030 // FIXED by IRIN as of 08/11/2002
00031 // + re-ordered and/or completed the initialization lists
00032 // + added the assignment operators that raise an exception
00033 // + added the copy constructors
00034 // + fixed memory leaks set_best, set_global_best 
00035 
00036 #include <interval.h>
00037 #include <vector>
00038 #include <coconut_config.h>
00039 #include <database>
00040 
00041 using namespace vgtl;
00042 
00043 #if 0
00044 class point
00045 {
00046 private:
00047   std::vector<double> x;
00048   std::vector<double> L_mult;
00049   double f;
00050   double kappa;
00051 
00052   bool best;
00053   bool verified;
00054   bool feasible;
00055   bool optimal;
00056   bool global;
00057 
00058 public:
00059   point() : x(), L_mult(), f(INFINITY), kappa(1.), best(false), verified(false),
00060             feasible(false), optimal(false), global(false)
00061   {}
00062 
00063   point(const std::vector<double>& _x, double _f) : x(_x), L_mult(),
00064                                          f(_f), kappa(1.), best(false),
00065                                          verified(false), feasible(false),
00066                                          optimal(false), global(false)
00067   {}
00068 
00069   point(const std::vector<double>& _x, double _f, const std::vector<double>&
00070         _Lm, double _kappa, bool _best = false, bool _feas = false,
00071         bool _opt = false, bool _ver = false, bool _glob = false) :
00072                                                x(_x), L_mult(_Lm), f(_f),
00073                                                kappa(_kappa),
00074                                                best(_best), verified(_ver),
00075                                                feasible(_feas), optimal(_opt),
00076                                                global(_glob)
00077   {}
00078 
00079   point(const point& _p) : x(_p.x), L_mult(_p.L_mult), f(_p.f), kappa(_p.kappa),
00080                            best(_p.best), verified(_p.verified),
00081                            feasible(_p.feasible), optimal(_p.optimal),
00082                            global(_p.global)
00083   {}
00084 
00085   virtual ~point() {}
00086 
00087 public:
00088   void set_best(bool _best) { best = _best; }
00089   void set_verified(bool _ver) { verified = _ver; }
00090   void set_feasible(bool _feas) { feasible = _feas; }
00091   void set_optimal(bool _opt) { optimal = _opt; }
00092   void set_global(bool _glob) { global = _glob; }
00093 
00094   void set_val(const std::vector<double>& _x, double _f) { x = _x; f = _f;}
00095   void set_multiplier(const std::vector<double>& _Lm, double _kappa = 1.)
00096         { L_mult = _Lm; kappa = _kappa; }
00097 
00098   void clear_multiplier()
00099         { L_mult.erase(L_mult.begin(), L_mult.end()); kappa = 1.; }
00100 
00101   bool is_empty() const { return x.empty(); }
00102 
00103   bool is_best() const { return best; }
00104   bool is_verified() const { return verified; }
00105   bool is_feasible() const { return feasible; }
00106   bool is_optimal() const { return optimal; }
00107   bool is_global() const { return global; }
00108 
00109   bool have_multiplier() const { return !L_mult.empty(); }
00110   
00111   const std::vector<double>& xval() const { return x; }
00112   double fval() const { return f; }
00113   const std::vector<double>& multiplier() const { return L_mult; }
00114   double kval() const { return kappa; }
00115 
00116   bool operator==(const point& _p)
00117   {
00118     return best == _p.best &&
00119            verified == _p.verified &&
00120            feasible == _p.feasible &&
00121            optimal == _p.optimal &&
00122            global == _p.global &&
00123            f == _p.f &&
00124            L_mult == _p.L_mult &&
00125            x == _p.x;
00126   }
00127 };
00128 
00129 class box
00130 {
00131 private:
00132   std::vector<interval> x;
00133 
00134   bool _exclusion;
00135   bool _contains_opt;
00136   bool _eval_region;
00137 
00138 public:
00139   box() : x(), _exclusion(false), _contains_opt(false), _eval_region(false)
00140   {}
00141 
00142   box(const std::vector<interval>& _x, bool _excl = false,
00143       bool _copt = false, bool _evr = false) :
00144                x(_x), _exclusion(_excl), _contains_opt(_copt),
00145                _eval_region(_evr)
00146   {}
00147 
00148   virtual ~box() {}
00149 
00150 public:
00151   void set_val(const std::vector<interval>& _x) { x = _x; }
00152 
00153   void set_exclusion(bool _exc) { _exclusion = _exc; }
00154   void set_contains_opt(bool _copt) { _contains_opt = _copt; }
00155   void set_eval_region(bool _evr) { _eval_region = _evr; }
00156 
00157   const std::vector<interval>& val() const { return x; }
00158 
00159   bool is_empty() const { return x.empty(); }
00160 
00161   bool is_exclusion_box() const { return _exclusion; }
00162   bool contains_opt() const { return _contains_opt; }
00163   bool is_eval_region() const { return _eval_region; }
00164 
00165   bool operator==(const box& _b)
00166   {
00167     return _exclusion == _b._exclusion &&
00168            _contains_opt == _b._contains_opt &&
00169            _eval_region == _b._eval_region &&
00170            x == _b.x;
00171   }
00172 };
00173 
00174 class annotation
00175 {
00176 public:
00177   point pt;                        // best point for this model
00178 
00179   bool local_is_global;            // best local point is global minimizer
00180 
00181   std::vector<double> priorities;  // when should this model be taken
00182 
00183   bool infeasible;
00184 
00185 public:
00186   annotation(annotation const &a) : pt(a.pt),
00187                         local_is_global(a.local_is_global),
00188                         priorities(a.priorities), infeasible(a.infeasible)
00189     {}
00190 
00191   annotation() : pt(), local_is_global(false), priorities(),
00192                  infeasible(false)
00193     {}
00194 
00195   annotation& operator= (annotation const& a)
00196   {
00197     pt = a.pt;
00198     local_is_global = a.local_is_global;
00199     priorities = a.priorities;
00200     infeasible = a.infeasible;
00201     // std :: cout << "Assignment of annotation" << std :: endl;
00202     // throw "in annotation :: operator = : cannot assign annotations";
00203     return *this;
00204   }
00205 
00206   // and others needed
00207   ~annotation() {}
00208 
00209   void set_best(const std::vector<double>& __xb,
00210                 const std::vector<double>& __Lm, double __fx,
00211                 bool _ver = false, bool _opt = false, bool _glob = false)
00212   {
00213     pt.set_best(true);
00214     pt.set_val(__xb, __fx);
00215     pt.set_multiplier(__Lm);
00216     pt.set_feasible(true);
00217     pt.set_verified(_ver);
00218     pt.set_optimal(_opt);
00219     pt.set_global(_glob);
00220   }
00221 
00222   void set_point(const point& _p) { pt = _p; }
00223 
00224   const point& get_point() const { return pt; }
00225 };
00226 
00227 class work_annotation : public annotation
00228 {
00229 private:
00230   typedef annotation _Base;
00231 
00232 public:
00233   typedef std::vector<point>::iterator point_chg;
00234   typedef std::vector<box>::iterator box_chg;
00235 
00236   typedef std::vector<point>::const_iterator point_ref;
00237   typedef std::vector<box>::const_iterator box_ref;
00238   
00239   std::vector<point> points;
00240   std::vector<box> boxes;
00241 
00242   work_annotation() : _Base(), points(), boxes()
00243       {}
00244 
00245   work_annotation(const work_annotation& a ) : _Base(a),
00246                                 points(a.points), boxes(a.boxes)
00247       {}
00248 
00249   work_annotation& operator= (const work_annotation& a)
00250   {
00251     _Base::operator=(a);
00252     points = a.points;
00253     boxes = a.boxes;
00254     return *this;
00255   }
00256 
00257   ~work_annotation() {}
00258 
00259   void set_global_best(const std::vector<double>& __xb,
00260                        const std::vector<double>& __Lm, double __fx,
00261                        bool verified = false, bool optimal = false,
00262                        bool replace_all = false)
00263   {
00264     for(unsigned int i = points.size(); i != 0; --i)
00265     {
00266       point_chg pr = points.begin()+i-1;
00267       if(pr->is_best() && pr->is_global() && 
00268           (replace_all || pr->fval() > __fx))
00269         points.erase(pr);
00270     }
00271 
00272     point p(__xb, __fx, __Lm, true, true, optimal, verified, true);
00273     points.push_back(p);
00274   }
00275 
00276   point_ref get_global_best() const
00277   {
00278     point_ref pr;
00279 
00280     for(pr = points.begin(); pr != points.end(); ++pr)
00281       if(pr->is_best() && pr->is_global())
00282         return pr;
00283     return pr;
00284   }
00285 
00286   std::vector<point_ref> get_all_global_best() const
00287   {
00288     std::vector<point_ref> pv;
00289 
00290     for(point_ref pr = points.begin(); pr != points.end(); ++pr)
00291       if(pr->is_best() && pr->is_global())
00292         pv.push_back(pr);
00293     return pv;
00294   }
00295 
00296   std::vector<box_ref> get_all_exclusion_boxes() const
00297   {
00298     std::vector<box_ref> bv;
00299 
00300     for(box_ref br = boxes.begin(); br != boxes.end(); ++br)
00301       if(br->is_exclusion_box())
00302         bv.push_back(br);
00303     return bv;
00304   }
00305 };
00306 #endif
00307 
00308 class annotation : public std::pair<vdbl::tableid,vdbl::rowid>
00309 {
00310 private:  
00311   typedef std::pair<vdbl::tableid,vdbl::rowid> _Base;
00312 
00313 public:
00314   annotation(const vdbl::tableid& _ti, const vdbl::rowid& _ri) : _Base(_ti,_ri)
00315         {}
00316   virtual ~annotation() {}
00317 
00318   vdbl::tableid get_table() const { return first; }
00319   vdbl::rowid get_entry() const { return second; }
00320 };
00321 
00322 #endif // _ANNOTATION_H

Generated on Tue Nov 4 01:57:56 2003 for COCONUT API by doxygen1.2.18