NLToolbox
src/include/ApproximationBuilder.h
00001 
00011 #ifndef HYBRIDIZATIONSIMPLEX_H_
00012 #define HYBRIDIZATIONSIMPLEX_H_
00013 
00014 #include "utils.h"
00015 #include "DynamicalSystem.h"
00016 #include "LinearSystem.h"
00017 #include "PointerSystem.h"
00018 #include "PolynomialSystem.h"
00019 #include "Hpolyhedron.h"
00020 #include "Box.h"
00021 //#include "CurvatureTensor.h"
00022 
00023 namespace nltool {
00024 
00025 using namespace std;
00026 
00027 enum system_type {
00028         NOT_DEFINED = 1, HESSIAN_CONSTANT = 2, HESSIAN_NOT_CONSTANT = 3
00029 };
00030 
00031 class ApproximationBuilder {
00032 public:
00033 
00034         ApproximationBuilder();
00035 
00042         ApproximationBuilder(int dimension);
00043 
00052         ApproximationBuilder(int dimension, DynamicalSystem* sys,
00053                         bool useT = false);
00054 
00056         virtual ~ApproximationBuilder();
00057 
00067         LinearSystem createApproximation(Hpolyhedron& initialSet,
00068                         Hpolyhedron& approximationDomain, Number errorBound,
00069                         bool& requiresSplitting);
00070 
00077         Simplex createSimplex(Hpolyhedron initialSet, Number error);
00078 
00084         Number computeMaximalCurvature();
00085 
00090         Matrix computeTransformationMatrix();
00091 
00092         /*
00093          * ##########################################
00094          * GETTTERS and SETTERS
00095          * ##########################################
00096          */
00097 
00098         Matrix getTransformation() const;
00099         void setTransformation(Matrix transformation);
00100 
00101         bool isUseTransformation() const;
00102         void setUseTransformation(bool useTransformation);
00103 
00104         double getMaxCurvature() {
00105                 return maxCurvature;
00106         }
00107         void setMaxCurvature(double maxCurvature);
00108 
00109         void setUseDisplacement(bool useDisplacement) {
00110                 this->useDisplacement = useDisplacement;
00111         }
00112 
00113         Box getCurvatureEstimationDomain() const {
00114                 return curvatureEstimationDomain;
00115         }
00116 
00117         void setCurvatureEstimationDomain(Box curvatureEstimationDomain) {
00118                 this->curvatureEstimationDomain = curvatureEstimationDomain;
00119         }
00120 
00121         unsigned getDimension() {
00122                 return dimension;
00123         }
00124 
00125         void setNonlinearSystem(DynamicalSystem* nlsys) {
00126                 if (nonlinearSystem != NULL)
00127                         delete &nonlinearSystem;
00128                 nonlinearSystem = nlsys;
00129                 cout << "dim: " << nonlinearSystem->getDimension() << endl;
00130                 nonlinearSystem->printType();
00131                 nlsys->printType();
00132         }
00133 
00134 private:
00135 
00136         /*
00137          * ##########################################
00138          * TRANSFORMATION MATRIX COMPUTATION
00139          * ##########################################
00140          */
00141 
00147         Matrix computeTransformationMatrix(Matrix &curvature);
00148 
00154         Matrix computeTransformationMatrix(vector<Matrix>& hessian);
00155 
00161         vector<Matrix> computeHessianMatrix();
00162 
00168         Matrix computeCurvatureMatrix(vector<Matrix>& hessian);
00169 
00170         /*
00171          * ##########################################
00172          * SIMPLEX CREATION
00173          * ##########################################
00174          */
00175 
00182         Simplex createRegularSimplex(Number radius, int dimension);
00183 
00189         void alignToDirection(Vertices &points, Vector direction);
00190 
00196         bool placeSimplex(Vertices& points, Hpolyhedron& init,
00197                         Number setMaxSize = 1);
00198 
00204         Vector computeDirectionalVector(Hpolyhedron &initial);
00205 
00211         Vector computeCentroid(Hpolyhedron &poly);
00212 
00218         Vector computeCentroid(Vertices &points);
00219 
00224         void computeCurvatureDomain(Hpolyhedron set);
00225 
00231         void testCurvature(Matrix& curvature, int nbTest = 100);
00232 
00233         // use or not the isotropic transformation to increase the approximation domain volume
00234         bool useTransformation;
00235 
00236         unsigned dimension; // dimension of the system
00237         int type; // information on the system
00238         const Number minCurvature;
00239 
00240         vector<Matrix> cstHessian; //constant hessian matrix list
00241         vector<vector<DynamicalSystem*> > hessian; //not constant hessian matrix
00242         Matrix curvature; //curvature matrix
00243         Matrix transformation; //transformation matrix
00244 
00245         Simplex initialSimplex; //initial equilateral simplex
00246         bool useDisplacement; // use additional displacement when positionning the
00247                                                   //approximation domain around the initial set
00248 
00249         Number maxCurvature; // maximal curvature of the nonlinear system
00250         //TODO: for now we recompute the transformation matrix at each
00251         //              approximation computation for non quadratic system,
00252         //              this should be optimized
00253 
00254         Box curvatureEstimationDomain; // domain where the curvature tensor is computed
00255         Number curvatureEstimationCoef; // a coefficient to determine the size of the curvature estimation domain
00256 
00257         DynamicalSystem* nonlinearSystem;
00258 
00259 };
00260 
00261 // ###############################
00262 // Error Approximation computation
00263 // ###############################
00264 
00265 struct ErrorEstimationParameters {
00266         DynamicalSystem* originalSystem;
00267         DynamicalSystem* approximateSystem;
00268         Hpolyhedron domain;
00269         int indice;
00270 };
00271 
00272 Box estimateApproximationerror(DynamicalSystem* original,
00273                 DynamicalSystem* approximation, Hpolyhedron& domain, Number initialerror);
00274 
00275 }
00276  // namespace nltool
00277 
00278 #endif
00279 
 All Classes Namespaces Functions