-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstReturn_red.cpp
More file actions
87 lines (69 loc) · 1.44 KB
/
FirstReturn_red.cpp
File metadata and controls
87 lines (69 loc) · 1.44 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
#include<cstdlib>
#include<fstream>
#include<iostream>
#include<vector>
#include <ctime>
using namespace std;
//Objetivo leer la red
string str;
int a, b;
const int Nv = 100;
int matA [Nv][Nv]; //Matriz de Adjacencia
int RandomInteger(int val)
{
return rand()%(val);
}
int main()
{
srand(time(NULL));
ifstream file("./Data/Random Walk Network 1/Lines.dat");
vector<int> Degrees(Nv);
vector<vector<int>> Neighbors(Nv);
vector<int> Frequ_visited(Nv);
while(getline(file,str))
{
a = stoi(str.substr(0,str.find(" ")));
b = stoi(str.substr(str.find(" ")+2));
Neighbors[a].push_back(b);
Neighbors[b].push_back(a);
}
for(int i= 0; i<Nv;i++)
{
Degrees[i] = Neighbors[i].size();
Frequ_visited[i] = 0;
}
for(int i = 0; i< Nv; i++)
{
string name = "./Data/FRT/T_" + to_string(i) + ".dat";
ofstream FRT_data (name);
FRT_data<<"Nodo"<<" "<<"t"<<endl;
int pos_init = i;
int target = i;
cout<<i<<endl;
for(int r = 0; r<100000; r++)
{
int t = 0;
if(pos_init == target)
{
pos_init = Neighbors[pos_init][RandomInteger(Degrees[pos_init])];
t += 1;
while(pos_init != target)
{
pos_init = Neighbors[pos_init][RandomInteger(Degrees[pos_init])];
t+=1;
}
}
else
{
while(pos_init != target)
{
pos_init = Neighbors[pos_init][RandomInteger(Degrees[pos_init])];
t+=1;
}
}
FRT_data<<i<<" "<<t<<endl;;
}
FRT_data.close();
}
return 0;
}