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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| #ifndef LINEAR_HPP
#define LINEAR_HPP
#include<iostream>
#include<cassert>
#include<cstdlib>
#include <vector>
#include <utility>
using namespace std;
typedef double R;
typedef int I;
class Element{
friend class Colonne;
public:
R valeur;// valeur de coeff non nul
I ligne, colonne;// la position de cette valeur dans la matrice
// constructeurs
Element():valeur(0.),ligne(0),colonne(0){}
Element(R a,I b, I c):valeur(a),ligne(b),colonne(c){}
Element(Element & e):
valeur(e.valeur),ligne(e.ligne),colonne(e.colonne){}
// fonctions membres
R get_val(){return valeur;}
I get_ligne(){return ligne;}
I get_colonne(){return colonne;}
I * get_coord(){
I * tab;
tab= new I[2];
tab[0]=ligne;
tab[1]=colonne;
return tab;
}
// operateurs
I & operator[](I i){
if(i==0)
return ligne;
else if(i==1)
return colonne;
else{
assert(0);
exit(1);
};
}
R & operator()(I i){
if(i==0)
return valeur;
else{
assert(0);
abort();
};
}
friend ostream & operator<<(ostream & f,Element & e){
f<<e.valeur<<" "
<<e.ligne<<" "
<<e.colonne<<endl;
return f;
}
};
class Colonne{
public:
int i;
int j;// numero de colonne
std::vector<Element> ma_colonne;
std::vector<Element> :: iterator it;
Colonne();
Colonne(I num,I n):j(num){
Element a(0.,0,0);
ma_colonne.reserve(n);
for(int i=0;i<ma_colonne.capacity();i++)
ma_colonne[i]=a;
}
Colonne(Colonne & c):j(c.j){
ma_colonne.reserve(c.ma_colonne.capacity());
for (i=0; i<c.ma_colonne.capacity(); i++)
ma_colonne[i]=c.ma_colonne[i];
}
friend ostream & operator<<(ostream & f,Colonne & c){
for( int i=0;i<c.ma_colonne.capacity();i++)
f<<c.ma_colonne[i]<<endl;
return f;
}
std::vector<std::map<int,int> > indic_coeff(){
std::vector<std::pair<int,int> > vect_p;
std::pair<int,int> mapaire;
vect_p.reserve(5*mapaire.size());
vect_p[0].first=i-1;
vect_p[0].second=j;
vect_p[1].first=i;
vect_p[1].second=j-1;
vect_p[2].first=i;
vect_p[2].second=j;
vect_p[3].first=i;
vect_p[3].second=j+1;
vect_p[4].first=i+1;
vect_p[4].second=j;
}
};
#endif |
Partager