-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdivide.cpp
114 lines (86 loc) · 2.4 KB
/
divide.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include<bits/stdc++.h>
using namespace std;
void divide(string net){
string line, val;
int FIRST_LINE = 1, EDGES = 1;
ifstream f("datasets/" + net + "_full.net");
ofstream test(net + ("_test.net"), ios::app);
ofstream train(net + ("_train.net"), ios::app);
int edge_count = 0;
while (getline(f,line)) {
if(FIRST_LINE){
stringstream s(line);
int text[2],i=0;
while (getline (s, val, ' ')){
try{
text[i++] = stoi(val);
}
catch(exception e){
}
}
test << "*vertices ";
train << "*vertices ";
test << text[1] << endl;
train << text[1] << endl;
FIRST_LINE = 0;
continue;
}
if(line != "*edges" && EDGES == 1)
continue;
else if(EDGES == 1){
EDGES = 0;
continue;
}
edge_count++;
}
ifstream f1("datasets/" + net + "_full.net");
FIRST_LINE = 1; EDGES = 1;
int random, test_size=floor(edge_count*0.1);
test << "*edges" << endl;
train << "*edges" << endl;
while (getline(f1,line)) {
if(FIRST_LINE){
stringstream s(line);
int text[2],i=0;
while (getline (s, val, ' ')){
try{
text[i++] = stoi(val);
}
catch(exception e){}
}
FIRST_LINE = 0;
continue;
}
if(line != "*edges" && EDGES == 1)
continue;
else if(EDGES == 1){
EDGES = 0;
continue;
}
if(edge_count > test_size && test_size){
random = rand()%2;
}
else if(test_size){
random = 1;
}
else{
random = 0;
}
stringstream s(line);
int edge[3],i=0;
while (getline(s, val, ' ')){
edge[i++] = stoi(val);
}
if(random){
test << edge[0] << " " << edge[1] << " " << edge[2] << endl;
test_size--;
}else{
train << edge[0] << " " << edge[1] << " " << edge[2] << endl;
}
edge_count--;
}
}
void del(string net){
while(remove((net + "_test.net").c_str()) != 0);
while(remove((net + "_train.net").c_str()) != 0);
}