-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
169 lines (130 loc) · 4.96 KB
/
main.cpp
File metadata and controls
169 lines (130 loc) · 4.96 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <iostream>
#include <fstream>
#include <tuple>
#include "readfile.h"
#include "dfs.h"
#include "printdata.h"
#include "cyclic.h"
// Aumentare la dimensione dello stack con $ ulimit -s unlimited
using namespace std;
int randomNumber(int a){
int range = a + 1;
int r = rand() % range;
return r;
}
void savePair(int file){
int counter =0;
int dcounter = 0;
vector<tuple<int, int>> pairs;
cout << endl << "Test salvataggio iniziato" << endl;
const char *filepaths[3] = {"pairs/drb.txt", "pairs/chrY.txt", "pairs/chrX.txt"};
for (int i=400; i < sources.size(); i++){
int s = sources[i];
cout << i << "sorgente: " << s << endl;
counter++;
dcounter = 0;
for (auto d: destinations){
if (dcounter % 100 == 0){
cout << dcounter << endl;}
dcounter++;
walkIndex = 0;
recursiveCallsDFS = 0;
DFS(s, d);
if (walkIndex > MINWALKS){
ofstream myfile (filepaths[file], ios_base::app);
if (myfile.is_open()){
string line = to_string(s) + " " + to_string(d) + "\n";
myfile << line;
}
myfile.close();
}
}
}
}
vector<int> randomPair(int file){
int len, s, d;
int index;
const char *filepaths[3] = {"pairs/drb.txt", "pairs/chrY.txt", "pairs/chrX.txt"};
auto data = freopen(filepaths[file], "r", stdin); // Apertura file
if (data != NULL){
cin >> len;
index = randomNumber(len);
for (int i=0; i<index; i++){
cin >> s >> d;
}
}
return {s, d};
}
int main(){
int choice;
const char *filepaths[3] = {"data/drb.gfa", "data/chrY.gfa", "data/chrX.gfa"};
srand(time(NULL));
// Scelta del file da analizzare
cout << "Selezionare il file da analizzare:" << endl;
cout << "0: drb.gfa" << endl << "1: chrY.gfa" << endl << "2: chrX.gfa" << endl;
cout << ">> ";
cin >> choice;
string searchString;
cout << endl << "Inserire stringa da cercare:" << endl << ">> ";
cin >> searchString;
cout << endl;
// Lettura del file
readData(filepaths[choice]);
// Ricerca di sorgenti e destinazioni
cout << endl << "Analisi con grafo ciclico:" << endl << endl;
cout << "Numero nodi:\t" << nodeCounter << endl;
cout << "Numero archi:\t" << linkCounter << endl;
findSources();
cout << "N. sorgenti:\t" << sources.size() << endl;
findDestinations();
cout << "N. destinaz.:\t" << destinations.size() << endl;
// Ricerca dei backedge e rimozione
cout << endl << "Analisi ciclicità del grafo senza segni:" << endl << endl;
// DFS partendo dalla prima sorgente trovata precedentemente
DFS_cyclic(sources[1]);
cout << "Backedge rim.:\t" << backedgeCounter << endl;
cout << "N. ricorsioni:\t" << cyclicRecursiveCalls << " (" << MAXCALLS << ")" << endl;
cout << endl << "Analisi grafo con ciclcità parzialmente rimossa:" << endl << endl;
cout << "Numero archi:\t" << linkCounter << endl;
// Cercare nuovamente sorgenti e destinazioni dopo aver rimosso parte dei backedge
sources.clear();
destinations.clear();
findSources();
cout << "N. sorgenti:\t" << sources.size() << endl;
findDestinations();
cout << "N. destinaz.:\t" << destinations.size() << endl;
// Capire come scegliere le sorgenti e le destinazioni per trovare qualche cammino
/*bisogna verificare che la collisione avvenga all'interno di un cammino.*/
int source;
int destination;
vector<int> pair = randomPair(choice);
//
//savePair(choice);
//
cout << endl << "Cammino con almeno " << MINWALKS << " cammini:" << endl << endl;
// Calcolare prima le coppie di (s,d) che hanno un numero decente di cammini. Salvarle su un file
// e poi prenderle random
source = pair[0];
destination = pair[1];
cout << "Sorgente:\t" << source << endl;
cout << "Destinazione:\t" << destination << endl;
recursiveCallsDFS = 0;
walkIndex = 0;
DFS(source, destination);
cout << "Cam. trovati:\t" << walkIndex << " (" << MAXWALKS << ")" << endl;
cout << "N. ricorsioni:\t" << recursiveCallsDFS << " (" << MAXCALLS << ")" << endl;
// Ricerca della stringa con rolling hash
cout << endl << "Ricerca di una stringa con rolling hash:" << endl << endl;
cout << "Ricerca:\t" << searchString << endl;
cout << "Hash ricerca:\t" << stringHash(searchString) << endl;
// Ripristino delle condizioni iniziali per la DFS
walkIndex = 0;
recursiveCallsDFS = 0;
DFS_hashing(source, destination, searchString);
int realCollisions = countCollision();
cout << "Collisioni:\t" << realCollisions << " (" << collisionCounter << ")" << endl;
cout << "Nodi visitati:\t" << hashCounter << endl;
cout << "N. rolling:\t" << rollingCounter << endl;
// printSequences(MAXWALKS);
return 0;
}