⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smatrixn.h

📁 basic mathematic classes used for math programming
💻 H
字号:
//// Sparse Matrix:	Aug 11, 1998//#ifndef	_SPARSE_MATRIX_H_#define	_SPARSE_MATRIX_H_#define	HEAD_ENTITY	-1#define	MEANINGLESS	0struct	entity
{
	int		id;
	m_real	value;
	entity*	next;
};class	vectorN;

class   SparseMatrixN{ // More general sparse matrix  and assume the max matrix dimension is 65535*65535


	public:
	SparseMatrixN(int n)	{ allocate(n); }
	SparseMatrixN();
	~SparseMatrixN()	{ deallocate(); }

	void setSize(int n);

	int		size() const	{ return n; }
	int		getSize() const	{ return n; }

	void	allocate(int n);
	void	deallocate();

	m_real	setValue(int row, int col, m_real value, entity** e = NULL);
	m_real	getValue(int row, int col) const;

	entity  getRows( int i ) const { return rows[i]; }
    int     getColNum(int row);

	m_real	add(int row, int col, m_real increment);
	m_real	sub(int row, int col, m_real decrement);
	m_real  deleteEntity(int row, int col);
	m_real  sumRow(int row);
	int     deleteSmallValEntity(int row, m_real valthres);
	int  multiplyRow(int row, m_real val);
	bool  isRowEmpty(int row);


	SparseMatrixN& add( SparseMatrixN& a, SparseMatrixN& b);

	friend ostream& operator<<(ostream& os, SparseMatrixN& A);
	friend istream& operator>>(istream& is, SparseMatrixN& A);

protected:
	int		n;		// n x n sparse matrix

	int		nnze;	// number of non-zero entity
	entity*	rows;


};
class	smatrixN   // This one is assumed to be symmetric, will be changed to be the derived class of 
// SparseMatrixN{public:	smatrixN(int n)	{ allocate(n); }	~smatrixN()	{ deallocate(); }	int		size() const	{ return n; }	int		getSize() const	{ return n; }	void	allocate(int n);	void	deallocate();	m_real	setValue(int row, int col, m_real value, entity** e = NULL);	m_real	getValue(int row, int col) const;	entity  getRows( int i ) const { return rows[i]; }	m_real	add(int row, int col, m_real increment);	m_real	sub(int row, int col, m_real decrement);	smatrixN& add( smatrixN& a, smatrixN& b);	friend ostream& operator<<(ostream& os, smatrixN& A);	friend istream& operator>>(istream& is, smatrixN& A);private:	int		n;		// n x n sparse matrix	int		nnze;	// number of non-zero entity	entity*	rows;};#endif	// _SPARSE_MATRIX_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -