Graphes  0.1
graphes.h
Aller à la documentation de ce fichier.
1 
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <math.h>
8 
9 #define TYP_VARC long
10 #define TYP_VSOM long
11 #ifndef HUGE
12 #define HUGE HUGE_VAL
13 #endif
14 #define SHRT_MIN -32767
15 #define SHRT_MAX +32767
16 #define USHRT_MAX 65535
17 #define INT_MIN -32767
18 #define INT_MAX +32767
19 #define UINT_MAX 65535
20 #define LONG_MIN -2147483647
21 #define LONG_MAX +2147483647
22 #define ULONG_MAX 4294967295
23 #define M_PI 3.14159265358979323846
24 #define max(X,Y) ((X)>=(Y)?(X):(Y))
25 #define min(X,Y) ((X)<=(Y)?(X):(Y))
26 
27 /* ================================================ */
28 /* types publics */
29 /* ================================================ */
30 
34 typedef struct cell {
36  int som;
38  TYP_VARC v_arc;
40  struct cell * next;
41 } cell;
42 
46 typedef cell * pcell;
47 
48 
52 typedef struct graphe {
53 
54  /* informations globales */
55 
57  int nsom;
59  int nmaxarc;
61  int narc;
62 
63  /* representation par listes chainees de successeurs (application gamma) */
64 
71 
72  /* representation par liste d'arcs
73  (vecteurs tete (sommet initial), queue (sommet final)) */
74 
76  int *tete;
78  int *queue;
79 
80  /* informations additionelles ajoutees aux arcs */
81 
83  TYP_VARC *v_arcs;
84 
85  /* informations additionelles ajoutees aux sommets */
86 
88  TYP_VSOM *v_sommets;
89 
91  double *x;
93  double *y;
95  char **nomsommet;
96 } graphe;
97 
98 /* ================================================ */
99 /* prototypes */
100 /* ================================================ */
101 
102 extern void AfficheEnsemble(boolean *s, int n);
103 extern void AfficheListe(pcell p);
104 extern void AfficheSuccesseurs(graphe * g) ;
105 extern void AfficheArcs(graphe * g);
106 extern void AfficheValeursSommets(graphe * g);
107 extern void PSGraphe(graphe * g, char *filename, double r, double t, double marge);
108 void EPSGraphe(graphe * g, char *filename, double r, double t, double marge, int noms_sommets, int v_sommets, int col_sommets, int v_arcs);
109 
110 /* ====================================================================== */
111 /* ====================================================================== */
112 /* FONCTIONS DE PLONGEMENT DE GRAPHES DANS LE PLAN */
113 /* ====================================================================== */
114 /* ====================================================================== */
115 
116 extern void AutoNomsSommets(graphe * g, int mode);
117 extern void PlongementCirculaire(graphe * g, double r);
118 extern void PlongementRadial(graphe * g, int c);
119 
120 /* ====================================================================== */
121 /* ====================================================================== */
122 /* FONCTIONS SUR LES LISTES CHAINEES DE SOMMETS */
123 /* ====================================================================== */
124 /* ====================================================================== */
125 
126 extern pcell AlloueCell(pcell * plibre);
127 extern void LibereCell(pcell * plibre, pcell p);
128 extern void RetireTete(pcell * plibre, pcell * pliste);
129 extern void AjouteTete(pcell * plibre, pcell * pliste, int a, TYP_VARC v);
130 extern int EstDansListe(pcell p, int a);
131 
132 /* ====================================================================== */
133 /* ====================================================================== */
134 /* FONCTIONS D'ALLOCATION / LIBERATION POUR UN GRAPHE */
135 /* ====================================================================== */
136 /* ====================================================================== */
137 
138 extern graphe * InitGraphe(int nsom, int nmaxarc);
139 extern void TermineGraphe(graphe * g);
140 extern graphe * ReadGraphe(char * filename);
141 
142 /* ====================================================================== */
143 /* ====================================================================== */
144 /* FONCTIONS DE MANIPULATION DES ARCS (APPLICATION GAMMA UNIQUEMENT) */
145 /* ====================================================================== */
146 /* ====================================================================== */
147 
148 extern void AjouteArc(graphe * g, int i, int s);
149 extern void AjouteArcValue(graphe * g, int i, int s, TYP_VARC v);
150 extern void RetireArc(graphe * g, int i, int s);
151 extern int PopSuccesseur(graphe *g, int i);
152 extern int EstSuccesseur(graphe *g, int i, int s);
153 
154 /* ====================================================================== */
155 /* ====================================================================== */
156 /* FONCTIONS DE GENERATION DE GRAPHES */
157 /* ====================================================================== */
158 /* ====================================================================== */
159 
160 extern graphe * GrapheAleatoire(int nsom, int narc);
161 
162 /* ====================================================================== */
163 /* ====================================================================== */
164 /* OPERATEURS DE BASE SUR LES GRAPHES */
165 /* ====================================================================== */
166 /* ====================================================================== */
167 
168 extern graphe * Symetrique(graphe * g);
void TermineGraphe(graphe *g)
libère la memoire occupée par le graphe g.
Definition: graph_basic.c:183
pcell libre
liste des cellules libres gérée en pile lifo
Definition: graphes.h:68
double * y
ordonnees des sommets
Definition: graphes.h:93
void AutoNomsSommets(graphe *g, int mode)
génère automatiquement des noms pour les sommets du graphe g.
Definition: graph_print.c:335
TYP_VARC * v_arcs
tableau des valeurs associées aux arcs
Definition: graphes.h:83
TYP_VSOM * v_sommets
tableau des valeurs associées aux sommets
Definition: graphes.h:88
pcell AlloueCell(pcell *plibre)
retire la premiere cellule de la liste pointée par plibre et retourne un pointeur sur cette cellule...
Definition: graph_basic.c:22
TYP_VARC v_arc
poids de l'arc pour les graphes pondérés
Definition: graphes.h:38
double * x
abcisses des sommets
Definition: graphes.h:91
void AfficheEnsemble(boolean *s, int n)
affiche à l'écran l'ensemble representé par le tableau de booléens s.
Definition: graph_print.c:22
char ** nomsommet
noms des sommets
Definition: graphes.h:95
struct cell * next
suite de la liste ou pointeur NULL
Definition: graphes.h:40
int * queue
tableau des extremités finales d'arcs
Definition: graphes.h:78
void AfficheSuccesseurs(graphe *g)
affiche le graphe dans sa représentation "listes de successeurs".
Definition: graph_print.c:46
structure pour la representation des graphes
Definition: graphes.h:52
void AfficheArcs(graphe *g)
affiche le graphe dans sa représentation "listes d'arcs".
Definition: graph_print.c:68
void AjouteArc(graphe *g, int i, int s)
ajoute l'arc (i,s) au graphe g (application gamma seulement).
Definition: graph_basic.c:300
void PlongementRadial(graphe *g, int c)
répartit les sommets de g sur des cercles concentriques en fonction de leur rang, avec le sommet c au c...
Definition: graph_print.c:400
pcell reserve
tableau des cellules en réserve
Definition: graphes.h:66
void EPSGraphe(graphe *g, char *filename, double r, double t, double marge, int noms_sommets, int v_sommets, int col_sommets, int v_arcs)
génère une figure PostScript d'après la représentation "successeurs" du graphe g.
Definition: graph_print.c:217
int nmaxarc
nombre maximum d'arcs
Definition: graphes.h:59
graphe * InitGraphe(int nsom, int nmaxarc)
alloue la memoire nécessaire pour représenter un graphe a 'nsom' sommets, possédant au maximum 'nmaxarc' ar...
Definition: graph_basic.c:113
void LibereCell(pcell *plibre, pcell p)
insère la cellule p au début de la liste pointée par 'plibre'.
Definition: graph_basic.c:42
void AjouteTete(pcell *plibre, pcell *pliste, int a, TYP_VARC v)
ajoute une cellule contenant le sommet 'a' et la valeur 'v' en tête de la liste 'pliste'. La cellule est prise dans la liste 'plibre'.
Definition: graph_basic.c:72
void AjouteArcValue(graphe *g, int i, int s, TYP_VARC v)
ajoute l'arc (i,s) au graphe g (application gamma seulement).
Definition: graph_basic.c:315
pcell * gamma
tableau des listes de successeurs indexé par les sommets
Definition: graphes.h:70
structure de cellule pour les listes chaînees de successeurs.
Definition: graphes.h:34
int PopSuccesseur(graphe *g, int i)
retire un arc (i,s) du graphe g (application gamma seulement), et retourne le sommet s ...
Definition: graph_basic.c:349
graphe * GrapheAleatoire(int nsom, int narc)
retourne un graphe aléatoire à 'nsom' sommets et 'narc' arcs. Le graphe est antisymétrique et sans bouc...
Definition: graph_basic.c:389
int * tete
tableau des extremités initiales d'arcs
Definition: graphes.h:76
cell * pcell
pointeur sur une cellule
Definition: graphes.h:46
void PlongementCirculaire(graphe *g, double r)
affecte à chaque sommet des coordonnées (x,y) régulierement réparties sur un cercle.
Definition: graph_print.c:376
void PSGraphe(graphe *g, char *filename, double r, double t, double marge)
génère une figure PostScript d'après la représentation "successeurs" du graphe g.
Definition: graph_print.c:116
int nsom
nombre de sommets
Definition: graphes.h:57
graphe * ReadGraphe(char *filename)
Lit les données d'un graphe dans le fichier filename, retourne un pointeur sur la structure graphe cons...
Definition: graph_basic.c:213
int narc
nombre d'arcs
Definition: graphes.h:61
int som
index du sommet
Definition: graphes.h:36
void AfficheListe(pcell p)
affiche le contenu de la liste p.
Definition: graph_print.c:34
void RetireTete(pcell *plibre, pcell *pliste)
retire la première cellule de la liste 'pliste'. La cellule est chaînee à la liste 'plibre'.
Definition: graph_basic.c:55
void RetireArc(graphe *g, int i, int s)
retire l'arc (i,s) du graphe g (application gamma seulement), si celui-ci etait présent. Sinon, pas d'action.
Definition: graph_basic.c:330
int EstDansListe(pcell p, int a)
retourne 1 si le sommet 'a' se trouve dans la liste 'p', 0 sinon.
Definition: graph_basic.c:90
void AfficheValeursSommets(graphe *g)
affiche les valeurs associées aux sommets.
Definition: graph_print.c:93
int EstSuccesseur(graphe *g, int i, int s)
retourne 1 si le sommet 's' est un successeur du sommet 'i', 0 sinon.
Definition: graph_basic.c:365