-
Notifications
You must be signed in to change notification settings - Fork 0
/
hc_to_concorde.c
80 lines (61 loc) · 1.49 KB
/
hc_to_concorde.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
/*
* creates a concord matrix style for concorde
* input is an edge list file output a weighted
* adjacency matrix 0 if edge exists and 1
* if no edge exists
*/
#include <stdio.h>
#include "hclib.h"
static void print_usage();
int main(int argc, char *argv[])
{
/* read command line arguments */
char *graph_file;
char *out_file;
FILE * fp;
if (argc > 1)
{
graph_file = argv[1];
out_file = argv[2];
} else
{
print_usage();
return 1;
}
/* read graph file */
int **graph;
int node_count;
int edge_count;
graph = read_graph(graph_file, &node_count, &edge_count);
printf("Graph has %d nodes and %d edges\n", node_count, edge_count);
int i;
int j;
/* setup the output file */
fp = fopen(out_file,"w+");
if (!fp) {
printf("Could not open file for writting %s\n", out_file);
return 1;
}
/* convert 0 to 1 in adjacency matrix */
for (i = 1; i <= node_count; i++) {
for (j = 1; j <= node_count; j++) {
if (j > 1) {
fprintf(fp," ");
} //if
fprintf(fp,"%i", (graph[i][j] ? 0 : 1) );
}
fputs("\n",fp);
}
/* cleanup */
if (fp) {
fclose(fp);
}
free_graph(graph, &node_count);
return 0;
}
static void print_usage()
{
printf("Converts graphfile into concorde compatible matrix");
printf("Usage:\n");
printf("hc_to_dot graphfile.hcp dotfile.opt\n");
}