/*************************************************************************** * Copyright (C) 2003-2004 by David Saxton * * david@bluehaze.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "matrix.h" #include #include #include #include #include /// Minimum value before an entry is deemed "zero" const double epsilon = 1e-50; Matrix::Matrix( uint n, uint m ) { m_n = n; m_m = m; m_size = m_n+m_m; m_mat = new matrix(m_size); m_lu = new matrix(m_size); m_y = new double[m_size]; m_inMap = new int[m_size]; // m_outMap = new int[m_size]; m_map = new Map(m_size); zero(); } Matrix::~Matrix() { delete m_map; delete m_mat; delete m_lu; delete [] m_y; delete [] m_inMap; // delete [] m_outMap; } void Matrix::zero() { for ( uint i=0; isetUse( i, j, type, big ); } void Matrix::createMap() { int newMap[m_size]; m_map->createMap(newMap); for ( uint i=0; iswapRows( a, b ); const int old = m_inMap[a]; m_inMap[a] = m_inMap[b]; m_inMap[b] = old; max_k = 0; } /*void Matrix::genOutMap() { for ( uint i=0; im(i,j); } } max_k = 0; } void Matrix::operator+=( Matrix *const m ) { for ( uint _i=0; _im(i,j); } } max_k = 0; } void Matrix::performLU() { // max_k = 0; uint n = m_size; if ( n == 0 ) return; // Copy the affected segment to LU for ( uint i=max_k; i 1e-12 ) { for ( uint j=std::max(k,max_k)+1; j=0; i-- ) { double sum = 0; for ( uint j=i+1; jreset(); for ( uint _i=0; _i 0 && (*m_mat)[i][j] >= 0 ) kdDebug() << "+"; kdDebug() << (*m_mat)[i][j] << "("< 0 && (*m_lu)[i][j] >= 0 ) std::cout << "+"; std::cout << (*m_lu)[i][j] << "("<"<"<( m_size ) ); reset(); } Map::~Map() { delete m_map; } void Map::reset() { for ( uint i=0; i= 0 && map[i] < int(m_size) ); } // Ignore this, for now: // Now, we want to order the matrix, with the following priorities: // (1) How often values change // (2) How few values there are // (3) How large the values are // For each value in the column, } bool Map::typeCmp( const uint t1, const uint t2 ) { if (!t2) return true; if (!t1) return false; int t1_score = 1; if ( t1 | Map::et_constant ) t1_score += 64; else if ( t1 | Map::et_stable ) t1_score += 16; else if ( t1 | Map::et_variable ) t1_score += 4; int t2_score = 1; if ( t2 | Map::et_constant ) t2_score += 64; else if ( t2 | Map::et_stable ) t2_score += 16; else if ( t2 | Map::et_variable ) t2_score += 4; if ( t1 | Map::et_big ) t1_score *= 2; if ( t2 | Map::et_big ) t2_score *= 2; return ( t1_score >= t2_score ); } Matrix22::Matrix22() { reset(); } bool Matrix22::solve() { const double old_x1 = m_x1; const double old_x2 = m_x2; const bool e11 = std::abs((m_a11))