sampling.h

Go to the documentation of this file.
00001 // Copyright (C) 2006 Ivo Nowak and Stefan Vigerske
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Author: Stefan Vigerske
00006 
00007 #ifndef SAMPLING_H
00008 #define SAMPLING_H
00009 
00010 #include "standard.h"
00011 #include "problem.h"
00012 #include "func.h"
00013 #include "opt.h"
00014 
00039 class Sampling {
00046         friend ostream& operator<<(ostream& out, const Sampling& s) {
00047                 s.print(out);
00048                 return out;
00049         }
00050 
00051         protected:
00054                 int montecarlo;
00057                 int vertices;
00060                 bool midpoint;
00063                 bool bounds;
00064 
00065         public:
00070                 Sampling(Pointer<Param> param=NULL, const char* param_prefix=NULL);
00071                 
00075                 virtual ~Sampling() { }
00076                 
00083                 virtual int get_points(vector<dvector>& sample_set, const UserVector<double>& lower, const UserVector<double>& upper);
00084                 
00091                 void get_points(vector<vector<dvector> >& sample_set, const UserVector<double>& lower, const UserVector<double>& upper, const vector<ivector>& block) {
00092                         assert(sample_set.size()==block.size());
00093                         for (int k=0; k<block.size(); k++) get_points(sample_set[k], lower(block[k]), upper(block[k]));
00094                 }
00095 
00102                 Pointer<vector<vector<dvector> > > get_points(const UserVector<double>& lower, const UserVector<double>& upper, const vector<ivector>& block) {
00103                         Pointer<vector<vector<dvector> > > ss(new vector<vector<dvector> >(block.size()));
00104                         get_points(*ss, lower, upper, block);
00105                         return ss;
00106                 }
00107 
00111                 virtual void print(ostream& out) const {
00112                         out << "Montecarlo points: " << montecarlo << endl
00113                             << "Vertices points  : " << vertices << endl
00114                             << "Midpoint         : " << (midpoint ? "yes" : "no") << endl
00115                           << "Bounds           : " << (bounds ? "yes" : "no") << endl
00116                         ;
00117                 }
00118 
00119 };
00120 
00129 class Sampling_Vertices {
00130         public:
00134                 int vertices;
00135 
00140                 Sampling_Vertices(Pointer<Param> param=NULL, const char* param_prefix=NULL);
00141 
00142                 void get_points(vector<vector<dvector> >& sample_set, const UserVector<double>& lower, const UserVector<double>& upper, const vector<ivector>& block, const vector<Pointer<set<int> > >& i_quad, const vector<Pointer<set<int> > > &i_nonquadlin);
00143 
00144                 void get_points(vector<vector<dvector> >& sample_set, const UserVector<double>& lower, const UserVector<double>& upper, const SepQcFunc& f);
00145 
00156                 int get_points(vector<dvector>& sample_set, const UserVector<double>& lower, const UserVector<double>& upper, set<int>& i_quad, set<int>& i_nonquadlin);
00157 
00158                 int get_points(vector<dvector>& sample_set, const UserVector<double>& lower, const UserVector<double>& upper, const SparsityInfo& si);
00159 
00160                 int get_points(vector<dvector>& sample_set, const UserVector<double>& lower, const UserVector<double>& upper);
00161 };
00162 
00179 class SimpleEquationSolver : public Solver {
00180         private:
00181                 const Func& f;
00182                 const UserVector<double>& lower;
00183                 const UserVector<double>& upper;
00184 
00185                 int bisection_iter_max;
00186 
00193                 int run(const dvector& start, double val, dvector& dir);
00194 
00195         public:
00196                 SimpleEquationSolver(const Func& f_, const UserVector<double>& lower_, const UserVector<double>& upper_, Pointer<Param> param=NULL)
00197                 : Solver(f_.dim()), f(f_), lower(lower_), upper(upper_)
00198                 { iter_max=param ? param->get_i("SimpleEquationSolver max iter", 4) : 4;
00199                   tol=param ? param->get_d("SimpleEquationSolver tolerance", 1e-4) : 1e-4;
00200                         bisection_iter_max=param ? param->get_i("SimpleEquationSolver bisection max iter", 1000) : 1000;
00201                 }
00202 
00203                 int solve(dvector& start);
00204 
00205                 int solve() {
00206                         dvector start(lower); start+=upper; start*=.5;
00207                         return solve(start);
00208                 }
00209 
00210 
00211 };
00212 
00216 class Sampling_check {
00217         private:
00218                 Pointer<Param> param;
00219 
00220         public:
00223                 Sampling_check(Pointer<Param> param_)
00224                 : param(param_)
00225                 { }
00226 
00241                 void check(vector<vector<dvector> >& sample_set, const SepQcFunc& f, bool eq, const vector<Pointer<set<int> > >& i_lin, const UserVector<double>& lower, const UserVector<double>& upper, const vector<int>& start, int min_keep=0);
00242 
00243                 void check(vector<vector<dvector> >& sample_set, const SepQcFunc& f, bool eq, const UserVector<double>& lower, const UserVector<double>& upper, const vector<int>& start, int min_keep);
00244 };
00245 
00260 class Sampling_Minimizer {
00261         private:
00262                 bool minimizer;
00263                 Pointer<Param> param;
00264 
00265         public:
00270                 Sampling_Minimizer(Pointer<Param> param_=NULL, const char* param_prefix=NULL);
00271 
00279                 bool add_minimizer(vector<vector<dvector> >& sample_set, Pointer<SepQcFunc> f, const UserVector<double>& lower, const UserVector<double>& upper);
00280 
00281                 bool add_minimizer(vector<dvector>& sample_set, Pointer<Func> f, const UserVector<double>& lower, const UserVector<double>& upper, dvector& start);
00282 };
00283 
00284 #endif

Generated on Tue Oct 21 03:12:10 2008 for LaGO by  doxygen 1.4.7