-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
163 lines (129 loc) · 4.51 KB
/
main.cpp
File metadata and controls
163 lines (129 loc) · 4.51 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
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include "include_me/S1_realization.h"
#include <sstream>
#include <random>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
// Custom library for specific Gaussian hypergeometric functions.
#include "include_else/hyp2f1.hpp"
using namespace std;
#include <cmath>
//Struct to hold command line parameters
struct Params {
int N = -1;
std::string parameter_file;
std::string correlation_file;
};
// Function to parse command line arguments
// Supports both flag-based and positional arguments
bool parse_args(int argc, char* argv[], Params ¶ms) {
// Flag-based parsing
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg == "-N" && i + 1 < argc) {
params.N = std::stoi(argv[++i]);
} else if (arg == "-pf" && i + 1 < argc) {
params.parameter_file = argv[++i];
} else if (arg == "-cf" && i + 1 < argc) {
params.correlation_file = argv[++i];
}
}
// Positional fallback if needed
if ((params.N == -1 || params.parameter_file.empty() || params.correlation_file.empty()) and argc == 4) {
params.N = std::stoi(argv[1]);
params.parameter_file = argv[2];
params.correlation_file = argv[3];
}
// Final validation
if (params.N == -1 || params.parameter_file.empty() || params.correlation_file.empty()) {
return false;
}
return true;
}
// Function to load parameters from a file
// The file should contain lines with: gamma beta kavg seed
void load_parameters(string filename, vector<double>& gammas, vector<double>& betas, vector<double>& kavgs, vector<int>& seeds)
{
ifstream infile(filename);
if (!infile.is_open()) {
cerr << "Error opening file: " << filename << endl;
return;
}
string line;
while (getline(infile, line)) {
stringstream ss(line);
double gamma, beta, kavg;
int seed;
ss >> gamma >> beta >> kavg >> seed;
gammas.push_back(gamma);
betas.push_back(beta);
kavgs.push_back(kavg);
seeds.push_back(seed);
}
infile.close();
}
// Function to load correlations from a file
// The file should contain lines with: nu g
void load_correlations(string filename, vector<double>& nus, vector<double>& gs)
{
ifstream infile(filename);
if (!infile.is_open()) {
cerr << "Error opening file: " << filename << endl;
return;
}
string line;
while (getline(infile, line)) {
stringstream ss(line);
double nu, g;
ss >> nu >> g;
nus.push_back(nu);
gs.push_back(g);
}
infile.close();
}
int main(int argc, char* argv[])
{
// Parse command line arguments
Params params;
if (!parse_args(argc, argv, params)) {
std::cerr << "Usage:\n"
<< " ./GENNET -N 1000 -pf param.txt -cf corr.txt\n"
<< " or\n"
<< " ./GENNET 1000 param.txt corr.txt\n";
return 1;
}
// Load the parameters and correlations
std::vector<double> gammas;
std::vector<double> betas;
std::vector<double> kavgs;
std::vector<double> nus;
std::vector<double> gs;
std::vector<int> seeds;
load_parameters(params.parameter_file, gammas, betas, kavgs, seeds);
load_correlations(params.correlation_file, nus, gs);
// Initialize multiplex
std::vector<S1_realization> multiplex;
// Generate the first layer
multiplex.push_back(S1_realization(gammas.at(0), betas.at(0), kavgs.at(0), params.N, seeds.at(0)));
// Generate the subsequent layers
for (int i = 1; i < gammas.size(); ++i) {
multiplex.push_back(S1_realization(multiplex.at(i-1), gammas.at(i), betas.at(i), kavgs.at(i), nus.at(i-1), gs.at(i-1), seeds.at(i)));
}
// Output the edge files and coordinates for each layer
std::stringstream ss;
std::ofstream coordfile;
for (int i = 0; i < multiplex.size(); ++i) {
ss << "layer" << i << ".coords";
coordfile.open(ss.str());
ss.str("");
for (int j = 0; j < params.N; ++j) {
coordfile << multiplex.at(i).thetas.at(j) << " " << multiplex.at(i).kappas.at(j) << endl;
}
coordfile.close();
multiplex.at(i).output_edgefile("layer" + std::to_string(i) + ".edge");
}
}