-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphManager.hpp
92 lines (74 loc) · 2.99 KB
/
GraphManager.hpp
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
#include <fstream>
#include "progressBar.h"
#include <networkit/graph/GraphTools.hpp>
#include <networkit/graph/Graph.hpp>
#include <networkit/io/EdgeListReader.hpp>
#ifndef GRAPHMANAGER_HPP_
#define GRAPHMANAGER_HPP_
class GraphManager
{
public:
static void read_hist(std::string source, NetworKit::Graph **g, std::vector<std::pair<uint64_t, std::pair<uint32_t , uint32_t>> > *edge_structure)
{
std::ifstream ifs(source);
if (!ifs)
throw std::runtime_error("Error opening File ");
int vertices = -1, edges = -1, weighted = -1, directed = -1;
ifs >> vertices >> edges >> weighted >> directed;
assert((weighted == 0 || weighted == 1) && (directed == 0 || directed == 1) && (vertices >= 0 && edges >= 0));
ProgressStream reader(edges);
std::string t1 = weighted == 0 ? " unweighted" : " weighted";
std::string t2 = directed == 0 ? " undirected" : " directed";
reader.label() << "Reading" << t1 << t2 << " graph in " << source << " (HIST FORMAT) containing " << vertices << " vertices and " << edges << " edges ";
NetworKit::Graph *graph = new NetworKit::Graph(vertices, weighted, directed);
int time, v1, v2, weight;
while (true)
{
ifs >> time >> v1 >> v2 >> weight;
if (ifs.eof())
break;
++reader;
//assert(weighted == 1 || weight == 1 || weight == -1);
if (v1 == v2)
continue;
assert(graph->hasNode(v1) && graph->hasNode(v2));
if (graph->hasEdge(v1, v2))
// std::cout<<"SKIPPING ROW"<<std::endl;
;
else
{
graph->addEdge(v1, v2, weight);
edge_structure->emplace_back(time, std::make_pair(v1,v2));
#ifndef NDEBUG
if (!directed)
{
if (!graph->hasEdge(v1, v2) && !graph->hasEdge(v2, v1))
throw std::runtime_error("wrong edge insertion during construction");
}
else
{
if (!graph->hasEdge(v1, v2))
throw std::runtime_error("wrong edge insertion during construction");
}
#endif
}
}
ifs.close();
graph->indexEdges();
*g = graph;
}
static void read_nde(std::string source, NetworKit::Graph **g)
{
std::ifstream ifs(source);
if (!ifs)
throw std::runtime_error("Error opening File ");
NetworKit::Graph *graph = new NetworKit::Graph();
const char x = ' ';
NetworKit::EdgeListReader reader(x,0,"#",true,false);
*graph = reader.read(source);
*g = graph;
graph->indexEdges();
std::cout << "Read graph in " << source << " (EDGELIST FORMAT) containing " << graph->numberOfNodes() << " vertices and " << graph->numberOfEdges() << " edges\n";
}
};
#endif /* GRAPHMANAGER_HPP_ */