forked from Ritu-Kundu/Superbubbles
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsupbub.cpp
89 lines (73 loc) · 2.57 KB
/
supbub.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
/**
Superbubbles
Copyright (C) 2016 Ritu Kundu, Fatima Vayani, Manal Mohamed, Solon P. Pissis
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
**/
/** Module containing main() method.
*/
#include <fstream>
#include <cstdlib>
#include "globalDefs.hpp"
#include "Graph.hpp"
#include "DetectSuperBubble.hpp"
#include "helperDefs.hpp"
using namespace supbub;
int main(int argc, char **argv){
/* Decode arguments */
struct InputFlags flags;
if(decodeFlags (argc, argv, &flags ) == 0){
usage();
return (1);
}
/* Read the input file in memory */
std::ifstream infile(flags.input_filename);
if(!infile.is_open()){
fprintf(stderr, "Cannot open input file \n" );
return 1;
}
// First line of the file contains number odf vertices
int64_t numVertices;
infile >> numVertices;
Graph graph(numVertices);
// File contains edges such that
// - new line as separator between edges
// - space/tab a separator between vertices of an edge
int64_t u, v;
while (infile >> u >> v) {
// add egde in the graph
graph.addEdge(u, v);
}
/* List for results */
DetectSuperBubble::SUPERBUBBLE_LIST superBubblesList{};
/* Find superbubbles */
double start = gettime();
DetectSuperBubble dsb;
dsb.find(graph, superBubblesList);
double end = gettime();
/* Write output */
std::ofstream outfile(flags.output_filename);
if(!outfile.is_open()){
fprintf(stderr, "Cannot open output file \n" );
return 1;
}
outfile << "Vertices: " << numVertices << "\n";
outfile << "Edges: "<< graph.numEdges() << "\n";
outfile << "Elapsed time for processing: " << (end - start)<< " secs.\n";
outfile << "Number of superbubbles found: " << superBubblesList.size()<< ".\n";
DetectSuperBubble::SUPERBUBBLE_LIST::iterator i;
for (i = superBubblesList.begin(); i != superBubblesList.end(); ++i) {
outfile << "<"<< (*i).entrance << "," << (*i).exit << ">\n";
}
// clean up
delete[] flags.input_filename;
delete[] flags.output_filename;
}