-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
79 lines (61 loc) · 2.28 KB
/
main.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
//
// Created by Xandru Mifsud on 09/09/2021.
// Please cite as: Mifsud X., "\[Lambda]--Core distance partitions", Linear Algebra Appl. (2021), https://doi.org/10.1016/j.laa.2020.12.012
//
#include <fstream>
#include <ctime>
#include "LaplacianLambdaCDP.h"
int main(int argc, char *argv[]){
ull N; // dimension of the input adjacency matrix
string adj_fpath; // file location of the CSV representation of the adjacency matrix
// option checking...
if(argc <= 2){
throw std::runtime_error("At least one of the adjacency matrix CSV or the dimension was not specified...exiting...");
}
else if(argc > 3){
throw std::runtime_error("Too many parameters specified...exiting...");
}
else{
N = stoll(argv[1], nullptr);
adj_fpath = argv[2];
}
std::ifstream adj_f(adj_fpath);
MatrixXd laplacian(N, N);
// Logging...
auto timenow = chrono::system_clock::to_time_t(chrono::system_clock::now());
cout << "Log " << ctime(&timenow) <<"\tLoading adjacency matrix..." << endl;
// From CSV file, load data as a MatrixXd instance
if(adj_f.is_open()){
std::string line;
int v, u; v = u = 0;
while(std::getline(adj_f, line)){
char* ptr = (char*) line.c_str();
ull len = line.length();
u = 0;
char* start = ptr;
for(ull i = 0; i < len; i++){
if(ptr[i] == ','){
laplacian(v, u++) = (-1)*strtod(start, nullptr);
start = ptr + i + 1;
}
}
laplacian(v, u) = (-1)*strtod(start, nullptr);
v++;
}
adj_f.close();
}
// Compute the degrees and set the diagonal entries...
for(ull v = 0; v < N; v++){
double d = 0;
for(ull u = 0; u < N; u++){
d += laplacian(v, u); // aggregate the degrees
}
laplacian(v, v) = (-1)*d; // set the diagonal entry to the sum of degrees across the v^th row
}
// Find the 'optimal' Lambda CDP for the Laplacian matrix...
getLaplacianLambdaCDP(&laplacian, laplacian.rows());
// Logging...
timenow = chrono::system_clock::to_time_t(chrono::system_clock::now());
cout << "Log " << ctime(&timenow) <<"\tCompleted." << endl;
return 0;
}