-
Notifications
You must be signed in to change notification settings - Fork 1
/
random.c
149 lines (121 loc) · 3.4 KB
/
random.c
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
/******************************************************
Copyright 2004, 2010 Fabien de Montgolfier
fm@liafa.jussieu.fr
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**********************************************************/
#include <time.h>
#include "dm_english.h"
#define NIV 20
#define VERBEUX 1
//extern noeud *decomposition_modulaire(int *,int);
extern void printarbre(noeud *);
/* ppm est la part par million d'arretes voulues dans le graphe */
void compte(noeud *N, int level, int *C)
{
fils *F;
switch(N->type)
{
case SERIE: C[4*level]++; break;
case PARALLELE: C[4*level+1]++; break;
case PREMIER: C[4*level+2]++; break;
case FEUILLE: C[4*level+3]++; break;
}
if(N->type!=FEUILLE)
for(F=N->fils;F!=NULL;F=F->suiv)
compte(F->pointe, level+1, C);
}
void test(int n, long int ppm, int *C)
{
/*genere un graphe aleatoire, l'affiche, le decompose*/
graphe G;
int i,j;
adj *a;
noeud *R;
srandom((unsigned)time(NULL));
G.n=n;
G.G=(adj **)malloc(n*sizeof(adj *));
for(i=0;i<n;i++)
G.G[i]=NULL;
printf("Programme test : generation d'un graphe aleatoire de %i sommets\n",n);
for(i=0; i<n; i++)
{
if(VERBEUX)
{
printf("Ajacence de %i: ",i);
for(a=G.G[i]; a!=NULL; a=a->suiv)
printf("%i ",a->s);
}
for(j=i+1;j<n;j++)
{
if( (random()%1000000L) < ppm )
{
// ajoute j a l'adjacence de i
a=(adj *)malloc(sizeof(adj));
a->s=j;
a->suiv=G.G[i];
G.G[i]=a;
// et reciproquement
a=(adj *)malloc(sizeof(adj));
a->s=i;
a->suiv=G.G[j];
G.G[j]=a;
if(VERBEUX)
printf("%i ",j);
}
}
if(VERBEUX)
printf("\n");
}
// appel de la fonction de decomposition
R = decomposition_modulaire(G);
// affichage de l'arbre
if(VERBEUX)
printarbre(R);
compte(R,0,C);
printf("Statistiques sur l'arbre de decomposition:\n");
if(C[0])
printf("La racine est Serie\n");
else if(C[1])
printf("La racine est Parrallele\n");
else
printf("La racine est Premier \n");
for(i=1 ; i<NIV ; i++)
{
printf("Niveau %i: %i modules (S-P-Pr= %i - %i - %i) et %i feuilles\n",i,
C[4*i]+C[4*i+1]+C[4*i+2], C[4*i], C[4*i+1], C[4*i+2],C[4*i+3]);
if(i<NIV-1 && C[4*i+4]+C[4*i+5]+C[4*i+6]+C[4*i+7]==0)
break;
}
printf("\n");
}
int main(int narg, char **arg)
{
int n;
long ppm;
int C[4*NIV];int i;
if(narg!=3)
{
printf("Decomposition modulaire de graphes \"aleatoires\" \n"
"Donnez en argument:\n"
"le nombre de sommets du graphe\n"
"puis la proportion d'aretes en en millioniemes \n"
"(generateur aleatoire tres primaire)\n"
"Exemple : %s 100 20000\n",arg[0]);
exit(0);
}
n=atoi(arg[1]);
ppm=atol(arg[2]);
for(i=0;i<4*NIV;i++) C[i]=0;
test(n, ppm, C);
return 0;
}