-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
241 lines (223 loc) · 6.22 KB
/
main.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>
#include "veinteveinte.h"
#include "GrafoSt2020.h"
#include "parser.h"
#include "helpers.h"
int main()
{
char welsh[3] = "-w";
char aleat[3] = "-a";
char cg[3] = "-c";
char rbc[3] = "-r";
char numcc[3] = "-n";
char bip[3] = "-b";
char gr[3] = "-g";
char nat[4] = "-nt";
char q[4] = "-q";
char wg[4] = "-wg";
char rc[4] = "-rc" ;
char cc[4] = "-cc";
clock_t t_ini, t_fin;
double secs;
char op[4]="";
printf("empeze a construir el grafo\n");
Grafo g = ConstruccionDelGrafo();
printf("termine de construir el grafo\n");
while(true)
{
printf("modo de uso:\n -g : Greedy n veces \n -w : WelshPowell y Greedy \n"
" -a : AleatorizarVertices y Greedy\n -c : ChicoGrandeBC y Greedy \n -r :"
"RevierteBC y Greedy \n -n : NumCCs \n -b : Bipartito\n -nt : Orden Natural \n"
" -q : break \n -wg : WelshPowell y sus grados\n -rc : RevierteBC y sus colores\n"
"-cc : ChicoGrandeBC y sus colores\n");
printf("Opción:\n");
scanf("%s",*(&op));
printf("opcion elegida %s\n",op);
if (0 == strcmp(op,welsh))
{
printf("WelshPowell Y Greedy 1100 iteraciones\n");
t_ini = clock();
for (u32 i = 0; i < 1000; i++) {
char check = WelshPowell(g);
if (check != '0'){
printf("error\n");
exit(EXIT_FAILURE);
}
u32 color = Greedy(g);
printf("%lu \n",color);
}
t_fin = clock();
secs = (double)(t_fin - t_ini) / CLOCKS_PER_SEC;
printf("\n%.16g segundos\n", secs);
}else if(0 == strcmp(op ,aleat))
{
printf("AleatorizarVertices Y Greedy 1100 iteraciones\n");
/*printf("empeze a construir el grafo\n");
Grafo g = ConstruccionDelGrafo();
printf("termine de construir el grafo\n");*/
t_ini = clock();
for (u32 i = 0; i < 1000; i++) {
char check = AleatorizarVertices(g,i);
if (check != '0'){
printf("error\n");
exit(EXIT_FAILURE);
}
u32 color = Greedy(g);
printf("%lu \n",color);
}
t_fin = clock();
secs = (double)(t_fin - t_ini) / CLOCKS_PER_SEC;
printf("\n%.16g segundos\n", secs);
}else if (0 == strcmp(op,cg))
{
printf("ChicoGrandeBC Y Greedy 1100 iteraciones\n");
/*printf("empeze a construir el grafo\n");
Grafo g = ConstruccionDelGrafo();
printf("termine de construir el grafo\n");*/
t_ini = clock();
for (u32 i = 0; i < 1000; i++) {
u32 color = Greedy(g);
printf("%lu \n",color);
char check = ChicoGrandeBC(g);
if (check != '0'){
printf("error\n");
exit(EXIT_FAILURE);
}
}
t_fin = clock();
secs = (double)(t_fin - t_ini) / CLOCKS_PER_SEC;
printf("\n%.16g segundos\n", secs);
}else if (0 == strcmp(op,rbc))
{
printf("RevierteBC Y Greedy 1100 iteraciones\n");
/*printf("empeze a construir el grafo\n");
Grafo g = ConstruccionDelGrafo();
printf("termine de construir el grafo\n");*/
t_ini = clock();
for (u32 i = 0; i < 1000; i++) {
char check = RevierteBC(g);
if (check != '0'){
printf("error\n");
exit(EXIT_FAILURE);
}
u32 color = Greedy(g);
printf("%lu \n",color);
}
t_fin = clock();
secs = (double)(t_fin - t_ini) / CLOCKS_PER_SEC;
printf("\n%.16g segundos\n", secs);
}else if (0 == strcmp(op,numcc))
{
printf("NumCCs 1100 iteraciones\n");
/*printf("empeze a construir el grafo\n");
Grafo g = ConstruccionDelGrafo();
printf("termine de construir el grafo\n");*/
t_ini = clock();
for (u32 i = 0; i < 1000; i++) {
u32 numcc = NumCCs(g);
if (numcc == 0){
printf("error\n");
exit(EXIT_FAILURE);
}
printf("numcc -> %lu \n",numcc);
}
t_fin = clock();
secs = (double)(t_fin - t_ini) / CLOCKS_PER_SEC;
printf("\n%.16g segundos\n", secs);
}else if (0 == strcmp(op,bip))
{
printf("Bipartito 1100 iteraciones\n");
/*printf("empeze a construir el grafo\n");
Grafo g = ConstruccionDelGrafo();
printf("termine de construir el grafo\n");*/
t_ini = clock();
for (u32 i = 0; i < 1000; i++) {
char bipartito = Bipartito(g);
printf("bipartito -> %c \n",bipartito);
}
t_fin = clock();
secs = (double)(t_fin - t_ini) / CLOCKS_PER_SEC;
printf("\n%.16g segundos\n", secs);
}else if(0 == strcmp(op,gr))
{
printf("Indique n: \n");
u32 n = 0;
scanf("%lu",&n);
if (n > 0){
printf("Greedy %lu veces\n",n);
/*printf("empeze a construir el grafo\n");
Grafo g = ConstruccionDelGrafo();
printf("termine de construir el grafo\n");*/
t_ini = clock();
for (u32 i = 0; i < n; i++) {
u32 color = Greedy(g);
printf("%lu \n",color);
}
t_fin = clock();
secs = (double)(t_fin - t_ini) / CLOCKS_PER_SEC;
printf("\n%.16g segundos\n", secs);
}
}else if(0 == strcmp(op,nat)){
printf("Orden natural\n");
t_ini = clock();
OrdenNatural(g);
t_fin = clock();
secs = (double)(t_fin - t_ini) / CLOCKS_PER_SEC;
printf("\n%.16g segundos\n", secs);
}
else if(0 == strcmp(op,q))
{
printf("Break\n");
break;
}
else if(0 == strcmp(op,wg)){
printf("WelshPowell con sus grados\n");
t_ini = clock();
WelshPowell(g);
for(u32 i=0; i<NumeroDeVertices(g);i++)
{
printf("Nombre %lu; Grado %lu\n",Nombre(i,g), Grado(i,g));
}
printf("Grado Grafo %lu\n",Delta(g));
t_fin = clock();
secs = (double)(t_fin - t_ini) / CLOCKS_PER_SEC;
printf("\n%.16g segundos\n", secs);
}
else if(0 == strcmp(op,rc)){
printf("RevierteBC con sus colores\n");
t_ini = clock();
Greedy(g);
RevierteBC(g);
for(u32 i=0; i<NumeroDeVertices(g);i++)
{
printf("Nombre %lu; Color %lu\n",Nombre(i,g), Color(i,g));
}
t_fin = clock();
secs = (double)(t_fin - t_ini) / CLOCKS_PER_SEC;
printf("\n%.16g segundos\n", secs);
}
else if(0 == strcmp(op,cc)){
printf("ChicoGrandeBC con sus colores\n");
t_ini = clock();
Greedy(g);
ChicoGrandeBC(g);
for(u32 i=0; i<NumeroDeVertices(g);i++)
{
printf("Nombre %lu; Color %lu\n",Nombre(i,g), Color(i,g));
}
t_fin = clock();
secs = (double)(t_fin - t_ini) / CLOCKS_PER_SEC;
printf("\n%.16g segundos\n", secs);
}
else {
printf("Argumento Invalido\n");
}
}
DestruccionDelGrafo(g);
return 0;
}