-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathloaders.cpp
More file actions
114 lines (89 loc) · 2.04 KB
/
Copy pathloaders.cpp
File metadata and controls
114 lines (89 loc) · 2.04 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include"loaders.h"
#include<cstdio>
#include<fstream>
#include<sstream>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;
void snap_loader(Graph* graph, const char* file_name) {
int n,m;
int from, to;
char buffer[1000];
FILE *fp = fopen(file_name, "r");
if (fp == NULL)
{
printf("File %s not found\n",file_name);
exit(1);
}
fgets(buffer, sizeof buffer, fp);
fgets(buffer, sizeof buffer, fp);
fgets(buffer, sizeof buffer, fp);
sscanf(buffer, "# Nodes: %d Edges: %d",&n,&m);
//read edges
while (fgets(buffer, sizeof buffer, fp) != NULL)
{
if (buffer[0] != '#')
{
sscanf(buffer, "%d\t%d", &from,&to);
graph->add_neighbor(from,to);
}
}
//graph->print_graph_size();
fclose(fp);
}
void preprocessed_loader(Graph* graph, const char* file_name) {
int n,m;
int from, to;
char buffer[1000];
char pre_file_name[1000];
strcpy(pre_file_name, file_name);
strcat(pre_file_name, ".preprocessed");
printf("%s\n",pre_file_name);
FILE *fp = fopen(pre_file_name, "r");
fgets(buffer, sizeof buffer, fp);
sscanf(buffer, "%d %d\n",&n,&m);
//read edges
while (fgets(buffer, sizeof buffer, fp) != NULL)
{
sscanf(buffer, "%d %d", &from,&to);
graph->add_neighbor(from,to);
}
graph->print_graph_size();
fclose(fp);
}
void elt_loader(Graph* graph) {
int n,m;
int neighbor;
string line;
ifstream elt_file(ELT_FILE);
elt_file >> n;
elt_file >> m;
//read edges
getline(elt_file, line);
for (int i=0 ; i<n; i++)
{
getline(elt_file, line);
stringstream linestream(line);
while (linestream >> neighbor)
{
neighbor--;
graph->add_neighbor(i, neighbor);
}
}
graph->print_graph_size();
elt_file.close();
}
void twitter_loader(Graph* graph) {
int from, to;
char buffer[1000];
FILE *fp = fopen(TWITTER_FILE, "r");
//read edges
while (fgets(buffer, sizeof buffer, fp) != NULL)
{
sscanf(buffer, "%d\t%d", &from,&to);
graph->add_neighbor(from,to);
}
graph->print_graph_size();
fclose(fp);
}