This repository has been archived by the owner on May 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Local.cpp
103 lines (68 loc) · 2.68 KB
/
Local.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// Created by tdh5188 on 3/18/18.
//
#include <complex>
#include <cstdlib>
#include <cmath>
#include <valarray>
#include <cstring>
#include "Local.h"
std::random_device rng::device;
std::mt19937_64 rng::generator(rng::device());
//std::mt19937_64 rng::generator(0);
bool rng::isSeeded = false;
void rng::seedGenerator(unsigned long seed) {
generator.seed(seed);
isSeeded = true;
}
double rng::getRealUniformDist(double lower, double upper) {
std::uniform_real_distribution<double> distribution(lower, upper);
return distribution(generator);
}
double rng::getRealNormalDist(double lower, double upper) {
std::normal_distribution<double> distribution(lower, upper);
return distribution(generator);
}
/*std::mt19937_64 mRandom::generator;
bool mRandom::isSeeded = false;
void mRandom::seedGenerator(unsigned long seed) {
generator.seed(seed);
isSeeded = true;
}
double mRandom::getRealUniformDist(double lower, double upper) {
std::uniform_real_distribution<double> distribution(lower, upper);
return distribution(generator);
}
double mRandom::getRealNormalDist(double lower, double upper) {
std::normal_distribution<double> distribution(lower, upper);
return distribution(generator);
}*/
std::function<double(const Individual&)> mFitnessFunctions::makeAbsoluteValue(const Polynomial& polynomial) {
return [&polynomial](const Individual& individual)->double {
return std::abs(polynomial(individual.getChromosome()));
};
}
double mFitnessFunctions::applyAbsoluteValue(const Individual& individual) {
return std::abs(individual.getChromosome());
}
void mInformationRetrieval::getInformation(int argc, char **argv, unsigned long &pop_s, double &acpt_e,
double &mut_rate, double &mut_rad, double &start_rad) {
for (int j = 0; j < argc; j++) {
if (strcmp("-p", argv[j]) == 0 || strcmp("--population-size", argv[j]) == 0) {
pop_s = strtoul(argv[++j], nullptr, 0);
}
if (strcmp("-ae", argv[j]) == 0 || strcmp("--accepted-error", argv[j]) == 0) {
acpt_e = strtod(argv[++j], nullptr);
}
if (strcmp("-mr", argv[j]) == 0 || strcmp("--mutation-rate", argv[j]) == 0) {
mut_rate = strtod(argv[++j], nullptr);
}
if (strcmp("-ms", argv[j]) == 0 || strcmp("--mutation-radius", argv[j]) == 0) {
mut_rad = strtod(argv[++j], nullptr);
}
if (strcmp("-ss", argv[j]) == 0 || strcmp("--starting-radius", argv[j]) == 0) {
start_rad = strtod(argv[++j], nullptr);
}
}
}
//NetworkSizeException::NetworkSizeException(const std::string &__arg) : runtime_error(__arg) {}