-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
106 lines (86 loc) · 3.28 KB
/
main.cpp
File metadata and controls
106 lines (86 loc) · 3.28 KB
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
/*
* File: main.cpp
* Author: Aztyu
*
* Created on 9 mars 2015, 11:24
*/
#include <cstdlib>
#include <map>
#include <vector>
#include <algorithm>
#include "Matrice.h"
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
int nbre_lettre = 0;
int depart = 1; //On demarre de la premiere lettre : A
int ligne = 1;
int step = 1;
cout << "Rentrez la taille de la matrice" << endl;
cin >> nbre_lettre;
Matrice matrix = Matrice(nbre_lettre);
//init
map<int, int> dist;
map<int, int> pred;
for(int i=0;i<nbre_lettre;i++){
if(i == depart-1){
dist.insert(pair<int, int>(i, 0));
pred.insert(pair<int, int>(i, 0));
}else{
dist.insert(pair<int, int>(i, 100));
pred.insert(pair<int, int>(i, -1));
}
}
bool hasChanged = true;
while(hasChanged){
hasChanged = false;
cout << "Etape " << step << endl;
step++;
for(map<int, int>::iterator it_x = dist.begin(); it_x != dist.end(); it_x++){
for(map<int, int>::iterator it_y = dist.begin(); it_y != dist.end(); it_y++){
if((*it_y).first != (*it_x).first){
//Tri des successeurs du point
if(matrix.GetValue((*it_x).first, (*it_y).first) != 0 && matrix.GetValue((*it_x).first, (*it_y).first) != 100){ //Si c'est un sucesseur du point
//cout << (*it_x).first << "." << (*it_x).second << "." << (*it_y).first << "." << (*it_y).second << endl;
if(dist[(*it_y).first] > dist[(*it_x).first] + matrix.GetValue((*it_x).first, (*it_y).first)){
(*it_y).second = dist[(*it_x).first] + matrix.GetValue((*it_x).first, (*it_y).first);
pred[(*it_y).first] = (*it_x).first;
hasChanged = true;
}
}
}
}
cout << "Lettre = " << IntToLetter((*it_x).first);
ligne++;
cout << endl;
cout << "Lettresss";
for(map<int, int>::iterator it = dist.begin(); it != dist.end(); it++){
cout << " | " << IntToLetter((*it).first) << " | ";
}
cout << endl;
cout << "Distances";
for(map<int, int>::iterator it = dist.begin(); it != dist.end(); it++){
cout << " | " << (*it).second << " | ";
}
cout << endl;
cout << "Predecess";
for(map<int, int>::iterator it = pred.begin(); it != pred.end(); it++){
cout << " | " << IntToLetter((*it).second) << " | ";
}
cout << endl << endl;
}
}
for(map<int, int>::iterator it = dist.begin(); it != dist.end(); it++){ //Affichage des distances
cout << IntToLetter((*it).first) << ":" << (*it).second << endl;
}
cout << endl;
for(map<int, int>::iterator it = pred.begin(); it != pred.end(); it++){ //Affichage des predecesseurs
cout << IntToLetter((*it).first) << ":" << IntToLetter((*it).second) << endl;
}
cout << "Appuyer sur Entree pour terminer" << endl;
cin.get();
cin.get();
return 0;
}