-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_convert.cpp
100 lines (89 loc) · 3.01 KB
/
main_convert.cpp
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
// File: main_convert.cpp
// -- conversion of a graph from ascii to binary, sample main file
//-----------------------------------------------------------------------------
// Community detection
// Based on the article "Fast unfolding of community hierarchies in large networks"
// Copyright (C) 2008 V. Blondel, J.-L. Guillaume, R. Lambiotte, E. Lefebvre
//
// This file is part of Louvain algorithm.
//
// Louvain algorithm 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 3 of the License, or
// (at your option) any later version.
//
// Louvain algorithm 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 Louvain algorithm. If not, see <http://www.gnu.org/licenses/>.
//-----------------------------------------------------------------------------
// Author : E. Lefebvre, adapted by J.-L. Guillaume
// Email : [email protected]
// Location : Paris, France
// Time : February 2008
//-----------------------------------------------------------------------------
// see readme.txt for more details
#include "graph.h"
using namespace std;
char *infile = NULL;
char *outfile = NULL;
char *outfile_w = NULL;
int type = UNWEIGHTED;
bool do_renumber = false;
void
usage(char *prog_name, const char *more) {
cerr << more;
cerr << "usage: " << prog_name << " -i input_file -o outfile [-r] [-w outfile_weight]" << endl << endl;
cerr << "read the graph and convert it to binary format." << endl;
cerr << "-r\tnodes are renumbered from 0 to nb_nodes-1 (the order is kept)." << endl;
cerr << "-w filename\tread the graph as a weighted one and writes the weights in a separate file." << endl;
cerr << "-h\tshow this usage message." << endl;
exit(0);
}
void
parse_args(int argc, char **argv) {
for (int i = 1; i < argc; i++) {
if(argv[i][0] == '-') {
switch(argv[i][1]) {
case 'i':
if (i==argc-1)
usage(argv[0], "Infile missing\n");
infile = argv[i+1];
i++;
break;
case 'o':
if (i==argc-1)
usage(argv[0], "Outfile missing\n");
outfile = argv[i+1];
i++;
break;
case 'w' :
type = WEIGHTED;
outfile_w = argv[i+1];
i++;
break;
case 'r' :
do_renumber=true;
break;
default:
usage(argv[0], "Unknown option\n");
}
} else {
usage(argv[0], "More than one filename\n");
}
}
if (infile==NULL || outfile==NULL)
usage(argv[0], "In or outfile missing\n");
}
int
main(int argc, char **argv) {
parse_args(argc, argv);
Graph g(infile, type);
g.clean(type);
if (do_renumber)
g.renumber(type);
g.display_binary(outfile, outfile_w, type);
}