00001 #ifndef LLSSOLVER_H
00002 #define LLSSOLVER_H
00003
00018 #ifdef SINGLE
00019 #define real float
00020 #else
00021 #define real double
00022 #endif
00023
00028 #define max(x,y) ((x)>(y)?(x):(y))
00029 #define min(x,y) ((x)<(y)?(x):(y))
00034
00035 extern "C" {
00036
00037
00038
00039
00040 #ifdef SINGLE
00041 void ssvd_(real *G,real *U,real *V,int *M,int *N,
00042 real *W,real *WORK,int *LWORK,int *INFO);
00043 void ssol_(real *U,real *W,real *V,int *M,int *N,
00044 real *rhs,real *aa,real *tmp);
00045 #else
00046 void dsvd_(real *G,real *U,real *V,int *M,int *N,
00047 real *W,real *WORK,int *LWORK,int *INFO);
00048 void dsol_(real *U,real *W,real *V,int *M,int *N,
00049 real *rhs,real *aa,real *tmp);
00050 #endif
00051 }
00052
00053 #include <iostream>
00054 #include <string>
00055 #include <cmath>
00056 #include <ctime>
00057 #include <vector>
00058 #include <stdlib.h>
00059 using namespace std;
00060
00066 class LLSSolver {
00067
00068 public:
00069
00073 LLSSolver();
00074
00088 void solve(int matrixSizeM,
00089 int matrixSizeN,
00090 real *A,
00091 real *b,
00092 real *x,
00093 vector<real> &UFixedParticles,
00094 vector<real> &SFixedParticles,
00095 vector<real> &VFixedParticles,
00096 int &fixedParticles
00097 );
00098
00102 ~LLSSolver();
00103
00104 private:
00105
00106
00107 void calculateUSV(real *);
00108
00109 real * allocate1dArray(int size);
00110
00111 void delete1dArray(real * x);
00112 void releaseMemory();
00113
00114
00115
00116
00117
00118
00119
00120
00121 int m, n;
00122 int i, j, iter;
00123
00124 int nIter;
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 real *U, *V, *S, *tmp;
00136
00137
00138 };
00139
00140 #endif