-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMbuilder.cpp
More file actions
85 lines (78 loc) · 1.79 KB
/
CMbuilder.cpp
File metadata and controls
85 lines (78 loc) · 1.79 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
#include <iostream>
#include <fstream>
#include <string>
#include <bits/stdc++.h>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(void)
{
srand(time(NULL));
ifstream degrees;
degrees.open("C:\\Users\\Usuario\\Desktop\\MasterUB\\Docencia\\ComplexNetworks\\network\\degreesreserva.txt");
string name; //im not saving the names of the nodes, this is a variable that will be overwritten and not used
int deg[4000]; //>N
int i, N, E;
i=0;
E=0;
while(!degrees.eof())
{
degrees >> name >> deg[i];
E=E+deg[i];
i++;
}
N=i;
degrees.close();
int stub[E]; //stub list
int reserva[E];
int j, degt;
i=0;
degt=deg[i];
j=0;
while(j<E)
{
if(j>=degt)
{
if(i>=N){goto SAL;}
i++;
degt=degt+deg[i];
}
stub[j]=i;
reserva[j]=stub[j];
j++;
}
SAL:
int k;
int repeticiones, Ereserva;
Ereserva=E;
repeticiones=1;
int a, nodea, b, nodeb;
ofstream edgelist;
for(k=0;k<repeticiones;k++)
{
E=Ereserva;
for(j=0;j<E;j++)
{
stub[j]=reserva[j];
}
edgelist.open("C:\\Users\\Usuario\\Desktop\\MasterUB\\Docencia\\ComplexNetworks\\network\\CMedgelist"+to_string(k)+".txt");
while(E>0)
{
//choose a node
a=rand()*E/RAND_MAX;
//remove it from the stub list
nodea=stub[a];
stub[a]=stub[E-1];
E=E-1;
//choose another
b=rand()*E/RAND_MAX;
nodeb=stub[b];
stub[b]=stub[E-1];
E=E-1;
//link them
edgelist << nodea << " " << nodeb << endl;
}
edgelist.close();
}
return 0;
}