0
|
1 // File: main_convert.cpp
|
|
2 // -- conversion of a graph from ascii to binary, sample main file
|
|
3 //-----------------------------------------------------------------------------
|
|
4 // Community detection
|
|
5 // Based on the article "Fast unfolding of community hierarchies in large networks"
|
|
6 // Copyright (C) 2008 V. Blondel, J.-L. Guillaume, R. Lambiotte, E. Lefebvre
|
|
7 //
|
|
8 // This program must not be distributed without agreement of the above mentionned authors.
|
|
9 //-----------------------------------------------------------------------------
|
|
10 // Author : E. Lefebvre, adapted by J.-L. Guillaume
|
|
11 // Email : jean-loup.guillaume@lip6.fr
|
|
12 // Location : Paris, France
|
|
13 // Time : February 2008
|
|
14 //-----------------------------------------------------------------------------
|
|
15 // see readme.txt for more details
|
|
16
|
|
17 #include "graph.h"
|
|
18
|
|
19 using namespace std;
|
|
20
|
|
21 char *infile = NULL;
|
|
22 char *outfile = NULL;
|
|
23 char *outfile_w = NULL;
|
|
24 int type = UNWEIGHTED;
|
|
25 bool do_renumber = false;
|
|
26
|
|
27 void
|
|
28 usage(char *prog_name, const char *more) {
|
|
29 cerr << more;
|
|
30 cerr << "usage: " << prog_name << " -i input_file -o outfile [-r] [-w outfile_weight]" << endl << endl;
|
|
31 cerr << "read the graph and convert it to binary format." << endl;
|
|
32 cerr << "-r\tnodes are renumbered from 0 to nb_nodes-1 (the order is kept)." << endl;
|
|
33 cerr << "-w filename\tread the graph as a weighted one and writes the weights in a separate file." << endl;
|
|
34 cerr << "-h\tshow this usage message." << endl;
|
|
35 exit(0);
|
|
36 }
|
|
37
|
|
38 void
|
|
39 parse_args(int argc, char **argv) {
|
|
40 for (int i = 1; i < argc; i++) {
|
|
41 if(argv[i][0] == '-') {
|
|
42 switch(argv[i][1]) {
|
|
43 case 'i':
|
|
44 if (i==argc-1)
|
|
45 usage(argv[0], "Infile missing\n");
|
|
46 infile = argv[i+1];
|
|
47 i++;
|
|
48 break;
|
|
49 case 'o':
|
|
50 if (i==argc-1)
|
|
51 usage(argv[0], "Outfile missing\n");
|
|
52 outfile = argv[i+1];
|
|
53 i++;
|
|
54 break;
|
|
55 case 'w' :
|
|
56 type = WEIGHTED;
|
|
57 outfile_w = argv[i+1];
|
|
58 i++;
|
|
59 break;
|
|
60 case 'r' :
|
|
61 do_renumber=true;
|
|
62 break;
|
|
63 default:
|
|
64 usage(argv[0], "Unknown option\n");
|
|
65 }
|
|
66 } else {
|
|
67 usage(argv[0], "More than one filename\n");
|
|
68 }
|
|
69 }
|
|
70 if (infile==NULL || outfile==NULL)
|
|
71 usage(argv[0], "In or outfile missing\n");
|
|
72 }
|
|
73
|
|
74 int
|
|
75 main(int argc, char **argv) {
|
|
76 parse_args(argc, argv);
|
|
77
|
|
78 Graph g(infile, type);
|
|
79
|
|
80 g.clean(type);
|
|
81
|
|
82 if (do_renumber)
|
|
83 g.renumber(type);
|
|
84
|
|
85 g.display_binary(outfile, outfile_w, type);
|
|
86
|
|
87 }
|