#include #include #include #include #include using namespace std; const int N=10; const int M=(N*(N-1))/2; typedef struct coord{int abs; int ord;} coord; typedef struct point{int x; int y;} point; void pointRandom(int n,coord point[][]); float distancexy(coord p1,coord p2); void voisins(int n,int dmax,coord point[][],vector voisin[][],int &m); void voisins2arete(int n,vectorvoisins[],int arete[][2]); void affichageGraphique(int n,int m,coord point[][],vector voisins[][],const char * name); bool existe(int n,int dis[],bool traite[]); int searchsmallest(int n, int dist[],bool traite[]); void dijkstra(int n,vector voisin[][],coord point[][],int pere[], int m); int construireArbre(int n,vector voisin[],int pere[]); int main(){ int n; // Le nombre de points. cout << "Entrer le nombre de points: "; cin >> n; int dmax=50; // La distance jusqu'a laquelle on relie deux points. coord point[N][N]; // Les coordonnees des points. vector voisin[N][N]; vector voisinbis[N]; // Les listes de voisins. int arbre[N-1][2]; // Les aretes de l'arbre de Dijkstra. int pere[N]; // La relation de filiation de l'arbre de Dijkstra. int m; // Le nombre d'aretes int arete[M][2]; // Les aretes du graphe pointRandom(n,point); voisins(n,dmax, point, voisin, m); const char * filename = "affichage.ps"; affichageGraphique(n,m,point,voisin,filename); // cout<<"Graphe de base créé et exporté vers "< voisins[][], int &m){ int arrete = 0; for (int i = 0; i < 10; i ++){ for (int j = 0; j < 10; j ++){ for (int o = 0; o < 10 ; o ++){ for (int k = 0; k < 10; k ++){ if (((o==i+1) && (j==k))|| ((k==j+1) && (i==o)) || ((o==i+1) && (k==j+1))){ point tmp; tmp.x=o; tmp.y=k; voisins[i][j].push_back(tmp); tmp.x=i; tmp.y=j; voisins[o][k].push_back(tmp); } } } } } } void affichageGraphique(int n, int m, coord point[], vector voisins[], const char * filename) // Cree le fichier Exemple.ps qui affiche // les points et l'arbre de Kruskal. { ofstream output; output.open(filename,ios::out); output << "%!PS-Adobe-3.0" << endl; output << "%%BoundingBox: 0 0 612 792" << endl; output << endl; for(int i=0;i<10;i++) for (int j = 0 ; j < 10; j ++){ { output << point[i][j].abs << " " << point[i][j].ord << " 3 0 360 arc" < voisin[], coord point[], int pere[], int m){ int d[n]; bool traite[n]; for (int i =0; i < n; i ++){ d[i]= -1; traite[i]=false; } pere[0]=0; d[0]=0; while (existe(n,d,traite)){ int current = searchsmallest(n,d,traite); //cout<<"C'est ti-par avec current = "<< current <(d[x]+distancexy(point[x],point[y]))))){ d[y]=d[x]+distancexy(point[x],point[y]); pere[y]=x; } } } } int construireArbre(int n,vector voisin[],int pere[]){ for ( int i = 0; i < n; i ++){ voisin[i].push_back(pere[i]); voisin[pere[i]].push_back(i); } return n; }