-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedgelist_v3_DD.cpp
More file actions
114 lines (108 loc) · 1.82 KB
/
edgelist_v3_DD.cpp
File metadata and controls
114 lines (108 loc) · 1.82 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
//Edgelist
#include<iostream>
#include <fstream>
#include <math.h>
#include<stdlib.h>
#include<string>
#include <sstream>
/*This program reads a four column file name from the command line, reads the embedded vectors and generates the edge list*/
using namespace std;
int el[10000][10000];
int main(int argc, char* argv[])
{
ifstream fin;
ofstream fout,fout2;
int N;
int T;
static int ds[20000];
static float dd[20000];
static float x1[20000],x2[20000],x3[20000],x4[20000];
float eps,d;
string fn,fnp,fnpp;
if (argc<4)
{
cout<<"Usage ./el.out <Fname> <#points> <epsilon>"<<endl;
return(0);
}
else
{
fn=argv[1];
N=stof(argv[2]);
eps=stof(argv[3]);
cout<<"N is"<<N;
}
fin.open(fn);
//reading from file
for(int i=0;i<N;i++)
{
fin>>x1[i]>>x2[i]>>x3[i]>>x4[i]; //stof?
}
//reduces 1 from degree sequence
for (int i=0;i<N;i++)
{
ds[i]=-1;
}
cout<<"Epsilon is"<<eps;
fnpp="el_";
fnp=fnpp+=fn;
cout<<"\n Output file is"<<fnp<<endl;
//fout2.open(fnp);
for (int i=0;i<N;i++)
{
for (int j=i;j<N;j++)
{
d=pow(pow(x1[j]-x1[i],2)+pow(x2[j]-x2[i],2)+pow(x3[j]-x3[i],2)+pow(x4[j]-x4[i],2),.5);
if(d<eps)
{
//cout<<i<<'\t'<<j<<endl;
if(i!=j)
{
el[i][j]=1;
//fout2<<i<<'\t'<<j<<'\n';
ds[i]=ds[i]+1;
}
}
else
{
//cout<<i<<"\t\t"<<j<<endl;
el[i][j]=0;
}
}
}
fout2.close();
//writes edgelist to file
/*for(int i=0;i<N;i++) COmmented out on 10 Aug 2018 SVG
for(int j=i;j<N;j++)
{
if(el[i][j]==1)
fout2<<i<<'\t'<<j<<'\n';
}
fout2.close();
fout.close();*/
//Makes degree distribution from sequence
for(int i=1;i<N;i++)
for(int j=i;j<N;j++)
{
if(ds[j]==i)
{
T++;
dd[i]++;
}
}
cout<<"T is"<<T<<"N is"<<N;
//Divides by total degree
for (int i=1;i<N;i++)
{
dd[i]=dd[i]/T;
}
fnpp="dd_";
fnp=fnpp+=fn;
fout.open(fnp);
//writes degree distribution to file
for(int i=0;i<N;i++)
{
fout<<i<<'\t'<<dd[i]<<'\n';
}
fin.close();
return(0);
}