-
Notifications
You must be signed in to change notification settings - Fork 4
/
systemsolver.h
47 lines (41 loc) · 1.08 KB
/
systemsolver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include <map>
#include <iostream>
#include <fstream>
#include <vector>
#pragma warning (disable: 4786)
using namespace std;
class SystemSolver
{
protected:
public:
typedef map<int, double> sparseCol;
typedef map<int, sparseCol> sparseMatrix;
friend ostream& operator<<(ostream& os, const SystemSolver& mat)
{
for(sparseMatrix::const_iterator it=mat.matrix.begin();it!=mat.matrix.end();it++)
{
const sparseCol& col=it->second;
for(sparseCol::const_iterator it2=col.begin();it2!=col.end();it2++)
os<<it2->first<<"-"<<it->first<<": "<<it2->second<<endl;
}
return os;
}
public:
SystemSolver (){num_col=num_row=0;}
virtual ~SystemSolver (){;}
int NumCol(){return num_col;}
int NumRow(){return num_row;}
double& operator()(int index_i,int index_j)
{
if(index_i+1>num_row)num_row=index_i+1;
if(index_j+1>num_col)num_col=index_j+1;
return matrix[index_j][index_i];
}
vector<double> SolveDense(vector<double> values);
vector<double> SolveSparse(vector<double> values);
public:
sparseMatrix matrix; //maps indices to value
int num_col;
int num_row;
};