2
2
#include <graphviz/cgraph.h>
3
3
#include <stdio.h>
4
4
#include <stdlib.h>
5
+ #include <string.h>
6
+
7
+ char rec_name [14 ] = "info_vertice" ;
5
8
6
9
typedef struct {
7
10
Agrec_t header ;
@@ -12,6 +15,7 @@ typedef struct {
12
15
typedef struct {
13
16
Agrec_t header ;
14
17
int criada ;
18
+ int padding ;
15
19
} info_aresta ;
16
20
17
21
static int backtrack_conexo (grafo g , vertice atual , int * contador_vertices ); // funcao que auxilia a funcao "conexo"
@@ -24,7 +28,8 @@ void assign(grafo g, vertice u, vertice root, grafo subgrafo);
24
28
grafo le_grafo (void )
25
29
{
26
30
grafo g = agread (stdin , NULL );
27
- aginit (g , AGNODE , "info_vertice" , sizeof (info_vertice ), TRUE);
31
+ // strcpy(rec_name, "info_vertice");
32
+ aginit (g , AGNODE , rec_name , sizeof (info_vertice ), TRUE);
28
33
return g ;
29
34
}
30
35
//------------------------------------------------------------------------------
@@ -149,11 +154,12 @@ int completo(grafo g) {
149
154
int conexo (grafo g )
150
155
{
151
156
info_vertice * info ;
157
+ // strcpy(rec_name, "info_vertice");
152
158
153
159
for (vertice v = agfstnode (g ); v ; v = agnxtnode (g ,v ))
154
160
{
155
- //info = agbindrec(v, "info_vertice" , sizeof(info_vertice), TRUE);
156
- info = (info_vertice * ) aggetrec (v , "info_vertice" , TRUE);
161
+ //info = agbindrec(v, rec_name , sizeof(info_vertice), TRUE);
162
+ info = (info_vertice * ) aggetrec (v , rec_name , TRUE);
157
163
info -> contado = 0 ;
158
164
}
159
165
@@ -165,7 +171,8 @@ int conexo(grafo g)
165
171
static int backtrack_conexo (grafo g , vertice atual , int * contador_vertices ) // funcao que auxilia a funcao "conexo"
166
172
{
167
173
info_vertice * info ;
168
- info = (info_vertice * ) aggetrec (atual , "info_vertice" , TRUE);
174
+ // strcpy(rec_name, "info_vertice");
175
+ info = (info_vertice * ) aggetrec (atual , rec_name , TRUE);
169
176
170
177
if (info -> contado == 0 ) // contabiliza o vertice
171
178
{
@@ -195,10 +202,11 @@ static int backtrack_conexo(grafo g, vertice atual, int *contador_vertices) // f
195
202
/// funcao auxiliar que checa se o componente do vertice v é um subgrafo bipartido.
196
203
int bipartido (grafo g ) {
197
204
info_vertice * info ;
205
+ // strcpy(rec_name, "info_vertice");
198
206
199
207
for (vertice v = agfstnode (g ); v ; v = agnxtnode (g ,v ))
200
208
{
201
- info = (info_vertice * ) aggetrec (v , "info_vertice" , TRUE);
209
+ info = (info_vertice * ) aggetrec (v , rec_name , TRUE);
202
210
info -> contado = -1 ;
203
211
}
204
212
@@ -214,7 +222,8 @@ int bipartido(grafo g) {
214
222
215
223
static int backtrack_bipartido (grafo g , vertice v , int cor_atual ) {
216
224
info_vertice * info ;
217
- info = (info_vertice * ) aggetrec (v , "info_vertice" , TRUE);
225
+ // strcpy(rec_name, "info_vertice");
226
+ info = (info_vertice * ) aggetrec (v , rec_name , TRUE);
218
227
if (info == NULL ) {
219
228
printf ("eita\n" );
220
229
}
@@ -332,7 +341,9 @@ int **matriz_adjacencia(grafo g)
332
341
// -----------------------------------------------------------------------------
333
342
grafo complemento (grafo g )
334
343
{
335
- grafo h = agopen ("complemento" , g -> desc , NULL );
344
+ char complemento [13 ] = "complemento" ;
345
+ char aresta [7 ] = "aresta" ;
346
+ grafo h = agopen (complemento , g -> desc , NULL );
336
347
337
348
// criando o mesmo numero de nodos no novo grafo
338
349
for (vertice v = agfstnode (g ); v ; v = agnxtnode (g , v )) {
@@ -344,7 +355,7 @@ grafo complemento(grafo g)
344
355
if (ga != gb && ha != hb ) {
345
356
if (!agedge (g , ga , gb , NULL , 0 )) {
346
357
// se nao existe no original, existe no complemento
347
- agedge (h , ha , hb , " aresta" , 1 );
358
+ agedge (h , ha , hb , aresta , 1 );
348
359
}
349
360
}
350
361
}
@@ -357,7 +368,8 @@ grafo complemento(grafo g)
357
368
void visit (grafo g , vertice u , vertice * stack , int * topo_stack )
358
369
{
359
370
info_vertice * info ;
360
- info = (info_vertice * ) aggetrec (u , "info_vertice" , TRUE);
371
+ // strcpy(rec_name, "info_vertice");
372
+ info = (info_vertice * ) aggetrec (u , rec_name , TRUE);
361
373
362
374
// If u is unvisited then:
363
375
if (info -> contado == 0 )
@@ -379,13 +391,14 @@ void visit(grafo g, vertice u, vertice* stack, int* topo_stack)
379
391
void assign (grafo g , vertice u , vertice root , grafo subgrafo )
380
392
{
381
393
info_vertice * info_root ;
382
- info_root = (info_vertice * ) aggetrec (root , "info_vertice" , TRUE);
394
+ // strcpy(rec_name, "info_vertice");
395
+ info_root = (info_vertice * ) aggetrec (root , rec_name , TRUE);
383
396
384
397
385
398
// For each in-neighbour v of u, do Assign(v,root)
386
399
for (Agedge_t * e = agfstin (g , u ); e ; e = agnxtin (g , e )) // esse agnxtout funciona?
387
400
{
388
- info_vertice * info_prox = (info_vertice * ) aggetrec (e -> node , "info_vertice" , TRUE);
401
+ info_vertice * info_prox = (info_vertice * ) aggetrec (e -> node , rec_name , TRUE);
389
402
390
403
if (info_prox -> componente == 0 ) {
391
404
// não definiu o componente ainda
@@ -411,17 +424,18 @@ void assign(grafo g, vertice u, vertice root, grafo subgrafo)
411
424
grafo decompoe (grafo g )
412
425
{
413
426
info_vertice * info ;
427
+ // strcpy(rec_name, "info_vertice");
414
428
415
429
// For each vertex u of the graph, mark u as unvisited. Let L be empty.
416
430
for (vertice v = agfstnode (g ); v ; v = agnxtnode (g ,v ))
417
431
{
418
- info = (info_vertice * ) aggetrec (v , "info_vertice" , TRUE);
432
+ info = (info_vertice * ) aggetrec (v , rec_name , TRUE);
419
433
info -> contado = 0 ; // nao visitado
420
434
info -> componente = 0 ; // nao faz parte de nenhum componente
421
435
}
422
436
423
437
// "stack" L?
424
- vertice * stack = (vertice * ) calloc (agnnodes (g ), sizeof (vertice ));
438
+ vertice * stack = (vertice * ) calloc (( size_t ) agnnodes (g ), sizeof (vertice ));
425
439
int topo_stack = 0 ;
426
440
427
441
// For each vertex u of the graph do Visit(u)
@@ -436,17 +450,17 @@ grafo decompoe(grafo g)
436
450
while (topo_stack != 0 ) {
437
451
vertice u = stack [-- topo_stack ];
438
452
439
- info_vertice * info = (info_vertice * ) aggetrec (u , "info_vertice" , TRUE);
453
+ info_vertice * info2 = (info_vertice * ) aggetrec (u , rec_name , TRUE);
440
454
441
- if (info -> componente == 0 ) {
455
+ if (info2 -> componente == 0 ) {
442
456
// Cria um subgrafo de g para servir de componente.
443
457
grafo s = agsubg (g , NULL , TRUE);
444
458
445
459
// adiciona u a seu próprio componente
446
460
agsubnode (s , u , TRUE);
447
461
448
462
// seta um novo id para o componente
449
- info -> componente = ++ id_componente ;
463
+ info2 -> componente = ++ id_componente ;
450
464
451
465
assign (g , u , u , s );
452
466
}
0 commit comments