Compounds | |
struct | guma::bbt_node |
class | guma::kdnnrec |
class | guma::kdrec |
class | guma::kdtnode |
class | guma::kdtsearch |
class | guma::kdtsnode |
class | guma::newton_info |
class | guma::random_des |
class | guma::rkdtree |
class | guma::rkdtree_base |
Typedefs | |
typedef guma::bbt_node | BBTNode |
Functions | |
template<class T> GULAPI bool | GaussJordan (int nRowsCols, int nRightSides, Ptr< Ptr< T > > &A, Ptr< Ptr< T > > &b) |
Solve systems of linear equations with Gauss Jordan Elimination. More... | |
template GULAPI bool | GaussJordan (int nRowsCols, int m, Ptr< Ptr< float > > &A, Ptr< Ptr< float > > &b) |
template GULAPI bool | GaussJordan (int nRowsCols, int m, Ptr< Ptr< double > > &A, Ptr< Ptr< double > > &b) |
template<class T> GULAPI bool | LUDecomposition (int nRowsCols, Ptr< Ptr< T > > &A, int *perm_sign, Ptr< int > &index) |
Decompose a matrix into lower and upper triangular matrix. More... | |
template GULAPI bool | LUDecomposition (int nRowsCols, Ptr< Ptr< float > > &A, int *perm_sign, Ptr< int > &index) |
template GULAPI bool | LUDecomposition (int nRowsCols, Ptr< Ptr< double > > &A, int *perm_sign, Ptr< int > &index) |
template<class T> GULAPI void | LUBackSubstitution (int nRowsCols, Ptr< int > &index, Ptr< Ptr< T > > &A, Ptr< T > &b) |
Solve system of linear equations with help of LU-Decomposition (given in A). More... | |
template GULAPI void | LUBackSubstitution (int nRowsCols, Ptr< int > &index, Ptr< Ptr< float > > &A, Ptr< float > &b) |
template GULAPI void | LUBackSubstitution (int nRowsCols, Ptr< int > &index, Ptr< Ptr< double > > &A, Ptr< double > &b) |
template<class T> GULAPI void | BandMVProduct (int n, int m1, int m2, Ptr< Ptr< T > > a, Ptr< T > x, Ptr< T > b) |
Multiply a band matrix and a vector: b = A*x, m1 = number of subdiagonal elements, m2 = number of superdiagonal elements, n = number of rows. More... | |
template GULAPI void | BandMVProduct (int n, int m1, int m2, Ptr< Ptr< float > > a, Ptr< float > x, Ptr< float > b) |
template GULAPI void | BandMVProduct (int n, int m1, int m2, Ptr< Ptr< double > > a, Ptr< double > x, Ptr< double > b) |
template<class T> GULAPI void | BandDecomposition (int n, int m1, int m2, Ptr< Ptr< T > > &A, Ptr< Ptr< T > > &L, int *perm_sign, Ptr< int > &index) |
Decompose a band matrix into lower and upper triangular matrix: A = L*U. More... | |
template GULAPI void | BandDecomposition (int n, int m1, int m2, Ptr< Ptr< float > > &A, Ptr< Ptr< float > > &L, int *perm_sign, Ptr< int > &index) |
template GULAPI void | BandDecomposition (int n, int m1, int m2, Ptr< Ptr< double > > &A, Ptr< Ptr< double > > &L, int *perm_sign, Ptr< int > &index) |
template<class T> GULAPI void | BandBackSubstitution (int n, int m1, int m2, const Ptr< Ptr< T > > &A, const Ptr< Ptr< T > > &L, const Ptr< int > &index, Ptr< T > &b) |
Solve system of linear equations with help of LU-Decomposition of a band matrix (given by L and A). More... | |
template GULAPI void | BandBackSubstitution (int n, int m1, int m2, const Ptr< Ptr< float > > &A, const Ptr< Ptr< float > > &L, const Ptr< int > &index, Ptr< float > &b) |
template GULAPI void | BandBackSubstitution (int n, int m1, int m2, const Ptr< Ptr< double > > &A, const Ptr< Ptr< double > > &L, const Ptr< int > &index, Ptr< double > &b) |
template<class T> GULAPI void | SVDecomposition (int m, int n, Ptr< Ptr< T > > &a, Ptr< T > &w, Ptr< Ptr< T > > &v) |
Singular Value Decomposition. More... | |
template GULAPI void | SVDecomposition (int m, int n, Ptr< Ptr< float > > &a, Ptr< float > &w, Ptr< Ptr< float > > &v) |
template GULAPI void | SVDecomposition (int m, int n, Ptr< Ptr< double > > &a, Ptr< double > &w, Ptr< Ptr< double > > &v) |
template<class T> GULAPI void | SVBackSubstitution (int m, int n, Ptr< Ptr< T > > &u, Ptr< T > &w, Ptr< Ptr< T > > &v, Ptr< T > &b, Ptr< T > &x) |
Solve system of linear equations, when a Singular Value Decomposition is given. More... | |
template GULAPI void | SVBackSubstitution (int m, int n, Ptr< Ptr< float > > &u, Ptr< float > &w, Ptr< Ptr< float > > &v, Ptr< float > &b, Ptr< float > &x) |
template GULAPI void | SVBackSubstitution (int m, int n, Ptr< Ptr< double > > &u, Ptr< double > &w, Ptr< Ptr< double > > &v, Ptr< double > &b, Ptr< double > &x) |
template<class T> GULAPI void | SVBackSubstitution (int m, int n, Ptr< Ptr< T > > &u, Ptr< T > &w, Ptr< Ptr< T > > &v, Ptr< T > &b) |
Solve system of linear equations, when a Singular Value Decomposition is given. More... | |
template GULAPI void | SVBackSubstitution (int m, int n, Ptr< Ptr< float > > &u, Ptr< float > &w, Ptr< Ptr< float > > &v, Ptr< float > &b) |
template GULAPI void | SVBackSubstitution (int m, int n, Ptr< Ptr< double > > &u, Ptr< double > &w, Ptr< Ptr< double > > &v, Ptr< double > &b) |
template<class T> GULAPI bool | SVZero (int n, Ptr< T > &w) |
Sets very small singular values to zero. More... | |
template GULAPI bool | SVZero (int n, Ptr< float > &w) |
template GULAPI bool | SVZero (int n, Ptr< double > &w) |
template<class T> int | SVDIntersectLines (point< T > P1, point< T > T1, point< T > P2, point< T > T2, T *alpha1, T *alpha2, point< T > *P) |
Intersect two lines in 3-dimensions, using singular decomposition. More... | |
template int | SVDIntersectLines (point< float > P1, point< float > T1, point< float > P2, point< float > T2, float *alpha1, float *alpha2, point< float > *P) |
template int | SVDIntersectLines (point< double > P1, point< double > T1, point< double > P2, point< double > T2, double *alpha1, double *alpha2, point< double > *P) |
template<class T> T | Pythagoras (const T &a, const T &b) |
Calculate (a^2 + b^2)^{1/2}, with precautions to avoid destructive over- or underflow. More... | |
template<class T> bool | GoldenSectionSearch (T ax, T bx, T cx, T(*func)(T, void *), void *fdat, T tol, int max_iterations, T *xmin, T *fmin) |
Searches the minimum of a function, defined over an intervall. More... | |
template bool | GoldenSectionSearch (float ax, float bx, float cx, float(*func)(float, void *), void *, float tol, int max_iterations, float *xmin, float *fmin) |
template bool | GoldenSectionSearch (double ax, double bx, double cx, double(*func)(double, void *), void *, double tol, int max_iterations, double *xmin, double *fmin) |
template<class T> bool | LinearSearch (const Ptr< T > &p, const Ptr< T > &xold, T fold, const Ptr< T > &g, const Ptr< T > &x1, const Ptr< T > &x2, newton_info< T > &I, bool &found, bool &check, Ptr< T > &x, T *fx) |
template bool | LinearSearch (const Ptr< float > &p, const Ptr< float > &xold, float fold, const Ptr< float > &g, const Ptr< float > &x1, const Ptr< float > &x2, newton_info< float > &I, bool &found, bool &check, Ptr< float > &x, float *fx) |
template<class T> bool | Newton (Ptr< T > &x, const Ptr< T > &x1, const Ptr< T > &x2, newton_info< T > &I, int maxits) |
template bool | Newton (Ptr< float > &x, const Ptr< float > &x1, const Ptr< float > &x2, newton_info< float > &I, int maxits) |
template bool | Newton (Ptr< double > &x, const Ptr< double > &x1, const Ptr< double > &x2, newton_info< double > &I, int maxits) |
GULAPI uint32 | GetSeed () |
GULAPI void | PseudoDes (uint32 *lword, uint32 *irword) |
GULAPI void | HeapSort (size_t nelem, size_t elsize, void *elptr, int(*usrfunc)(void *, void *, void *), void *usrdata) |
GULAPI void | PtrHeapSort (size_t nelem, void **elptr, int(*usrfunc)(void *, void *, void *), void *usrdata) |
GULAPI void | heapsort (int nA, Ptr< void *> &A) |
GULAPI void | heapsort (int nA, Ptr< int > &A) |
GULAPI int | BinarySearch (int x, int nA, const gul::Ptr< int > &A) |
GULAPI int | BinarySearch (void *x, int nA, const gul::Ptr< void *> &A) |
GULAPI void | InitBBT (BBTNode *head) |
GULAPI int | SearchElementInBBT (BBTNode *head, void *key, int compare(void *, void *), BBTNode **element) |
GULAPI BBTNode * | SearchSuccessorInBBT (BBTNode *element, BBTNode *head) |
GULAPI BBTNode * | SearchPredecessorInBBT (BBTNode *element, BBTNode *head) |
GULAPI void | InsertElementIntoBBT (BBTNode *element, BBTNode *where, int side, BBTNode *head) |
GULAPI void | DeleteElementFromBBT (BBTNode *element, BBTNode *head) |
GULAPI void | DumpBBTTree (BBTNode *node, int level, void dumpkey_func(void *)) |
GULAPI void | DumpBBTNode (BBTNode *node, int level) |
template<class T> void | _heapsort (int nA, gul::Ptr< T > &A) |
template<class T> int | _BinarySearch (T x, int nA, const gul::Ptr< T > &A) |
template<class T> int | _BinarySearch (T x, int nA, const gul::Ptr< T > &A, int *rleft, int *rright) |
template<class U> void | CommonCoordinateSystem (const point< U > &B, const point< U > &P, const point< U > &Ab, const point< U > &Pb, Ptr< Ptr< U > > &T) |
template void | CommonCoordinateSystem (const point< float > &B, const point< float > &P, const point< float > &Ab, const point< float > &Pb, Ptr< Ptr< float > > &T) |
template void | CommonCoordinateSystem (const point< double > &B, const point< double > &P, const point< double > &Ab, const point< double > &Pb, Ptr< Ptr< double > > &T) |
template<class U> void | CommonCoordinateSystem (const gul::point< U > &B, const gul::point< U > &P, const gul::point< U > &Ab, const gul::point< U > &Pb, gul::Ptr< gul::Ptr< U > > &T) |
|
|
Definition at line 219 of file guma_sorting.h.
00221 { 00222 int mid,right,left; 00223 00224 if( nA == 0 ) 00225 { 00226 *rleft = -1; 00227 *rright = -1; 00228 return -1; 00229 } 00230 00231 if( A[0] >= x ) 00232 { 00233 *rright = 0; 00234 00235 if( A[0] > x ) 00236 { 00237 *rleft = -1; 00238 return -1; 00239 } 00240 else 00241 { 00242 *rleft = 0; 00243 return 0; 00244 } 00245 } 00246 00247 if( A[nA-1] <= x ) 00248 { 00249 *rleft = nA-1; 00250 00251 if( A[nA-1] < x ) 00252 { 00253 *rright = -1; 00254 return -1; 00255 } 00256 else 00257 { 00258 *rright = nA-1; 00259 return nA-1; 00260 } 00261 } 00262 00263 left = 0; 00264 right = nA; 00265 mid = (left+right)/2; 00266 00267 while( (mid!=left) && (mid!=right) ) 00268 { 00269 if( A[mid] == x ) 00270 break; 00271 else if( A[mid] > x ) 00272 { 00273 right = mid; 00274 mid = (left+right)>>1; 00275 } 00276 else 00277 { 00278 left = mid; 00279 mid = (left+right)>>1; 00280 } 00281 } 00282 if( A[mid] != x ) 00283 { 00284 *rleft = left; 00285 *rright = right; 00286 return -1; 00287 } 00288 else 00289 { 00290 *rleft = mid; 00291 *rright = mid; 00292 } 00293 00294 return mid; 00295 } |
|
Definition at line 168 of file guma_sorting.h.
00169 { 00170 int mid,right,left; 00171 00172 if( nA == 0 ) return -1; 00173 00174 if( A[0] >= x ) 00175 { 00176 if( A[0] > x ) return -1; 00177 return 0; 00178 } 00179 if( A[nA-1] <= x ) 00180 { 00181 if( A[nA-1] < x ) return -1; 00182 return nA-1; 00183 } 00184 00185 left = 0; 00186 right = nA; 00187 mid = (left+right)/2; 00188 00189 while( (mid!=left) && (mid!=right) ) 00190 { 00191 if( A[mid] == x ) 00192 break; 00193 else if( A[mid] > x ) 00194 { 00195 right = mid; 00196 mid = (left+right)>>1; 00197 } 00198 else 00199 { 00200 left = mid; 00201 mid = (left+right)>>1; 00202 } 00203 } 00204 if( A[mid] != x ) return -1; 00205 00206 return mid; 00207 } |
|
Definition at line 109 of file guma_sorting.h.
00110 { 00111 gul::Ptr<T>& ra = A; 00112 T rra; 00113 int n = nA, l, ir, i, j; 00114 00115 if( n < 2 ) return; 00116 l = (n >> 1) + 1; 00117 ir = n; 00118 00119 for(;;) 00120 { 00121 if( l > 1 ) 00122 { 00123 rra = ra[l-2]; 00124 l--; 00125 } 00126 else 00127 { 00128 rra = ra[ir-1]; 00129 ra[ir-1] = ra[0]; 00130 00131 if( --ir == 1 ) 00132 { 00133 ra[0] = rra; 00134 break; 00135 } 00136 } 00137 i = l; 00138 j = l+l; 00139 00140 while( j <= ir ) 00141 { 00142 if( (j < ir) && (ra[j-1] < ra[j]) ) 00143 j++; 00144 00145 if( rra < ra[j-1] ) 00146 { 00147 ra[i-1] = ra[j-1]; 00148 i = j; 00149 j <<= 1; 00150 } 00151 else 00152 j = ir + 1; 00153 } 00154 00155 ra[i-1] = rra; 00156 } 00157 } |
|
|
|
|
|
Solve system of linear equations with help of LU-Decomposition of a band matrix (given by L and A).
Definition at line 393 of file guma_lineq.cpp.
00396 { 00397 int i,k,l,mm; 00398 T dum; 00399 00400 mm = m1 + m2 + 1; 00401 l = m1; 00402 00403 for( k = 0; k < n; k++ ) /* Forward substitution */ 00404 { 00405 i = index[k]; 00406 if( i != k ) Swap( b[k], b[i] ); 00407 if( l < n ) l++; 00408 for( i = k+1; i < l; i++ ) 00409 b[i] -= L[k][i-k-1]*b[k]; 00410 } 00411 l = 1; 00412 for( i = n-1; i >= 0; i-- ) /* Forward substitution */ 00413 { 00414 dum = b[i]; 00415 for( k = 1; k < l; k++ ) 00416 dum -= A[i][k]*b[k+i]; 00417 b[i] = dum/A[i][0]; 00418 if( l < mm ) l++; 00419 } 00420 } |
|
|
|
|
|
Decompose a band matrix into lower and upper triangular matrix: A = L*U. m1 = number of subdiagonal elements, m2 = number of superdiagonal elements, n = number of rows and columns. L is returned in L[0..n-1][0..m1-1], U in the input matrix A; the rowwise permutation from pivoting is returned in 'index', its sign in 'perm_sign'. Definition at line 320 of file guma_lineq.cpp.
00323 { 00324 int i,j,k,l,mm,d; 00325 T dum; 00326 00327 mm = m1 + m2 + 1; 00328 l = m1; 00329 for( i = 0; i < m1; i++ ) 00330 { 00331 for( j = m1-i; j < mm; j++ ) 00332 A[i][j-l] = A[i][j]; 00333 l--; 00334 for( j = mm-l-1; j < mm; j++ ) 00335 A[i][j] = 0.0; 00336 } 00337 d = 1; 00338 l = m1; 00339 00340 for( k = 0; k < n; k++ ) 00341 { 00342 dum = A[k][0]; 00343 i = k; 00344 00345 if( l < n ) l++; 00346 for( j = k+1; j < l; j++ ) 00347 { 00348 if( rtr<T>::fabs(A[j][0]) > rtr<T>::fabs(dum) ) 00349 { 00350 dum = A[j][0]; 00351 i = j; 00352 } 00353 } 00354 index[k] = i; 00355 00356 if( dum == 0.0 ) /* if algorithmically singular */ 00357 A[k][0] = rtr<T>::tiny(); 00358 00359 if( i != k ) /* interchange rows */ 00360 { 00361 d = -d; 00362 for( j = 0; j < mm; j++ ) 00363 Swap( A[k][j], A[i][j] ); 00364 } 00365 00366 for( i = k+1; i < l; i++ ) // i = i'+1 00367 { 00368 dum = A[i][0]/A[k][0]; 00369 L[k][i-k-1] = dum; 00370 00371 for( j = 1; j < mm; j++ ) 00372 A[i][j-1] = A[i][j] - dum*A[k][j]; 00373 00374 A[i][mm-1] = 0.0; 00375 } 00376 } 00377 *perm_sign = d; 00378 } |
|
|
|
|
|
Multiply a band matrix and a vector: b = A*x, m1 = number of subdiagonal elements, m2 = number of superdiagonal elements, n = number of rows. It demonstrates the indexing scheme for band matrices Definition at line 286 of file guma_lineq.cpp.
00288 { 00289 int i,k,j,m; 00290 00291 for( i = 0; i < n; i++ ) 00292 { 00293 k = i - m1; 00294 00295 m = Min(m1+m2+1,n-k); 00296 00297 b[i] = 0; 00298 00299 for( j = Max(0,-k); j < m; j++ ) 00300 b[i] += a[i][j] * x[j+k]; 00301 } 00302 } |
|
Definition at line 153 of file guma_sorting.cpp.
00154 { return _BinarySearch( x, nA, A); } |
|
Definition at line 151 of file guma_sorting.cpp.
00152 { return _BinarySearch( x, nA, A); } |
|
|
|
|
|
|
|
Definition at line 49 of file guma_transform.cpp. Referenced by GUL_CommonCoordinateSystem().
00052 { 00053 point<U> a1,a2,a3,b1,b2,b3; 00054 Ptr< Ptr<U> > Ta,Tb; 00055 int i; 00056 00057 Ta.reserve_pool(3); 00058 Tb.reserve_pool(3); 00059 for( i = 0; i < 3; i++ ) 00060 { 00061 Ta[i].reserve_pool(3); 00062 Tb[i].reserve_pool(3); 00063 } 00064 00065 normalize( &a1, B ); 00066 normalize( &a2, P-((P*a1)*a1) ); 00067 normalize( &a3, cross_product(a1,a2) ); 00068 00069 normalize( &b1, -Ab ); 00070 normalize( &b2, P-((P*b1)*b1) ); 00071 normalize( &b3, cross_product(b1,b2) ); 00072 00073 Tb[0][0] = b1[0]; Tb[0][1] = b1[1]; Tb[0][2] = b1[2]; 00074 Tb[1][0] = b2[0]; Tb[1][1] = b2[1]; Tb[1][2] = b2[2]; 00075 Tb[2][0] = b3[0]; Tb[2][1] = b3[1]; Tb[2][2] = b3[2]; 00076 00077 GaussJordan( 3, 0, Tb, Tb ); 00078 00079 Ta[0][0] = a1[0]; Ta[0][1] = a1[1]; Ta[0][2] = a1[2]; 00080 Ta[1][0] = a2[0]; Ta[1][1] = a2[1]; Ta[1][2] = a2[2]; 00081 Ta[2][0] = a3[0]; Ta[2][1] = a3[1]; Ta[2][2] = a3[2]; 00082 00083 MMProduct( 3, 3, 3, Tb, Ta, T ); 00084 00085 T[3][0] = B[0]; T[3][1] = B[1]; T[3][2] = B[2]; T[3][3] = (U)1; 00086 T[0][3] = T[1][3] = T[2][3] = (U)0; 00087 } |
|
Definition at line 601 of file guma_sorting.cpp. Referenced by gul::RefMap::RemoveNode(), gul::Map< kdnnrec< U, V > >::RemoveNode(), and gugr::edge_interval_tree::RemoveNode().
00602 { 00603 BBTNode *P,*Q,*Pk,*Pk_1,*A,*B,*X; 00604 int ak, ak_1, ak_ini; 00605 00606 P = head->right; 00607 if( P == NULL ) return; 00608 00609 P = Q = element; 00610 00611 if( P->right == NULL ) /* Knoten suchen, bei dem rechter oder */ 00612 { /* linker Ast = NULL: */ 00613 Pk = P; 00614 ak = 1; 00615 Pk_1 = Pk->parent; 00616 ak_1 = ak_ini = Pk->F.l; 00617 } 00618 else if( P->left == NULL ) 00619 { 00620 Pk = P; 00621 ak = -1; 00622 Pk_1 = Pk->parent; 00623 ak_1 = ak_ini = Pk->F.l; 00624 } 00625 else 00626 { 00627 P = P->right; /* nach rechts gehen */ 00628 00629 if( P->left == NULL ) 00630 { 00631 Pk = Q; 00632 00633 if( Q->F.l == 1 ) 00634 { 00635 Q->parent->right = P; 00636 P->F.l = 1; 00637 } 00638 else 00639 { 00640 Q->parent->left = P; 00641 P->F.l = -1; 00642 } 00643 P->parent = Q->parent; 00644 P->F.b = Q->F.b; 00645 00646 ak = 1; 00647 Pk_1 = P; 00648 ak_1 = -1; 00649 ak_ini = 1; 00650 } 00651 else 00652 { 00653 do /* suchen bis Nachfolger in symmetrischer */ 00654 { /* Ordnung gefunden */ 00655 Pk = P; 00656 P = P->left; 00657 } 00658 while( P != NULL ); 00659 00660 ak = -1; 00661 Pk_1 = Pk->parent; 00662 ak_1 = ak_ini = Pk->F.l; 00663 } 00664 } 00665 00666 /* --- Knoten loeschen: -------------------------------------------- */ 00667 00668 if( ak_1 == -1 ) /* wenn Pk linker Sohn */ 00669 { 00670 Pk_1->left = (ak == -1 ? Pk->right : Pk->left); 00671 if( Pk_1->left != NULL ) 00672 { 00673 Pk_1->left->parent = Pk_1; 00674 Pk_1->left->F.l = -1; 00675 } 00676 } 00677 else 00678 { 00679 Pk_1->right = (ak == -1 ? Pk->right : Pk->left); 00680 if( Pk_1->right != NULL ) 00681 { 00682 Pk_1->right->parent = Pk_1; 00683 Pk_1->right->F.l = 1; 00684 } 00685 } 00686 00687 if( Pk != Q ) 00688 { 00689 Pk->left = Q->left; /* Pk uebernimmt nun die Rolle von Q */ 00690 if( Pk->left != NULL ) 00691 Pk->left->parent = Pk; 00692 Pk->right = Q->right; 00693 if( Pk->right != NULL ) 00694 Pk->right->parent = Pk; 00695 00696 Pk->F.b = Q->F.b; 00697 00698 Pk->parent = Q->parent; 00699 Pk->F.l = Q->F.l; 00700 if( Pk->F.l == -1 ) 00701 Pk->parent->left = Pk; 00702 else 00703 Pk->parent->right = Pk; 00704 } 00705 /* Q kann jetzt freigeben werden */ 00706 00707 /* --- Balance-Faktoren updaten ------------------------------------- */ 00708 00709 ak = ak_ini; 00710 Pk = Pk_1; 00711 00712 while( 1 ) 00713 { 00714 if( Pk == head ) /* Listenkopf */ 00715 { 00716 (*((int *)&head->left))--; /* Hoehe des Baums um 1 erniedrigen */ 00717 break; /*** fertig ***/ 00718 } 00719 else if( Pk->F.b == ak ) 00720 { 00721 Pk->F.b = 0; 00722 00723 ak = Pk->F.l; /* k-- */ 00724 Pk = Pk->parent; 00725 } 00726 else if( Pk->F.b == 0 ) 00727 { 00728 Pk->F.b = -ak; 00729 break; /*** fertig ***/ 00730 } 00731 else /* rebalancieren erforderlich, */ 00732 { /* da (Pk->B == -ak) */ 00733 if( ak == -1 ) /*** Ausfuehrung fuer (ak == -1) ***/ 00734 { 00735 A = Pk; 00736 ak_1 = Pk->F.l; 00737 Pk_1 = Pk->parent; 00738 00739 B = A->right; /* B = Zweig auf der anderen Seite */ 00740 00741 if( B->F.b == 1 ) /* B->B == -ak => Single Rotation */ 00742 { 00743 A->right = B->left; /* LINK(A,-ak) = LINK(B,ak) */ 00744 if( A->right != NULL ) 00745 { 00746 A->right->parent = A; 00747 A->right->F.l = 1; 00748 } 00749 00750 B->left = A; /* LINK(B,ak) = A */ 00751 if( B->left != NULL ) 00752 { 00753 B->left->parent = B; 00754 B->left->F.l = -1; 00755 } 00756 00757 A->F.b = B->F.b = 0; 00758 00759 ak = ak_1; /* k-- */ 00760 Pk = Pk_1; 00761 00762 if( ak == -1 ) 00763 { 00764 Pk->left = B; 00765 if( Pk->left != NULL ) 00766 { 00767 Pk->left->parent = Pk; 00768 Pk->left->F.l = -1; 00769 } 00770 } 00771 else 00772 { 00773 Pk->right = B; 00774 if( Pk->right != NULL ) 00775 { 00776 Pk->right->parent = Pk; 00777 Pk->right->F.l = 1; 00778 } 00779 } 00780 } 00781 else if( B->F.b == -1 ) /* (B->B == ak) => Double Rotation */ 00782 { 00783 X = B->left; /* X = LINK(B,ak) */ 00784 00785 A->right = X->left; /* LINK(A,-ak) = LINK(X,ak) */ 00786 if( A->right != NULL ) 00787 { 00788 A->right->parent = A; 00789 A->right->F.l = 1; 00790 } 00791 00792 B->left = X->right; /* LINK(B,ak) = LINK(X,-ak) */ 00793 if( B->left != NULL ) 00794 { 00795 B->left->parent = B; 00796 B->left->F.l = -1; 00797 } 00798 00799 X->left = A; /* LINK(X,ak) = A */ 00800 if( X->left != NULL ) 00801 { 00802 X->left->parent = X; 00803 X->left->F.l = -1; 00804 } 00805 00806 X->right = B; /* LINK(X,-ak) = B */ 00807 if( X->right != NULL ) 00808 { 00809 X->right->parent = X; 00810 X->right->F.l = 1; 00811 } 00812 00813 if( X->F.b == -1 ) /* (X->B == ak) */ 00814 { 00815 A->F.b = 0; /* A->B = 0 */ 00816 B->F.b = 1; /* B->B = -ak */ 00817 } 00818 else if( X->F.b == 1 ) /* (X->B == -ak) */ 00819 { 00820 A->F.b = -1; /* A->B = ak */ 00821 B->F.b = 0; /* B->B = 0 */ 00822 } 00823 else /* B->B = 0 */ 00824 { 00825 A->F.b = 0; 00826 B->F.b = 0; 00827 } 00828 X->F.b = 0; 00829 00830 ak = ak_1; /* k-- */ 00831 Pk = Pk_1; 00832 00833 if( ak == -1 ) 00834 { 00835 Pk->left = X; 00836 if( Pk->left != NULL ) 00837 { 00838 Pk->left->parent = Pk; 00839 Pk->left->F.l = -1; 00840 } 00841 } 00842 else 00843 { 00844 Pk->right = X; 00845 if( Pk->right != NULL ) 00846 { 00847 Pk->right->parent = Pk; 00848 Pk->right->F.l = 1; 00849 } 00850 } 00851 } 00852 else /* (B->B == 0) => Single Rotation */ 00853 { 00854 A->right = B->left; /* LINK(A,-ak) = LINK(B,ak) */ 00855 if( A->right != NULL ) 00856 { 00857 A->right->parent = A; 00858 A->right->F.l = 1; 00859 } 00860 00861 B->left = A; /* LINK(B,ak) = A */ 00862 if( B->left != NULL ) 00863 { 00864 B->left->parent = B; 00865 B->left->F.l = -1; 00866 } 00867 00868 B->F.b = -1; /* B->B = ak */ 00869 00870 ak = ak_1; /* k-- */ 00871 Pk = Pk_1; 00872 00873 if( ak == -1 ) 00874 { 00875 Pk->left = B; 00876 if( Pk->left != NULL ) 00877 { 00878 Pk->left->parent = Pk; 00879 Pk->left->F.l = -1; 00880 } 00881 } 00882 else 00883 { 00884 Pk->right = B; 00885 if( Pk->right != NULL ) 00886 { 00887 Pk->right->parent = Pk; 00888 Pk->right->F.l = 1; 00889 } 00890 } 00891 00892 break; /*** fertig ***/ 00893 } 00894 00895 00896 } 00897 else /*** dasselbe nochmal fuer (ak == +1) ***/ 00898 { 00899 A = Pk; 00900 ak_1 = Pk->F.l; 00901 Pk_1 = Pk->parent; 00902 00903 B = A->left; /* B = Zweig auf der anderen Seite */ 00904 00905 if( B->F.b == -1 ) /* (B->B == -ak) => Single Rotation */ 00906 { 00907 A->left = B->right; /* LINK(A,-ak) = LINK(B,ak) */ 00908 if( A->left != NULL ) 00909 { 00910 A->left->parent = A; 00911 A->left->F.l = -1; 00912 } 00913 00914 B->right = A; 00915 if( B->right != NULL ) 00916 { 00917 B->right->parent = B; 00918 B->right->F.l = 1; 00919 } 00920 00921 A->F.b = B->F.b = 0; 00922 00923 ak = ak_1; /* k-- */ 00924 Pk = Pk_1; 00925 00926 if( ak == -1 ) 00927 { 00928 Pk->left = B; 00929 if( Pk->left != NULL ) 00930 { 00931 Pk->left->parent = Pk; 00932 Pk->left->F.l = -1; 00933 } 00934 } 00935 else 00936 { 00937 Pk->right = B; 00938 if( Pk->right != NULL ) 00939 { 00940 Pk->right->parent = Pk; 00941 Pk->right->F.l = 1; 00942 } 00943 } 00944 } 00945 else if( B->F.b == 1 ) /* (B->B == ak) => Double Rotation */ 00946 { 00947 X = B->right; /* X = LINK(B,ak) */ 00948 00949 A->left = X->right; /* LINK(A,-ak) = LINK(X,ak) */ 00950 if( A->left != NULL ) 00951 { 00952 A->left->parent = A; 00953 A->left->F.l = -1; 00954 } 00955 00956 B->right = X->left; /* LINK(B,ak) = LINK(X,-ak) */ 00957 if( B->right != NULL ) 00958 { 00959 B->right->parent = B; 00960 B->right->F.l = 1; 00961 } 00962 00963 X->right = A; /* LINK(X,ak) = A */ 00964 if( X->right != NULL ) 00965 { 00966 X->right->parent = X; 00967 X->right->F.l = 1; 00968 } 00969 00970 X->left = B; /* LINK(X,-ak) = B */ 00971 if( X->left != NULL ) 00972 { 00973 X->left->parent = X; 00974 X->left->F.l = -1; 00975 } 00976 00977 if( X->F.b == 1 ) /* (X->B == ak) */ 00978 { 00979 A->F.b = 0; /* A->B = 0 */ 00980 B->F.b = -1; /* B->B = -ak */ 00981 } 00982 else if( X->F.b == -1 ) /* (X->B == -ak) */ 00983 { 00984 A->F.b = 1; /* A->B = ak */ 00985 B->F.b = 0; /* B->B = 0 */ 00986 } 00987 else /* B->B = 0 */ 00988 { 00989 A->F.b = 0; 00990 B->F.b = 0; 00991 } 00992 X->F.b = 0; 00993 00994 ak = ak_1; /* k-- */ 00995 Pk = Pk_1; 00996 00997 if( ak == -1 ) 00998 { 00999 Pk->left = X; 01000 if( Pk->left != NULL ) 01001 { 01002 Pk->left->parent = Pk; 01003 Pk->left->F.l = -1; 01004 } 01005 } 01006 else 01007 { 01008 Pk->right = X; 01009 if( Pk->right != NULL ) 01010 { 01011 Pk->right->parent = Pk; 01012 Pk->right->F.l = 1; 01013 } 01014 } 01015 } 01016 else /* (B->B == 0) => Single Rotation */ 01017 { 01018 A->left = B->right; /* LINK(A,-ak) = LINK(B,ak) */ 01019 if( A->left != NULL ) 01020 { 01021 A->left->parent = A; 01022 A->left->F.l = -1; 01023 } 01024 01025 B->right = A; /* LINK(B,ak) = A */ 01026 if( B->right != NULL ) 01027 { 01028 B->right->parent = B; 01029 B->right->F.l = 1; 01030 } 01031 01032 B->F.b = 1; /* B->B = ak */ 01033 01034 ak = ak_1; /* k-- */ 01035 Pk = Pk_1; 01036 01037 if( ak == -1 ) 01038 { 01039 Pk->left = B; 01040 if( Pk->left != NULL ) 01041 { 01042 Pk->left->parent = Pk; 01043 Pk->left->F.l = -1; 01044 } 01045 } 01046 else 01047 { 01048 Pk->right = B; 01049 if( Pk->right != NULL ) 01050 { 01051 Pk->right->parent = Pk; 01052 Pk->right->F.l = 1; 01053 } 01054 } 01055 01056 break; /*** fertig ***/ 01057 } 01058 } 01059 } /*** Ende "while"-Schleife ***/ 01060 } 01061 01062 return; 01063 } |
|
Definition at line 1097 of file guma_sorting.cpp.
01098 { 01099 int i; 01100 01101 if( node == NULL ) 01102 return; 01103 01104 if( node->left != NULL ) 01105 DumpBBTNode( node->left, level+4 ); 01106 01107 for( i = 0; i < level; i++ ) 01108 { 01109 cout << " "; 01110 } 01111 cout << (void *)node << ":[b:" << node->F.b << ", l:" << node->F.l << 01112 "] (l=" << (void *)node->left << ", r=" << 01113 (void *)node->right << ", p=" << (void *)node->parent << ")\n"; 01114 01115 if( node->right != NULL ) 01116 DumpBBTNode( node->right, level+4 ); 01117 } |
|
Definition at line 1069 of file guma_sorting.cpp.
01071 { 01072 int i; 01073 01074 if( node == NULL ) 01075 return; 01076 01077 if( node->left != NULL ) 01078 DumpBBTTree( node->left, level+4, dumpkey_func ); 01079 01080 for( i = 0; i < level; i++ ) 01081 { 01082 cout << " "; 01083 } 01084 01085 if( node->key != NULL ) 01086 dumpkey_func( node->key ); 01087 cout << "\n"; 01088 01089 if( node->right != NULL ) 01090 DumpBBTTree( node->right, level+4, dumpkey_func ); 01091 } |
|
|
|
|
|
Solve systems of linear equations with Gauss Jordan Elimination. (A)nn * (b')nm = (b)nm (A)nn * (A')nn = (1)nn After that, matrix 'A' contains the inverse matrix of 'A', and the columns of 'b' contain the solution vectors of the different right sides in 'b'. (see "Numerical Recipes in C") Definition at line 59 of file guma_lineq.cpp.
00061 { 00062 Ptr<int> indexc,indexr; 00063 Ptr<T> ipivot; 00064 int icol,irow, n,i,j,k,l,ll,m; 00065 T big,pivotinv,dummy; 00066 00067 n = nRowsCols - 1; 00068 m = nRightSides - 1; 00069 00070 indexc.reserve_pool(n+1); 00071 indexr.reserve_pool(n+1); 00072 ipivot.reserve_pool(n+1); 00073 00074 for( j = 0; j <= n; j++ ) 00075 ipivot[j] = 0; 00076 00077 for( i = 0; i <= n; i++ ) 00078 { 00079 big = 0.0; 00080 00081 for( j = 0; j <= n; j++ ) 00082 { 00083 if( ipivot[j] != 1 ) 00084 { 00085 for( k = 0; k <= n; k++ ) 00086 { 00087 if( ipivot[k] == 0 ) 00088 { 00089 if( rtr<T>::fabs( A[j][k] ) >= big ) 00090 { 00091 big = rtr<T>::fabs( A[j][k] ); 00092 irow = j; 00093 icol = k; 00094 } 00095 } 00096 else if( ipivot[k] > 1 ) 00097 return false; 00098 } 00099 } 00100 } 00101 ipivot[icol]++; 00102 00103 if( irow != icol ) 00104 { 00105 for( l = 0; l <= n; l++ ) 00106 Swap( A[irow][l], A[icol][l] ); 00107 for( l = 0; l <= m; l++ ) 00108 Swap( b[irow][l], b[icol][l] ); 00109 } 00110 indexr[i] = irow; 00111 indexc[i] = icol; 00112 00113 if( A[icol][icol] == 0.0 ) 00114 return false; 00115 00116 pivotinv = (T)1 / A[icol][icol]; 00117 A[icol][icol] = 1.0; 00118 for( l = 0; l <= n; l++ ) 00119 A[icol][l] *= pivotinv; 00120 for( l = 0; l <= m; l++ ) 00121 b[icol][l] *= pivotinv; 00122 00123 for( ll = 0; ll <= n; ll++ ) 00124 { 00125 if( ll != icol ) 00126 { 00127 dummy = A[ll][icol]; 00128 A[ll][icol] = 0.0; 00129 for( l = 0; l <= n; l++ ) 00130 A[ll][l] -= A[icol][l] * dummy; 00131 for( l = 0; l <= m; l++ ) 00132 b[ll][l] -= b[icol][l] * dummy; 00133 } 00134 } 00135 } 00136 for( l = n; l >= 0; l-- ) 00137 { 00138 if( indexr[l] != indexc[l] ) 00139 { 00140 for( k = 0; k <= n; k++ ) 00141 Swap( A[k][indexr[l]], A[k][indexc[l]] ); 00142 } 00143 } 00144 return true; 00145 } |
|
Definition at line 91 of file guma_random.cpp. Referenced by guma::random_des::Random().
00092 { 00093 uint32 seed; 00094 int fd,n; 00095 00096 fd = open( "/dev/random", O_RDONLY ); 00097 if( fd < 0 ) 00098 { 00099 cout << "GetSeed: Couldn't open \"/dev/random\"\n"; 00100 return (uint32)time(0); 00101 } 00102 n = read( fd, &seed, sizeof(seed) ); 00103 if( n != sizeof(seed) ) 00104 { 00105 close(fd); 00106 00107 cout << "GetSeed: Couldn't read " << sizeof(seed) << "bytes\n"; 00108 return (uint32)time(0); 00109 } 00110 00111 close(fd); 00112 return seed; 00113 } |
|
|
|
|
|
Searches the minimum of a function, defined over an intervall. uses Golden Section search (a three point bracketing method), see "Numerical recipes in C", intervall: ax < bx < cx, function values: f(ax) > f(bx) < f(cx) Definition at line 35 of file guma_minimize.cpp.
00037 { 00038 T x0,x1,x2,x3,f1,f2; 00039 int iteration; 00040 00041 x0 = ax; 00042 x3 = cx; 00043 00044 if( rtr<T>::fabs(cx-bx) > rtr<T>::fabs(bx-ax) ) 00045 { 00046 x1 = bx; 00047 x2 = bx + rtr<T>::golden_c()*(cx-bx); 00048 } 00049 else 00050 { 00051 x2 = bx; 00052 x1 = bx - rtr<T>::golden_c()*(bx-ax); 00053 } 00054 f1 = func( x1, fdat ); 00055 f2 = func( x2, fdat ); 00056 00057 for( iteration = 0; iteration < max_iterations; iteration++ ) 00058 { 00059 if( f2 < f1 ) 00060 { 00061 x0 = x1; 00062 x1 = x2; 00063 x2 = rtr<T>::golden_r() * x2 + rtr<T>::golden_c() * x3; 00064 f1 = f2; 00065 f2 = func( x2, fdat ); 00066 } 00067 else 00068 { 00069 x3 = x2; 00070 x2 = x1; 00071 x1 = rtr<T>::golden_r() * x2 + rtr<T>::golden_c() * x0; 00072 f2 = f1; 00073 f1 = func( x1, fdat ); 00074 } 00075 if( rtr<T>::fabs(x3-x0) <= tol*(rtr<T>::fabs(x1)+rtr<T>::fabs(x2)) ) 00076 break; 00077 } 00078 if( f1 < f2 ) 00079 { 00080 *xmin = x1; 00081 *fmin = f1; 00082 } 00083 else 00084 { 00085 *xmin = x2; 00086 *fmin = f2; 00087 } 00088 if( iteration == max_iterations ) return false; 00089 return true; 00090 } |
|
Definition at line 148 of file guma_sorting.cpp.
00148 { _heapsort( nA, A ); } |
|
Definition at line 147 of file guma_sorting.cpp.
00147 { _heapsort( nA, A ); } |
|
Definition at line 38 of file guma_sorting.cpp.
00040 { 00041 char *ra, *rra; 00042 size_t n = nelem, l, ir, i, j; 00043 00044 rra = (char *)alloca( elsize ); 00045 if( rra == NULL ) return; 00046 00047 ra = (char *)elptr; 00048 00049 if( n < 2 ) return; 00050 l = (n >> 1) + 1; 00051 ir = n; 00052 00053 for(;;) 00054 { 00055 if( l > 1 ) 00056 { 00057 memcpy( rra, &ra[(l-2)*elsize], elsize ); 00058 l--; 00059 } 00060 else 00061 { 00062 memcpy( rra, &ra[(ir-1)*elsize], elsize ); 00063 memcpy( &ra[(ir-1)*elsize], ra, elsize ); 00064 if( --ir == 1 ) 00065 { 00066 memcpy( ra, rra, elsize ); 00067 break; 00068 } 00069 } 00070 i = l; 00071 j = l+l; 00072 00073 while( j <= ir ) 00074 { 00075 if( (j < ir) && 00076 (usrfunc( &ra[(j-1)*elsize], &ra[j*elsize], usrdata ) < 0) ) 00077 j++; 00078 00079 if( usrfunc(rra, &ra[(j-1)*elsize], usrdata) < 0 ) 00080 { 00081 memcpy( &ra[(i-1)*elsize], &ra[(j-1)*elsize], elsize ); 00082 i = j; 00083 j <<= 1; 00084 } 00085 else 00086 j = ir + 1; 00087 } 00088 memcpy( &ra[(i-1)*elsize], rra, elsize ); 00089 } 00090 return; 00091 } |
|
Definition at line 166 of file guma_sorting.cpp. Referenced by gul::RefMap::DeleteElems(), gul::Map< kdnnrec< U, V > >::DeleteElems(), gugr::edge_interval_tree::edge_interval_tree(), gul::Map< kdnnrec< U, V > >::Map(), and gul::RefMap::RefMap().
00167 { 00168 head->F.b = 1; 00169 head->F.l = 0; 00170 00171 (*((int *)(&head->left))) = 0; /* height = 0 */ 00172 head->right = NULL; 00173 } |
|
Definition at line 281 of file guma_sorting.cpp. Referenced by gul::RefMap::InsertNode(), gul::Map< kdnnrec< U, V > >::InsertNode(), and gugr::edge_interval_tree::InsertNode().
00283 { 00284 BBTNode *Q, *Pk, *Pk_1, *A, *B, *X; 00285 int ak, ak_1; 00286 00287 Q = element; /* neuen Knoten initialisieren */ 00288 Q->left = Q->right = NULL; 00289 Q->F.b = 0; 00290 00291 Pk = where; 00292 ak = side; 00293 00294 if( ak == -1 ) 00295 { 00296 Pk->left = Q; 00297 if( Pk->left != NULL ) 00298 { 00299 Pk->left->parent = Pk; 00300 Pk->left->F.l = -1; 00301 } 00302 } 00303 else 00304 { 00305 Pk->right = Q; 00306 if( Pk->right != NULL ) 00307 { 00308 Pk->right->parent = Pk; 00309 Pk->right->F.l = 1; 00310 } 00311 } 00312 00313 while( (Pk->F.b == 0) && (Pk != head) ) /* Balance Faktoren aktualisieren */ 00314 { 00315 Pk->F.b = ak; 00316 ak = Pk->F.l; /* k-- */ 00317 Pk = Pk->parent; 00318 } 00319 00320 if( Pk == head ) 00321 { 00322 (*((int *)(&head->left)))++; /* Baumhoehe im Headerknoten erhoehen */ 00323 return; /*** fertig ***/ 00324 } 00325 00326 if( ak == -1 ) /*** eventuell Rebalancieren, Ausfuehrung fuer (ak == -1) ***/ 00327 { 00328 A = Pk; 00329 Pk_1 = Pk->parent; 00330 ak_1 = Pk->F.l; 00331 00332 if( A->F.b == 1 ) /* (A->B == -ak) */ 00333 { 00334 A->F.b = 0; 00335 return; /*** fertig ***/ 00336 } 00337 else /* A->B == ak */ 00338 { 00339 B = Pk->left; /* B = LINK(A,ak) */ 00340 00341 if( B->F.b == -1 ) /* (B->B == ak) => Single Rotation */ 00342 { 00343 A->left = B->right; /* LINK(A,ak) = LINK(B,-ak) */ 00344 if( A->left != NULL ) 00345 { 00346 A->left->parent = A; 00347 A->left->F.l = -1; 00348 } 00349 00350 B->right = A; /* LINK(B,-ak) = A */ 00351 if( B->right != NULL ) 00352 { 00353 B->right->parent = B; 00354 B->right->F.l = 1; 00355 } 00356 00357 A->F.b = B->F.b = 0; 00358 00359 ak = ak_1; /* k-- */ 00360 Pk = Pk_1; 00361 00362 if( ak == -1 ) /* Wurzel Teilbaum = B */ 00363 { 00364 Pk->left = B; 00365 if( Pk->left != NULL ) 00366 { 00367 Pk->left->parent = Pk; 00368 Pk->left->F.l = -1; 00369 } 00370 } 00371 else 00372 { 00373 Pk->right = B; 00374 if( Pk->right != NULL ) 00375 { 00376 Pk->right->parent = Pk; 00377 Pk->right->F.l = 1; 00378 } 00379 } 00380 00381 return; /*** fertig ***/ 00382 } 00383 else /* (B->B == -ak) => Double Rotation */ 00384 { 00385 X = B->right; /* X = LINK(B,-ak) */ 00386 00387 A->left = X->right; /* LINK(A,ak) = LINK(X,-ak) */ 00388 if( A->left != NULL ) 00389 { 00390 A->left->parent = A; 00391 A->left->F.l = -1; 00392 } 00393 00394 B->right = X->left; /* LINK(B,-ak) = LINK(X,ak) */ 00395 if( B->right != NULL ) 00396 { 00397 B->right->parent = B; 00398 B->right->F.l = 1; 00399 } 00400 00401 X->left = B; /* LINK(X,ak) = B */ 00402 if( X->left != NULL ) 00403 { 00404 X->left->parent = X; 00405 X->left->F.l = -1; 00406 } 00407 00408 X->right = A; /* LINK(X,-ak) = A */ 00409 if( X->right != NULL ) 00410 { 00411 X->right->parent = X; 00412 X->right->F.l = 1; 00413 } 00414 00415 if( X->F.b == 1 ) /* (X.B == -ak) */ 00416 { 00417 B->F.b = -1; /* B->B = ak */ 00418 A->F.b = 0; /* A->B = 0 */ 00419 } 00420 else if( X->F.b == -1 ) /* (X.B == ak ) */ 00421 { 00422 B->F.b = 0; /* B->B = 0 */ 00423 A->F.b = 1; /* A->B = -ak */ 00424 } 00425 else /* (X.B == 0), (Anm: ist der Fall, wenn X == Q)*/ 00426 { 00427 B->F.b = 0; /* B->B = 0 */ 00428 A->F.b = 0; /* A->B = 0 */ 00429 } 00430 X->F.b = 0; /* X->B = 0 */ 00431 00432 ak = ak_1; /* k-- */ 00433 Pk = Pk_1; 00434 00435 if( ak == -1 ) /* Wurzel Teilbaum = X */ 00436 { 00437 Pk->left = X; 00438 if( Pk->left != NULL ) 00439 { 00440 Pk->left->parent = Pk; 00441 Pk->left->F.l = -1; 00442 } 00443 } 00444 else 00445 { 00446 Pk->right = X; 00447 if( Pk->right != NULL ) 00448 { 00449 Pk->right->parent = Pk; 00450 Pk->right->F.l = 1; 00451 } 00452 } 00453 00454 return; /*** fertig ***/ 00455 } 00456 } 00457 } 00458 00459 00460 else /*** Ausfuehrung fuer (ak == 1) ***/ 00461 { 00462 A = Pk; 00463 Pk_1 = Pk->parent; 00464 ak_1 = Pk->F.l; 00465 00466 if( A->F.b == -1 ) /* (A->B == -ak) */ 00467 { 00468 A->F.b = 0; 00469 return; /*** fertig ***/ 00470 } 00471 else /* A->B == ak */ 00472 { 00473 B = Pk->right; /* B = LINK(A,ak) */ 00474 00475 if( B->F.b == 1 ) /* (B->B == ak) => Single Rotation */ 00476 { 00477 A->right = B->left; /* LINK(A,ak) = LINK(B,-ak) */ 00478 if( A->right != NULL ) 00479 { 00480 A->right->parent = A; 00481 A->right->F.l = 1; 00482 } 00483 00484 B->left = A; /* LINK(B,-ak) = A */ 00485 if( B->left != NULL ) 00486 { 00487 B->left->parent = B; 00488 B->left->F.l = -1; 00489 } 00490 00491 A->F.b = B->F.b = 0; 00492 00493 ak = ak_1; /* k-- */ 00494 Pk = Pk_1; 00495 00496 if( ak == -1 ) /* Wurzel Teilbaum = B */ 00497 { 00498 Pk->left = B; 00499 if( Pk->left != NULL ) 00500 { 00501 Pk->left->parent = Pk; 00502 Pk->left->F.l = -1; 00503 } 00504 } 00505 else 00506 { 00507 Pk->right = B; 00508 if( Pk->right != NULL ) 00509 { 00510 Pk->right->parent = Pk; 00511 Pk->right->F.l = 1; 00512 } 00513 } 00514 00515 return; /*** fertig ***/ 00516 } 00517 else /* (B->B == -ak) => Double Rotation */ 00518 { 00519 X = B->left; /* X = LINK(B,-ak) */ 00520 00521 A->right = X->left; /* LINK(A,ak) = LINK(X,-ak) */ 00522 if( A->right != NULL ) 00523 { 00524 A->right->parent = A; 00525 A->right->F.l = 1; 00526 } 00527 00528 B->left = X->right; /* LINK(B,-ak) = LINK(X,ak) */ 00529 if( B->left != NULL ) 00530 { 00531 B->left->parent = B; 00532 B->left->F.l = -1; 00533 } 00534 00535 X->right = B; /* LINK(X,ak) = B */ 00536 if( X->right != NULL ) 00537 { 00538 X->right->parent = X; 00539 X->right->F.l = 1; 00540 } 00541 00542 X->left = A; /* LINK(X,-ak) = A */ 00543 if( X->left != NULL ) 00544 { 00545 X->left->parent = X; 00546 X->left->F.l = -1; 00547 } 00548 00549 if( X->F.b == -1 ) /* (X.B == -ak) */ 00550 { 00551 B->F.b = 1; /* B->B = ak */ 00552 A->F.b = 0; /* A->B = 0 */ 00553 } 00554 else if( X->F.b == 1 ) /* (X.B == ak ) */ 00555 { 00556 B->F.b = 0; /* B->B = 0 */ 00557 A->F.b = -1; /* A->B = -ak */ 00558 } 00559 else /* (X.B == 0), (Anm: ist der Fall, wenn X == Q)*/ 00560 { 00561 B->F.b = 0; /* B->B = 0 */ 00562 A->F.b = 0; /* A->B = 0 */ 00563 } 00564 X->F.b = 0; /* X->B = 0 */ 00565 00566 ak = ak_1; /* k-- */ 00567 Pk = Pk_1; 00568 00569 if( ak == -1 ) /* Wurzel Teilbaum = X */ 00570 { 00571 Pk->left = X; 00572 if( Pk->left != NULL ) 00573 { 00574 Pk->left->parent = Pk; 00575 Pk->left->F.l = -1; 00576 } 00577 } 00578 else 00579 { 00580 Pk->right = X; 00581 if( Pk->right != NULL ) 00582 { 00583 Pk->right->parent = Pk; 00584 Pk->right->F.l = 1; 00585 } 00586 } 00587 00588 return; /*** fertig ***/ 00589 } 00590 } 00591 } 00592 } |
|
|
|
Definition at line 50 of file guma_newton.cpp.
00061 {i+1}-x_{i}| < TOLX) */ 00062 Ptr<T>& x, /* return: point in domain */ 00063 T *fx /* return: function value there */ 00064 ) 00065 { 00066 T sum, slope, test, temp, alamin, alam, alphamin, alpha, stpmax; 00067 T a, b, alam2, disc, f2, fold2, rhs1, rhs2, tmplam; 00068 int i, n; 00069 T f; 00070 00071 found = false; 00072 n = I.dim; 00073 00074 // maximale Schrittweite bestimmen 00075 00076 alphamin = 1.0; 00077 00078 for( i = 0; i < n; i++ ) 00079 { 00080 if( xold[i] + p[i] < x1[i] ) 00081 alpha = (x1[i] - xold[i]) / p[i]; 00082 else if( xold[i] + p[i] > x2[i] ) 00083 alpha = (x2[i] - xold[i]) / p[i]; 00084 else 00085 alpha = 1.0; 00086 00087 if( rtr<T>::fabs(alpha) == 0.0 ) 00088 { 00089 p[i] = 0.0; 00090 alpha = 1.0; 00091 } 00092 00093 if( alpha < alphamin ) 00094 alphamin = alpha; 00095 } 00096 00097 for( sum = 0.0, i = 0; i < n; i++ ) 00098 sum += p[i] * p[i]; 00099 00100 stpmax = rtr<T>::fabs(alphamin) * rtr<T>::sqrt(sum); 00101 00102 /*-------------------------------------------------------------*/ 00103 00104 for( sum = 0.0, i = 0; i < n; i++ ) 00105 sum += p[i] * p[i]; 00106 sum = rtr<T>::sqrt( sum ); 00107 00108 if( sum > stpmax ) 00109 for( i = 0; i < n; i++ ) 00110 p[i] *= stpmax / sum; /* Skalieren, falls Schritt zu gross */ 00111 00112 for( slope = 0.0, i = 0; i < n; i++ ) 00113 slope += g[i] * p[i]; 00114 00115 test = 0.0; 00116 00117 for( i = 0; i < n; i++ ) 00118 { 00119 temp = rtr<T>::fabs(p[i]) / Max(rtr<T>::fabs(xold[i]),(T)1); 00120 if( temp > test ) test = temp; 00121 } 00122 if( test == (T)0 ) test = rtr<T>::tiny(); 00123 00124 alamin = I.tolx / test; 00125 alam = (T)1; /* Im ersten Durchgang volle Schrittweite */ 00126 00127 for( ;; ) 00128 { 00129 for( i = 0; i < n; i++ ) 00130 { 00131 x[i] = xold[i] + alam * p[i]; 00132 00133 if( x[i] < x1[i] ) x[i] = x1[i]; 00134 else if( x[i] > x2[i] ) x[i] = x2[i]; 00135 } 00136 00137 found = I.calcf( x, &f ); 00138 if( found ) { check = false; break; } 00139 00140 if( alam < alamin ) /* Konvergenz von dx, */ 00141 { /* aufrufendes Programm sollte Konvergenz */ 00142 for( i = 0; i < n; i++ ) /* verifizieren */ 00143 x[i] = xold[i]; 00144 check = true; 00145 break; 00146 } 00147 00148 if( f <= fold + I.alf * alam * slope ) /* Funktionswert nimmt stark */ 00149 { check = false; break; } /* genug ab */ 00150 00151 if( alam == (T)1 ) /* falls 1.Durchgang */ 00152 tmplam = -slope / ((T)2 * (f-fold-slope)); 00153 else 00154 { 00155 rhs1 = f - fold - alam * slope; 00156 rhs2 = f2 - fold2 - alam2 * slope; 00157 a = (rhs1/(alam*alam) - rhs2/(alam2*alam2)) / (alam-alam2); 00158 b = (-alam2*rhs1/(alam*alam) + alam*rhs2/(alam2*alam2)) / (alam-alam2); 00159 00160 if( a == (T)0 ) 00161 tmplam = -slope/((T)2*b); 00162 else 00163 { 00164 disc = b*b - (T)3*a*slope; 00165 00166 if( disc < (T)0 ) /* roundoff problem */ 00167 return false; 00168 00169 tmplam = (-b + rtr<T>::sqrt(disc)) / ((T)3*a); 00170 } 00171 00172 if( tmplam > (T)0.5 * alam ) 00173 tmplam = (T)0.5 * alam; /* lambda <= 0.5 * lambda1 */ 00174 } 00175 00176 alam2 = alam; 00177 f2 = f; 00178 fold2 = fold; 00179 alam = Max( tmplam, (T)0.1*alam ); /* lambda >= 0.1 * lambda1 */ 00180 } 00181 00182 *fx = f; 00183 return true; 00184 } |
|
|
|
|
|
Solve system of linear equations with help of LU-Decomposition (given in A).
Definition at line 237 of file guma_lineq.cpp.
00239 { 00240 int ii,i,j,ip,n; 00241 T sum; 00242 00243 n = nRowsCols-1; 00244 00245 ii = -1; 00246 00247 for( i = 0; i <= n; i++ ) 00248 { 00249 ip = index[i]; 00250 sum = b[ip]; 00251 b[ip] = b[i]; 00252 00253 if( ii >= 0 ) 00254 { 00255 for( j = ii; j <= i-1; j++ ) 00256 sum -= A[i][j] * b[j]; 00257 } 00258 else 00259 if( sum != 0.0 ) 00260 ii = i; 00261 00262 b[i] = sum; 00263 } 00264 for( i = n; i >= 0; i-- ) 00265 { 00266 sum = b[i]; 00267 00268 for( j = i+1; j <= n; j++ ) 00269 sum -= A[i][j] * b[j]; 00270 00271 b[i] = sum / A[i][i]; 00272 } 00273 } |
|
|
|
|
|
Decompose a matrix into lower and upper triangular matrix. the function throws an exception when an singular matrix is encountered (for convenience, so that not only the calling program can react to this, but also functions higher in the call stack) Definition at line 155 of file guma_lineq.cpp.
00157 { 00158 Ptr<T> vv; 00159 T big,sum,dummy,temp; 00160 int i,j,k,imax,n,d; 00161 00162 n = nRowsCols - 1; 00163 vv.reserve_pool(n+1); /* vv will contain pivot scale factor for each row */ 00164 d = 1; 00165 00166 for( i = 0; i <= n; i++ ) 00167 { 00168 big = 0.0; 00169 for( j = 0; j <= n; j++ ) 00170 { 00171 if( (temp = rtr<T>::fabs(A[i][j])) > big ) 00172 big = temp; 00173 } 00174 if( big == 0.0 ) 00175 return false; 00176 00177 vv[i] = (T)1 / big; 00178 } 00179 for( j = 0; j <= n; j++ ) /* loop over columns */ 00180 { 00181 for( i = 0; i < j; i++ ) 00182 { 00183 sum = A[i][j]; 00184 for( k = 0; k < i; k++ ) 00185 sum -= A[i][k] * A[k][j]; 00186 A[i][j] = sum; 00187 } 00188 big = 0.0; 00189 00190 for( i = j; i <= n; i++ ) 00191 { 00192 sum = A[i][j]; 00193 for( k = 0; k < j; k++ ) 00194 sum -= A[i][k] * A[k][j]; 00195 A[i][j] = sum; 00196 00197 if( (dummy = vv[i] * rtr<T>::fabs(sum)) >= big ) // search pivot element 00198 { 00199 big = dummy; 00200 imax = i; 00201 } 00202 } 00203 if( j != imax ) /* pivot element not on diagonal */ 00204 { 00205 for( k = 0; k <= n; k++ ) 00206 Swap( A[imax][k], A[j][k] ); /* swap rows */ 00207 00208 d = -d; 00209 vv[imax] = vv[j]; /* swap scale factors */ 00210 } 00211 index[j] = imax; 00212 00213 if( A[j][j] == 0.0 ) 00214 A[j][j] = rtr<T>::tiny(); 00215 00216 if( j != n ) /* divide by pivot element */ 00217 { 00218 dummy = (T)1 / A[j][j]; 00219 for( i = j+1; i <= n; i++ ) 00220 A[i][j] *= dummy; 00221 } 00222 } /* next column */ 00223 00224 *perm_sign = d; 00225 return true; 00226 } |
|
|
|
|
|
Definition at line 215 of file guma_newton.cpp.
00221 { 00222 int its, i, j, n; 00223 T f, fold, sum, temp, test; 00224 bool result, found, check; 00225 Ptr<int> indx; 00226 Ptr<T> g,p,xold; 00227 Ptr< Ptr<T> > A; 00228 int sign; 00229 00230 n = I.dim; 00231 00232 A.reserve_pool(n); 00233 for( i = 0; i < n; i++ ) 00234 A[i].reserve_pool(n); 00235 00236 indx.reserve_pool(n); 00237 g.reserve_pool(n); 00238 p.reserve_pool(n); 00239 xold.reserve_pool(n); 00240 00241 /* ------- Hauptschleife: ---------------------------------------- */ 00242 00243 found = I.calcf( x, &f ); 00244 if( found ) { return true; } 00245 00246 for( its = 1; its < maxits; its++ ) 00247 { 00248 for( i = 0; i < n; i++ ) /* Gradient von f=1/2*F*F */ 00249 { /* berechnen (=> df = F*J */ 00250 for( sum = 0.0, j = 0; j < n; j++ ) 00251 sum += I.fvec[j] * I.fjac[j][i]; 00252 g[i] = sum; 00253 } 00254 00255 for( i = 0; i < n; i++ ) 00256 xold[i] = x[i]; 00257 fold = f; 00258 00259 for( i = 0; i < n; i++ ) 00260 p[i] = -I.fvec[i]; /* rechte Seite der Gleichung */ 00261 00262 MCopy(n,n,I.fjac,A); 00263 result = LUDecomposition( n, A, &sign, indx ); 00264 if( !result ) return(false); 00265 LUBackSubstitution( n, indx, A, p ); 00266 00267 /* ------------------------------------------------------------------- */ 00268 00269 result = LinearSearch( p, xold, fold, g, x1, x2, I, found, check, x, &f ); 00270 // if( (!result) || check ) return false; 00271 if( !result ) return false; 00272 00273 // convergence of dx may happen when there is no better solution then a 00274 // point on the border of the surface, so for the time beeing i am 00275 // simply ignoring the 'check' flag (i am not sure, if this is allright 00276 // in all cases) 00277 00278 if( found ) { return true; } 00279 00280 test = 0.0; 00281 for( i = 0; i < n; i++ ) 00282 { 00283 temp = (rtr<T>::fabs(x[i]-xold[i])) / Max(rtr<T>::fabs(x[i]),(T)1); 00284 if( temp > test ) test = temp; 00285 } 00286 if( test < I.tolx ) return true; 00287 } 00288 00289 /* maximum iterations exceeded */ 00290 return false; 00291 } |
|
Definition at line 119 of file guma_random.cpp. Referenced by guma::random_des::des_random().
00120 { 00121 static uint32 c1[4] = { 00122 0xbaa96887L, 0x1e17d32cL, 0x03bcdc3cL, 0x0f33d1b2L }; 00123 static uint32 c2[4] = { 00124 0x4b0f3b58L, 0xe874f0c3L, 0x6955c5a6L, 0x55a7ca46L }; 00125 00126 uint32 i,ia,ib,iswap,itmph=0,itmpl=0; 00127 00128 for( i = 0; i < 4; i++ ) 00129 { 00130 ia = (iswap=(*irword)) ^ c1[i]; 00131 itmpl = ia & 0xffff; 00132 itmph = ia >> 16; 00133 ib = itmpl*itmpl + ~(itmph*itmph); 00134 ia = (ib>>16) | ((ib&0xffff)<<16); 00135 *irword = (*lword) ^ ((ia ^ c2[i]) + itmpl*itmph); 00136 *lword = iswap; 00137 } 00138 } |
|
Definition at line 93 of file guma_sorting.cpp.
00095 { 00096 void **ra, *rra; 00097 size_t n = nelem, l, ir, i, j; 00098 00099 ra = elptr; 00100 00101 if( n < 2 ) return; 00102 l = (n >> 1) + 1; 00103 ir = n; 00104 00105 for(;;) 00106 { 00107 if( l > 1 ) 00108 { 00109 rra = ra[l-2]; 00110 l--; 00111 } 00112 else 00113 { 00114 rra = ra[ir-1]; 00115 ra[ir-1] = ra[0]; 00116 00117 if( --ir == 1 ) 00118 { 00119 ra[0] = rra; 00120 break; 00121 } 00122 } 00123 i = l; 00124 j = l+l; 00125 00126 while( j <= ir ) 00127 { 00128 if( (j < ir) && 00129 (usrfunc( ra[j-1], ra[j], usrdata ) < 0) ) 00130 j++; 00131 00132 if( usrfunc( rra, ra[j-1], usrdata) < 0 ) 00133 { 00134 ra[i-1] = ra[j-1]; 00135 i = j; 00136 j <<= 1; 00137 } 00138 else 00139 j = ir + 1; 00140 } 00141 00142 ra[i-1] = rra; 00143 } 00144 } |
|
Calculate (a^2 + b^2)^{1/2}, with precautions to avoid destructive over- or underflow.
Definition at line 99 of file guma_lineq.h.
|
|
Definition at line 183 of file guma_sorting.cpp. Referenced by gul::RefMap::SearchNode(), gul::Map< kdnnrec< U, V > >::SearchNode(), and gugr::edge_interval_tree::SearchNode().
00186 { 00187 int result; 00188 BBTNode *P,*el; 00189 00190 el = head; 00191 result = 1; 00192 P = head->right; 00193 00194 while( P != NULL ) /* Knoten suchen */ 00195 { 00196 el = P; 00197 result = compare( key, P->key ); 00198 00199 if( result < 0 ) 00200 { 00201 P = P->left; 00202 } 00203 else if( result > 0 ) 00204 { 00205 P = P->right; 00206 } 00207 else 00208 break; 00209 } 00210 00211 *element = el; 00212 return(result); 00213 } |
|
Definition at line 249 of file guma_sorting.cpp. Referenced by gul::RefMap::Predecessor(), and gul::Map< kdnnrec< U, V > >::Predecessor().
00250 { 00251 BBTNode *N = element, *R, *P; 00252 00253 if( N->left ) 00254 { 00255 N = N->left; 00256 for(;;) 00257 { 00258 R = N->right; 00259 if( R == NULL ) return N; 00260 N = R; 00261 } 00262 } 00263 else 00264 { 00265 for(;;) 00266 { 00267 P = N->parent; 00268 if( P == head ) return NULL; 00269 if( N->F.l == +1 ) return P; 00270 N = P; 00271 } 00272 } 00273 } |
|
Definition at line 219 of file guma_sorting.cpp. Referenced by gul::RefMap::Successor(), and gul::Map< kdnnrec< U, V > >::Successor().
00220 { 00221 BBTNode *N = element, *L, *P; 00222 00223 if( N->right ) 00224 { 00225 N = N->right; 00226 for(;;) 00227 { 00228 L = N->left; 00229 if( L == NULL ) return N; 00230 N = L; 00231 } 00232 } 00233 else 00234 { 00235 for(;;) 00236 { 00237 if( N == head ) return NULL; 00238 P = N->parent; 00239 if( N->F.l == -1 ) return P; 00240 N = P; 00241 } 00242 } 00243 } |
|
|
|
|
|
Solve system of linear equations, when a Singular Value Decomposition is given.
Definition at line 764 of file guma_lineq.cpp.
00767 { 00768 int jj,j,i; 00769 T s; 00770 Ptr<T> tmp; 00771 00772 tmp.reserve_pool(n); 00773 00774 for( j = 1; j <= n; j++ ) 00775 { 00776 s = 0.0; 00777 if( w[j-1] != 0.0 ) 00778 { 00779 for( i = 1; i <= m; i++ ) 00780 s += u[i-1][j-1] * b[i-1]; 00781 s /= w[j-1]; 00782 } 00783 tmp[j-1] = s; 00784 } 00785 for( j = 1; j <= n; j++ ) 00786 { 00787 s = 0.0; 00788 for ( jj = 1; jj <= n; jj++ ) 00789 s += v[j-1][jj-1] * tmp[jj-1]; 00790 b[j-1] = s; 00791 } 00792 return; 00793 } |
|
|
|
|
|
Solve system of linear equations, when a Singular Value Decomposition is given.
Definition at line 718 of file guma_lineq.cpp.
00722 { 00723 int jj,j,i; 00724 T s; 00725 Ptr<T> tmp; 00726 00727 tmp.reserve_pool(n); 00728 00729 for( j = 1; j <= n; j++ ) 00730 { 00731 s = 0.0; 00732 if( w[j-1] != 0.0 ) 00733 { 00734 for( i = 1; i <= m; i++ ) 00735 s += u[i-1][j-1] * b[i-1]; 00736 s /= w[j-1]; 00737 } 00738 tmp[j-1] = s; 00739 } 00740 for( j = 1; j <= n; j++ ) 00741 { 00742 s = 0.0; 00743 for ( jj = 1; jj <= n; jj++ ) 00744 s += v[j-1][jj-1] * tmp[jj-1]; 00745 x[j-1] = s; 00746 } 00747 return; 00748 } |
|
|
|
|
|
Singular Value Decomposition. ============================= A = U * W * V^{T} with A = m x n Matrix (m >= n) U = m x n Matrix W = n x n Matrix V = n x n Matrix U,V orthogonal ( i.e. U^{T} * U = (1), V^{T} * V = (1) ) W diagonal matrix, containing the singular values. Definition at line 445 of file guma_lineq.cpp.
00447 { 00448 int flag,i,its,j,jj,k,l,nm; 00449 T anorm,c,f,g,h,s,scale,x,y,z; 00450 Ptr<T> rv1; 00451 00452 rv1.reserve_pool(n+1); 00453 00454 /* ----- Householder reduction to bidiagonal form ------------------- */ 00455 00456 g = scale = anorm = 0.0; 00457 00458 for( i = 1; i <= n; i++ ) 00459 { 00460 l = i+1; 00461 rv1[i-1] = scale * g; 00462 g = s = scale = 0.0; 00463 00464 if( i <= m ) 00465 { 00466 for( k = i; k <=m; k++ ) 00467 scale += rtr<T>::fabs( a[k-1][i-1] ); 00468 if( scale != 0.0 ) 00469 { 00470 for( k = i; k <= m; k++ ) 00471 { 00472 a[k-1][i-1] /= scale; 00473 s += a[k-1][i-1] * a[k-1][i-1]; 00474 } 00475 f = a[i-1][i-1]; 00476 g = -Sign( rtr<T>::sqrt(s), f ); 00477 h = f*g - s; 00478 a[i-1][i-1] = f-g; 00479 00480 for( j=l; j<=n; j++ ) 00481 { 00482 for( s=0.0,k=i; k<=m; k++ ) 00483 s += a[k-1][i-1] * a[k-1][j-1]; 00484 f = s / h; 00485 for( k = i; k <= m; k++ ) 00486 a[k-1][j-1] += f * a[k-1][i-1]; 00487 } 00488 for( k = i; k <=m; k++ ) 00489 a[k-1][i-1] *= scale; 00490 } 00491 } 00492 w[i-1] = scale * g; 00493 g = s = scale = 0.0; 00494 00495 if( (i <= m) && (i != n) ) 00496 { 00497 for( k = l; k <= n; k++ ) 00498 scale += rtr<T>::fabs( a[i-1][k-1] ); 00499 00500 if( scale != 0.0 ) 00501 { 00502 for( k = l; k <= n; k++ ) 00503 { 00504 a[i-1][k-1] /= scale; 00505 s += a[i-1][k-1] * a[i-1][k-1]; 00506 } 00507 00508 f = a[i-1][l-1]; 00509 g = -Sign( rtr<T>::sqrt(s), f ); 00510 h = f*g - s; 00511 a[i-1][l-1] = f-g; 00512 00513 for( k = l; k <= n; k++ ) 00514 rv1[k-1] = a[i-1][k-1] / h; 00515 00516 for( j = l; j <= m; j++ ) 00517 { 00518 for( s = 0.0,k=l; k <= n; k++ ) 00519 s += a[j-1][k-1] * a[i-1][k-1]; 00520 for( k = l; k <= n; k++ ) 00521 a[j-1][k-1] += s * rv1[k-1]; 00522 } 00523 00524 for( k = l; k <= n; k++ ) 00525 a[i-1][k-1] *= scale; 00526 } 00527 } 00528 anorm = Max( anorm, (rtr<T>::fabs(w[i-1]) + rtr<T>::fabs(rv1[i-1])) ); 00529 } 00530 /* ------- akkumulation of right side transformations ------------- */ 00531 00532 for( i = n; i >= 1; i-- ) 00533 { 00534 if( i < n ) 00535 { 00536 if( g != 0.0 ) 00537 { 00538 for( j = l; j <= n; j++ ) 00539 v[j-1][i-1] = (a[i-1][j-1] / a[i-1][l-1]) / g; 00540 for( j = l; j <= n; j++ ) 00541 { 00542 for( s=0.0,k=l; k<=n; k++ ) 00543 s += a[i-1][k-1] * v[k-1][j-1]; 00544 for( k = l; k <= n; k++ ) 00545 v[k-1][j-1] += s * v[k-1][i-1]; 00546 } 00547 } 00548 for( j = l; j <= n; j++ ) 00549 v[i-1][j-1] = v[j-1][i-1] = 0.0; 00550 } 00551 v[i-1][i-1] = 1.0; 00552 g = rv1[i-1]; 00553 l = i; 00554 } 00555 /* -------- accumulation of left side transformations --------------- */ 00556 00557 for( i = Min(m,n); i >=1; i-- ) 00558 { 00559 l = i+1; 00560 g = w[i-1]; 00561 00562 for( j = l; j <= n; j++ ) 00563 a[i-1][j-1] = 0.0; 00564 00565 if( g != 0.0 ) 00566 { 00567 g = (T)1 / g; 00568 00569 for( j = l; j <= n; j++ ) 00570 { 00571 for( s=0.0,k=l; k <= m; k++ ) 00572 s += a[k-1][i-1] * a[k-1][j-1]; 00573 00574 f = (s/a[i-1][i-1]) * g; 00575 00576 for( k = i; k <= m; k++ ) 00577 a[k-1][j-1] += f * a[k-1][i-1]; 00578 } 00579 00580 for( j = i; j <= m; j++ ) 00581 a[j-1][i-1] *= g; 00582 } 00583 else 00584 for( j = i; j <= m; j++ ) 00585 a[j-1][i-1] = 0.0; 00586 00587 a[i-1][i-1] += 1.0; 00588 } 00589 /* -------- Diagonalize the bidiagonal form --------------------- */ 00590 00591 for( k = n; k >= 1; k-- ) 00592 { 00593 for( its = 1; its <= 30; its++ ) 00594 { 00595 flag = 1; 00596 00597 for( l = k; l >= 1; l-- ) 00598 { 00599 nm = l-1; 00600 if( rtr<T>::fabs(rv1[l-1]) + anorm == anorm ) 00601 { 00602 flag = 0; 00603 break; 00604 } 00605 if( rtr<T>::fabs(w[nm-1]) + anorm == anorm ) 00606 break; 00607 } 00608 if( flag != 0 ) 00609 { 00610 c = 0.0; 00611 s = 1.0; 00612 for( i = l; i <= k; i++ ) 00613 { 00614 f = s * rv1[i-1]; 00615 rv1[i-1] = c * rv1[i-1]; 00616 00617 if( rtr<T>::fabs(f) + anorm == anorm ) 00618 break; 00619 00620 g = w[i-1]; 00621 h = Pythagoras( f, g ); 00622 w[i-1] = h; 00623 h = (T)1 / h; 00624 c = g * h; 00625 s = -f * h; 00626 00627 for( j = 1; j <= m; j++ ) 00628 { 00629 y = a[j-1][nm-1]; 00630 z = a[j-1][i-1]; 00631 a[j-1][nm-1] = y * c + z * s; 00632 a[j-1][i-1] = z * c - y * s; 00633 } 00634 } 00635 } 00636 z = w[k-1]; 00637 if( l == k ) 00638 { 00639 if( z < 0.0 ) 00640 { 00641 w[k-1] = -z; 00642 for( j = 1; j <= n; j++ ) 00643 v[j-1][k-1] = -v[j-1][k-1]; 00644 } 00645 break; 00646 } 00647 if( its == 30 ) 00648 throw InternalError(); 00649 00650 x = w[l-1]; 00651 nm = k-1; 00652 y = w[nm-1]; 00653 g = rv1[nm-1]; 00654 h = rv1[k-1]; 00655 f = ((y-z)*(y+z)+(g-h)*(g+h))/((T)2*h*y); 00656 g = Pythagoras( f, (T)1 ); 00657 f = ((x-z)*(x+z) + h*((y/(f+Sign(g,f)))-h)) / x; 00658 c = s = 1.0; 00659 00660 for( j = l; j <= nm; j++ ) 00661 { 00662 i = j+1; 00663 g = rv1[i-1]; 00664 y = w[i-1]; 00665 h = s * g; 00666 g = c * g; 00667 z = Pythagoras( f, h ); 00668 rv1[j-1] = z; 00669 c = f/z; 00670 s = h/z; 00671 f = x*c + g*s; 00672 g = g*c - x*s; 00673 h = y*s; 00674 y *= c; 00675 00676 for( jj = 1; jj <= n; jj++ ) 00677 { 00678 x = v[jj-1][j-1]; 00679 z = v[jj-1][i-1]; 00680 v[jj-1][j-1] = x*c + z*s; 00681 v[jj-1][i-1] = z*c - x*s; 00682 } 00683 z = Pythagoras( f, h ); 00684 w[j-1] = z; 00685 if( z != 0.0 ) 00686 { 00687 z = (T)1 / z; 00688 c = f*z; 00689 s = h*z; 00690 } 00691 f = c*g + s*y; 00692 x = c*y - s*g; 00693 00694 for( jj = 1; jj <= m; jj++ ) 00695 { 00696 y = a[jj-1][j-1]; 00697 z = a[jj-1][i-1]; 00698 a[jj-1][j-1] = y*c + z*s; 00699 a[jj-1][i-1] = z*c - y*s; 00700 } 00701 } 00702 rv1[l-1] = 0.0; 00703 rv1[k-1] = f; 00704 w[k-1] = x; 00705 } 00706 } 00707 } |
|
|
|
|
|
Intersect two lines in 3-dimensions, using singular decomposition. (remark: this is a overkill, if you alredy know that the two lines intersect (but on the other hand this is the first oppurtinity to do something senseful with the above SVD algorithm:))))) retcode = 0 => intersection point found retcode = 1 => lines are parallel retcode = 2 => lines are not parallel, but don't intersect either (what's the english word for "windschief" ?) In the last two cases the solution minimizes |x|^2 or |Ax + b|, and the midst of the two points on the two lines is returned. Definition at line 858 of file guma_lineq.cpp.
00861 { 00862 Ptr< Ptr<T> > u,v; 00863 Ptr<T> w, x, b; 00864 point<T> L1,L2; 00865 int code,i; 00866 00867 u.reserve_pool(3); 00868 for( i = 0; i < 3; i++ ) 00869 u[i].reserve_pool(2); 00870 v.reserve_pool(2); 00871 for( i = 0; i < 2; i++ ) 00872 v[i].reserve_pool(2); 00873 w.reserve_pool(2); 00874 x.reserve_pool(2); 00875 b.reserve_pool(3); 00876 00877 code = 0; 00878 00879 u[0][0] = T1.x; u[0][1] = -T2.x; 00880 u[1][0] = T1.y; u[1][1] = -T2.y; 00881 u[2][0] = T1.z; u[2][1] = -T2.z; 00882 00883 SVDecomposition( 3, 2, u, w, v ); 00884 00885 if( SVZero( 2, w ) ) // are the lines parallel ? 00886 code = 1; 00887 00888 b[0] = P2.x - P1.x; 00889 b[1] = P2.y - P1.y; 00890 b[2] = P2.z - P1.z; 00891 00892 SVBackSubstitution( 3, 2, u, w, v, b, x ); 00893 00894 L1.x = P1.x + x[0] * T1.x; 00895 L1.y = P1.y + x[0] * T1.y; 00896 L1.z = P1.z + x[0] * T1.z; 00897 00898 L2.x = P2.x + x[1] * T2.x; 00899 L2.y = P2.y + x[1] * T2.y; 00900 L2.z = P2.z + x[1] * T2.z; 00901 00902 // not parallel, but points too far away from each other ? 00903 if( !code && !rel_equal(L1, L2, rtr<T>::zero_tol() ) ) 00904 code = 2; 00905 00906 P->x = (L1.x + L2.x) / (T)2; 00907 P->y = (L1.y + L2.y) / (T)2; 00908 P->z = (L1.z + L2.z) / (T)2; 00909 00910 *alpha1 = x[0]; 00911 *alpha2 = x[1]; 00912 00913 return code; 00914 } |
|
|
|
|
|
Sets very small singular values to zero. This avoids disastrous rounding errors, when the coefficient matrix of a system of linear equations is ill-conditioned. If some singular values were zero, or had to be set to zero, the function returns false, else it returns true Definition at line 809 of file guma_lineq.cpp.
00810 { 00811 T wmax,wmin; 00812 int j; 00813 bool well_conditioned; 00814 T limit = (T)n * rtr<T>::epsilon(); 00815 00816 wmax = wmin = rtr<T>::fabs(w[0]); 00817 for( j = 2; j <= n; j++ ) 00818 { 00819 if( rtr<T>::fabs(w[j-1]) > wmax ) wmax = rtr<T>::fabs(w[j-1]); 00820 else if( rtr<T>::fabs(w[j-1]) < wmin ) wmin = rtr<T>::fabs(w[j-1]); 00821 } 00822 // ill conditioned ? 00823 if( (wmax == 0.0) || 00824 (wmin / wmax < limit) ) 00825 well_conditioned = false; 00826 else 00827 well_conditioned = true; 00828 00829 /* 00830 cout << "wmin/wmax = " << wmin / wmax << "\n"; 00831 */ 00832 00833 wmin = wmax * limit; 00834 00835 for( j = 1; j <= n; j++ ) 00836 if( wmin > rtr<T>::fabs(w[j-1]) ) w[j-1] = 0.0; 00837 00838 return well_conditioned; 00839 } |