-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
148 lines (125 loc) · 4.49 KB
/
main.cpp
File metadata and controls
148 lines (125 loc) · 4.49 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* File: main.cpp
* Author: Aztyu
*
* Created on 7 mars 2015, 18:35
*/
#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;
int ligne = 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;
vector<int> fait;
for(int i=0;i<nbre_lettre;i++){
dist.insert(pair<int, int>(i, 0));
pred.insert(pair<int, int>(i, depart-1));
}
for(map<int, int>::iterator it = dist.begin(); it != dist.end(); it++){
int t_mat = matrix.GetValue(depart-1, (*it).first);
if(matrix.GetValue(depart-1, (*it).first) >= 0 && matrix.GetValue(depart-1, (*it).first) != 100){
(*it).second = matrix.GetValue(depart-1, (*it).first);
pred[(*it).first] = depart-1;
}else{
(*it).second = 100;
pred[(*it).first] = -1;
}
}
cout << "process" << endl;
fait.push_back(depart-1);
//process
while(fait.size() != dist.size()){
//choisir xEV tel que
vector<int> non_traite;
for(map<int, int>::iterator it = dist.begin(); it != dist.end(); it++){ //On recupere tous les sommets non traites
bool traite = false;
for(int i=0; i<fait.size();i++){
if(fait[i] == (*it).first){
traite = true;
}
}
if(!traite){
non_traite.push_back((*it).first);
}
}
//On prends le minimum
int min_point = 0;
int min_value = 100;
for(int i=0; i<non_traite.size(); i++){ //On cherche le minimum
if(dist[non_traite[i]] < min_value){
min_point = non_traite[i];
min_value = dist[non_traite[i]];
}
}
//Pour tout y successeur de x
for(map<int, int>::iterator it = dist.begin(); it != dist.end(); it++){
std::vector<int>::iterator it_v;
it_v = find(non_traite.begin(), non_traite.end(), (*it).first);
//Si il est non traite
if(it_v != non_traite.end()){
//Tri des successeurs du point
if(matrix.GetValue(min_point, (*it).first) >= 0 && matrix.GetValue(min_point, (*it).first) != 100){
if(dist[(*it).first] > dist[min_point] + matrix.GetValue(min_point, (*it).first)){
(*it).second = dist[min_point] + matrix.GetValue(min_point, (*it).first);
pred[(*it).first] = min_point;
}
//pred[(*it).first] = min_point;
}
}
}
fait.push_back(min_point);
cout << "Ligne " << ligne << endl;
ligne++;
cout << "Fait : ";
for(int i=0; i < fait.size(); i++){
cout << IntToLetter(fait[i]) << ", ";
}
cout << endl;
cout << "Distances";
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++){
cout << (*it).first << ":" << (*it).second << endl;
}
cout << endl;
for(map<int, int>::iterator it = pred.begin(); it != pred.end(); it++){
cout << (*it).first << ":" << (*it).second << endl;
}
for(map<int, int>::iterator it = dist.begin(); it != dist.end(); it++){
cout << IntToLetter((*it).first) << ":" << (*it).second << endl;
}
cout << endl;
for(map<int, int>::iterator it = pred.begin(); it != pred.end(); it++){
cout << IntToLetter((*it).first) << ":" << IntToLetter((*it).second) << endl;
}*/
cout << "Appuyer sur Entree pour terminer" << endl;
cin.get();
cin.get();
return 0;
}