Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Graphe valeursPlusCourtsCheminsFloyd () {
- // on commence par dupliquer la matrice de départ, on obtient la matrice intitulee matriceM
- Graphe matriceM = this.dupliqueGraphe();
- // changer la diagonale : matriceM[i][i] a 0
- for(int i = 0; i<this.getNombreSommets();i++){
- matriceM.graphe[i][i]=0;
- }
- // toutes les valeurs < 0 donc sans arcs sont passées à + l'infini
- for(int i = 0; i<this.getNombreSommets();i++){
- for(int j = 0;j<this.getNombreSommets();j++){
- if(matriceM.graphe[i][j]<0)
- matriceM.graphe[i][j]=Integer.MAX_VALUE;
- }
- }
- // la triple boucle en "blindant" pour éviter des calculs du type Integer.MAX_VALUE + autre chose qui feraient
- // un depassement de capacite
- for(int k = 0; k<this.getNombreSommets();k++){
- for(int i = 0; i<this.getNombreSommets();i++){
- for(int j = 0; j<this.getNombreSommets();j++){
- if(matriceM.graphe[i][k]<Integer.MAX_VALUE && matriceM.graphe[k][j]<Integer.MAX_VALUE){
- if(matriceM.graphe[i][k]+matriceM.graphe[k][j]<matriceM.graphe[i][j]){
- matriceM.graphe[i][j]=matriceM.graphe[i][k]+matriceM.graphe[k][j];
- }
- }
- }
- }
- }
- return matriceM;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement