Commit 00638372 authored by Konstantinos Chatzilygeroudis's avatar Konstantinos Chatzilygeroudis
Browse files

Switched to Stroustrup break braces version

parent 086bd2a4
...@@ -5,43 +5,41 @@ ...@@ -5,43 +5,41 @@
using namespace limbo; using namespace limbo;
struct Params struct Params {
{ struct boptimizer {
struct boptimizer
{
BO_PARAM(double, noise, 0.01); BO_PARAM(double, noise, 0.01);
BO_PARAM(int, dump_period, 1); BO_PARAM(int, dump_period, 1);
}; };
struct init
{ struct init {
BO_PARAM(int, nb_samples, 10); BO_PARAM(int, nb_samples, 10);
// calandra: number of dimensions * 5 // calandra: number of dimensions * 5
// knowles : 11 * dim - 1 // knowles : 11 * dim - 1
}; };
struct parego : public defaults::parego
{ struct parego : public defaults::parego {
}; };
struct maxiterations
{ struct maxiterations {
BO_PARAM(int, n_iterations, 30); BO_PARAM(int, n_iterations, 30);
}; };
struct ucb : public defaults::ucb
{ struct ucb : public defaults::ucb {
}; };
struct gp_ucb : public defaults::gp_ucb
{ struct gp_ucb : public defaults::gp_ucb {
}; };
struct cmaes : public defaults::cmaes
{ struct cmaes : public defaults::cmaes {
}; };
struct gp_auto : public defaults::gp_auto
{ struct gp_auto : public defaults::gp_auto {
}; };
struct meanconstant : public defaults::meanconstant
{ struct meanconstant : public defaults::meanconstant {
}; };
struct ehvi
{ struct ehvi {
BO_PARAM(double, x_ref, -11); BO_PARAM(double, x_ref, -11);
BO_PARAM(double, y_ref, -11); BO_PARAM(double, y_ref, -11);
}; };
...@@ -55,8 +53,7 @@ struct Params ...@@ -55,8 +53,7 @@ struct Params
#define ZDT_DIM 30 #define ZDT_DIM 30
#endif #endif
struct zdt1 struct zdt1 {
{
static constexpr size_t dim = ZDT_DIM; static constexpr size_t dim = ZDT_DIM;
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{ {
...@@ -73,8 +70,7 @@ struct zdt1 ...@@ -73,8 +70,7 @@ struct zdt1
} }
}; };
struct zdt2 struct zdt2 {
{
static constexpr size_t dim = ZDT_DIM; static constexpr size_t dim = ZDT_DIM;
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{ {
...@@ -91,8 +87,7 @@ struct zdt2 ...@@ -91,8 +87,7 @@ struct zdt2
} }
}; };
struct zdt3 struct zdt3 {
{
static constexpr size_t dim = ZDT_DIM; static constexpr size_t dim = ZDT_DIM;
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{ {
...@@ -109,8 +104,7 @@ struct zdt3 ...@@ -109,8 +104,7 @@ struct zdt3
} }
}; };
struct mop2 struct mop2 {
{
static constexpr size_t dim = 2; static constexpr size_t dim = 2;
Eigen::VectorXd operator()(const Eigen::VectorXd& x) const Eigen::VectorXd operator()(const Eigen::VectorXd& x) const
{ {
...@@ -129,13 +123,12 @@ struct mop2 ...@@ -129,13 +123,12 @@ struct mop2
} }
}; };
namespace limbo namespace limbo {
{ namespace stat {
namespace stat
{
template <typename F> template <typename F>
struct ParetoBenchmark struct ParetoBenchmark {
{
template <typename BO> template <typename BO>
void operator()(BO& opt) void operator()(BO& opt)
{ {
......
...@@ -28,8 +28,7 @@ void boundary_transformation_init(boundary_transformation_t* t, ...@@ -28,8 +28,7 @@ void boundary_transformation_init(boundary_transformation_t* t,
t->lower_bounds = default_lower; t->lower_bounds = default_lower;
if (upper_bounds == NULL && len_of_bounds <= 1) if (upper_bounds == NULL && len_of_bounds <= 1)
t->upper_bounds = default_upper; t->upper_bounds = default_upper;
if (len_of_bounds == 0) if (len_of_bounds == 0) {
{
t->lower_bounds = default_lower; t->lower_bounds = default_lower;
t->upper_bounds = default_upper; t->upper_bounds = default_upper;
t->len_of_bounds = 1; t->len_of_bounds = 1;
...@@ -47,8 +46,7 @@ void boundary_transformation_init(boundary_transformation_t* t, ...@@ -47,8 +46,7 @@ void boundary_transformation_init(boundary_transformation_t* t,
lb = t->lower_bounds; lb = t->lower_bounds;
ub = t->upper_bounds; ub = t->upper_bounds;
for (i = 0; i < t->len_of_bounds; ++i) for (i = 0; i < t->len_of_bounds; ++i) {
{
if (lb[i] == ub[i]) if (lb[i] == ub[i])
_FatalError("in _init: lower and upper bounds must be different in all " _FatalError("in _init: lower and upper bounds must be different in all "
"variables"); "variables");
...@@ -71,8 +69,7 @@ void boundary_transformation(boundary_transformation_t* t, double const* x, ...@@ -71,8 +69,7 @@ void boundary_transformation(boundary_transformation_t* t, double const* x,
double lb, ub, al, au; double lb, ub, al, au;
unsigned long i; unsigned long i;
boundary_transformation_shift_into_feasible_preimage(t, x, y, len); boundary_transformation_shift_into_feasible_preimage(t, x, y, len);
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i) {
{
lb = t->lower_bounds[_index(t, i)]; lb = t->lower_bounds[_index(t, i)];
ub = t->upper_bounds[_index(t, i)]; ub = t->upper_bounds[_index(t, i)];
al = t->al[_index(t, i)]; al = t->al[_index(t, i)];
...@@ -92,8 +89,7 @@ void boundary_transformation_discrete(boundary_transformation_t* t, ...@@ -92,8 +89,7 @@ void boundary_transformation_discrete(boundary_transformation_t* t,
unsigned long i; unsigned long i;
// boundary_transformation_shift_into_feasible_preimage(t, x, y, len); // boundary_transformation_shift_into_feasible_preimage(t, x, y, len);
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i) {
{
lb = t->lower_bounds[_index(t, i)]; lb = t->lower_bounds[_index(t, i)];
ub = t->upper_bounds[_index(t, i)]; ub = t->upper_bounds[_index(t, i)];
al = t->al[_index(t, i)]; al = t->al[_index(t, i)];
...@@ -114,8 +110,7 @@ void boundary_transformation_shift_into_feasible_preimage( ...@@ -114,8 +110,7 @@ void boundary_transformation_shift_into_feasible_preimage(
double lb, ub, al, au, r, xlow, xup; double lb, ub, al, au, r, xlow, xup;
unsigned long i; unsigned long i;
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i) {
{
lb = t->lower_bounds[_index(t, i)]; lb = t->lower_bounds[_index(t, i)];
ub = t->upper_bounds[_index(t, i)]; ub = t->upper_bounds[_index(t, i)];
al = t->al[_index(t, i)]; al = t->al[_index(t, i)];
...@@ -126,12 +121,10 @@ void boundary_transformation_shift_into_feasible_preimage( ...@@ -126,12 +121,10 @@ void boundary_transformation_shift_into_feasible_preimage(
y[i] = x[i]; y[i] = x[i];
if (y[i] < xlow) if (y[i] < xlow) { /* shift up */
{ /* shift up */
y[i] += r * (1 + (int)((xlow - y[i]) / r)); y[i] += r * (1 + (int)((xlow - y[i]) / r));
} }
if (y[i] > xup) if (y[i] > xup) { /* shift down */
{ /* shift down */
y[i] -= r * (1 + (int)((y[i] - xup) / r)); y[i] -= r * (1 + (int)((y[i] - xup) / r));
/* printf(" \n%f\n", fmod(y[i] - ub - au, r)); */ /* printf(" \n%f\n", fmod(y[i] - ub - au, r)); */
} }
...@@ -140,8 +133,7 @@ void boundary_transformation_shift_into_feasible_preimage( ...@@ -140,8 +133,7 @@ void boundary_transformation_shift_into_feasible_preimage(
if (y[i] > ub + au) if (y[i] > ub + au)
y[i] -= 2 * (y[i] - ub - au); y[i] -= 2 * (y[i] - ub - au);
if ((y[i] < lb - al - 1e-15) || (y[i] > ub + au + 1e-15)) if ((y[i] < lb - al - 1e-15) || (y[i] > ub + au + 1e-15)) {
{
printf("BUG in boundary_transformation_shift_into_feasible_preimage: " printf("BUG in boundary_transformation_shift_into_feasible_preimage: "
"lb=%f, ub=%f, al=%f au=%f, y=%f\n", "lb=%f, ub=%f, al=%f au=%f, y=%f\n",
lb, ub, al, au, y[i]); lb, ub, al, au, y[i]);
...@@ -156,8 +148,7 @@ void boundary_transformation_inverse(boundary_transformation_t* t, ...@@ -156,8 +148,7 @@ void boundary_transformation_inverse(boundary_transformation_t* t,
double lb, ub, al, au; double lb, ub, al, au;
unsigned long i; unsigned long i;
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i) {
{
lb = t->lower_bounds[_index(t, i)]; lb = t->lower_bounds[_index(t, i)];
ub = t->upper_bounds[_index(t, i)]; ub = t->upper_bounds[_index(t, i)];
al = t->al[_index(t, i)]; al = t->al[_index(t, i)];
...@@ -168,8 +159,7 @@ void boundary_transformation_inverse(boundary_transformation_t* t, ...@@ -168,8 +159,7 @@ void boundary_transformation_inverse(boundary_transformation_t* t,
else if (y[i] > ub - au) else if (y[i] > ub - au)
y[i] = (ub + au) - 2 * sqrt(au * (ub - y[i])); y[i] = (ub + au) - 2 * sqrt(au * (ub - y[i]));
} }
if (11 < 3 || do_assertions) if (11 < 3 || do_assertions) {
{
double* z = calloc(len, sizeof(double)); double* z = calloc(len, sizeof(double));
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i)
z[i] = y[i]; z[i] = y[i];
......
...@@ -26,7 +26,7 @@ extern "C" { ...@@ -26,7 +26,7 @@ extern "C" {
*/ */
typedef struct typedef struct
{ {
double const* lower_bounds; /* array of size len_of_bounds */ double const* lower_bounds; /* array of size len_of_bounds */
double const* upper_bounds; /* array of size len_of_bounds */ double const* upper_bounds; /* array of size len_of_bounds */
unsigned long len_of_bounds; /* in case, last value is recycled */ unsigned long len_of_bounds; /* in case, last value is recycled */
......
This diff is collapsed.
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
#include <time.h> #include <time.h>
typedef struct typedef struct
/* random_t /* random_t
* sets up a pseudo random number generator instance * sets up a pseudo random number generator instance
*/ */
{ {
/* Variables for Uniform() */ /* Variables for Uniform() */
long int startseed; long int startseed;
long int aktseed; long int aktseed;
...@@ -34,10 +34,10 @@ typedef struct ...@@ -34,10 +34,10 @@ typedef struct
} random_t; } random_t;
typedef struct typedef struct
/* timings_t /* timings_t
* time measurement, used to time eigendecomposition * time measurement, used to time eigendecomposition
*/ */
{ {
/* for outside use */ /* for outside use */
double totaltime; /* zeroed by calling re-calling timings_start */ double totaltime; /* zeroed by calling re-calling timings_start */
double totaltotaltime; double totaltotaltime;
...@@ -57,11 +57,11 @@ typedef struct ...@@ -57,11 +57,11 @@ typedef struct
} timings_t; } timings_t;
typedef struct typedef struct
/* readpara_t /* readpara_t
* collects all parameters, in particular those that are read from * collects all parameters, in particular those that are read from
* a file before to start. This should split in future? * a file before to start. This should split in future?
*/ */
{ {
char* char*
filename; /* keep record of the file that was taken to read parameters */ filename; /* keep record of the file that was taken to read parameters */
...@@ -80,7 +80,7 @@ typedef struct ...@@ -80,7 +80,7 @@ typedef struct
double facmaxeval; double facmaxeval;
double stopMaxIter; double stopMaxIter;
struct struct
{ {
int flg; int flg;
double val; double val;
} stStopFitness; } stStopFitness;
...@@ -100,7 +100,7 @@ typedef struct ...@@ -100,7 +100,7 @@ typedef struct
double ccov; /* <- mucov, <- N */ double ccov; /* <- mucov, <- N */
double diagonalCov; /* number of initial iterations */ double diagonalCov; /* number of initial iterations */
struct struct
{ {
int flgalways; int flgalways;
double modulo; double modulo;
double maxtime; double maxtime;
...@@ -120,10 +120,10 @@ typedef struct ...@@ -120,10 +120,10 @@ typedef struct
} readpara_t; } readpara_t;
typedef struct typedef struct
/* cmaes_t /* cmaes_t
* CMA-ES "object" * CMA-ES "object"
*/ */
{ {
const char* version; const char* version;
/* char *signalsFilename; */ /* char *signalsFilename; */
readpara_t sp; readpara_t sp;
......
...@@ -25,31 +25,25 @@ double ehvi2d(deque<individual*> P, double r[], double mu[], double s[]) ...@@ -25,31 +25,25 @@ double ehvi2d(deque<individual*> P, double r[], double mu[], double s[])
int Sstart = k - 1, Shorizontal = 0; int Sstart = k - 1, Shorizontal = 0;
// See thesis for explanation of how the O(1) iteration complexity // See thesis for explanation of how the O(1) iteration complexity
// is reached. NOTE: i = y = f[1], j = x = f[0] // is reached. NOTE: i = y = f[1], j = x = f[0]
for (int i = 0; i <= k; i++) for (int i = 0; i <= k; i++) {
{
Sminus = 0; Sminus = 0;
Shorizontal = Sstart; Shorizontal = Sstart;
for (int j = k - i; j <= k; j++) for (int j = k - i; j <= k; j++) {
{
double fmax[2]; // staircase width and height double fmax[2]; // staircase width and height
double cl1, cl2, cu1, cu2; // Boundaries of grid cells double cl1, cl2, cu1, cu2; // Boundaries of grid cells
if (j == k) if (j == k) {
{
fmax[1] = r[1]; fmax[1] = r[1];
cu1 = INFINITY; cu1 = INFINITY;
} }
else else {
{
fmax[1] = P[j]->f[1]; fmax[1] = P[j]->f[1];
cu1 = P[j]->f[0]; cu1 = P[j]->f[0];
} }
if (i == k) if (i == k) {
{
fmax[0] = r[0]; fmax[0] = r[0];
cu2 = INFINITY; cu2 = INFINITY;
} }
else else {
{
fmax[0] = P[k - i - 1]->f[0]; fmax[0] = P[k - i - 1]->f[0];
cu2 = P[k - i - 1]->f[1]; cu2 = P[k - i - 1]->f[1];
} }
...@@ -58,17 +52,14 @@ double ehvi2d(deque<individual*> P, double r[], double mu[], double s[]) ...@@ -58,17 +52,14 @@ double ehvi2d(deque<individual*> P, double r[], double mu[], double s[])
// Cell boundaries have been decided. Determine Sminus. // Cell boundaries have been decided. Determine Sminus.
#ifdef NAIVE_DOMPOINTS #ifdef NAIVE_DOMPOINTS
dompoints.clear(); dompoints.clear();
for (int m = 0; m < k; m++) for (int m = 0; m < k; m++) {
{ if (cl1 >= P[m]->f[0] && cl2 >= P[m]->f[1]) {
if (cl1 >= P[m]->f[0] && cl2 >= P[m]->f[1])
{
dompoints.push_back(P[m]); dompoints.push_back(P[m]);
} }
} }
Sminus = calculateS(dompoints, fmax); Sminus = calculateS(dompoints, fmax);
#else #else
if (Shorizontal > Sstart) if (Shorizontal > Sstart) {
{
Sminus += (P[Shorizontal]->f[0] - fmax[0]) * (P[Shorizontal]->f[1] - fmax[1]); Sminus += (P[Shorizontal]->f[0] - fmax[0]) * (P[Shorizontal]->f[1] - fmax[1]);
} }
Shorizontal++; Shorizontal++;
...@@ -97,22 +88,17 @@ double ehvi3d_2term(deque<individual*> P, double r[], double mu[], ...@@ -97,22 +88,17 @@ double ehvi3d_2term(deque<individual*> P, double r[], double mu[],
double Sminus; // Correction term for the integral. double Sminus; // Correction term for the integral.
deque<individual*> Py, Pz; // P sorted by y/z coordinate deque<individual*> Py, Pz; // P sorted by y/z coordinate
sort(P.begin(), P.end(), ycomparator); sort(P.begin(), P.end(), ycomparator);
for (int i = 0; i < P.size(); i++) for (int i = 0; i < P.size(); i++) {
{
Py.push_back(P[i]); Py.push_back(P[i]);
} }
sort(P.begin(), P.end(), zcomparator); sort(P.begin(), P.end(), zcomparator);
for (unsigned int i = 0; i < P.size(); i++) for (unsigned int i = 0; i < P.size(); i++) {
{
Pz.push_back(P[i]); Pz.push_back(P[i]);
} }
sort(P.begin(), P.end(), xcomparator); sort(P.begin(), P.end(), xcomparator);
for (int z = 0; z <= n; z++) for (int z = 0; z <= n; z++) {
{ for (int y = 0; y <= n; y++) {
for (int y = 0; y <= n; y++) for (int x = 0; x <= n; x++) {
{
for (int x = 0; x <= n; x++)
{
double fmax[3]; // upper corner of hypervolume improvement box double fmax[3]; // upper corner of hypervolume improvement box
double cl[3], cu[3]; // Boundaries of grid cells double cl[3], cu[3]; // Boundaries of grid cells
cl[0] = (x == 0 ? r[0] : P[x - 1]->f[0]); cl[0] = (x == 0 ? r[0] : P[x - 1]->f[0]);
...@@ -159,22 +145,17 @@ double ehvi3d_5term(deque<individual*> P, double r[], double mu[], ...@@ -159,22 +145,17 @@ double ehvi3d_5term(deque<individual*> P, double r[], double mu[],
double Sminus; // Correction term for the integral. double Sminus; // Correction term for the integral.
deque<individual*> Py, Pz; // P sorted by y/z coordinate deque<individual*> Py, Pz; // P sorted by y/z coordinate
sort(P.begin(), P.end(), ycomparator); sort(P.begin(), P.end(), ycomparator);
for (int i = 0; i < P.size(); i++) for (int i = 0; i < P.size(); i++) {
{
Py.push_back(P[i]); Py.push_back(P[i]);
} }
sort(P.begin(), P.end(), zcomparator); sort(P.begin(), P.end(), zcomparator);
for (unsigned int i = 0; i < P.size(); i++) for (unsigned int i = 0; i < P.size(); i++) {
{
Pz.push_back(P[i]); Pz.push_back(P[i]);
} }
sort(P.begin(), P.end(), xcomparator); sort(P.begin(), P.end(), xcomparator);
for (int z = 0; z <= n; z++) for (int z = 0; z <= n; z++) {
{ for (int y = 0; y <= n; y++) {
for (int y = 0; y <= n; y++) for (int x = 0; x <= n; x++) {
{
for (int x = 0; x <= n; x++)
{
double v[3]; // upper corner of hypervolume improvement box double v[3]; // upper corner of hypervolume improvement box
double cl[3], cu[3]; // Boundaries of grid cells double cl[3], cu[3]; // Boundaries of grid cells
cl[0] = (x == 0 ? r[0] : P[x - 1]->f[0]); cl[0] = (x == 0 ? r[0] : P[x - 1]->f[0]);
...@@ -188,25 +169,20 @@ double ehvi3d_5term(deque<individual*> P, double r[], double mu[], ...@@ -188,25 +169,20 @@ double ehvi3d_5term(deque<individual*> P, double r[], double mu[],
v[1] = r[1]; v[1] = r[1];
v[2] = r[2]; v[2] = r[2];
bool dominated = false; bool dominated = false;
for (unsigned int i = 0; i < P.size(); i++) for (unsigned int i = 0; i < P.size(); i++) {
{ if (P[i]->f[0] >= cu[0] && P[i]->f[1] >= cu[1] && P[i]->f[2] >= cu[2]) {
if (P[i]->f[0] >= cu[0] && P[i]->f[1] >= cu[1] && P[i]->f[2] >= cu[2])
{
dominated = true; dominated = true;
break; break;
} }
else if (P[i]->f[0] <= cu[0] && P[i]->f[1] >= cu[1] && P[i]->f[2] >= cu[2]) else if (P[i]->f[0] <= cu[0] && P[i]->f[1] >= cu[1] && P[i]->f[2] >= cu[2]) {
{
if (P[i]->f[0] > v[0]) if (P[i]->f[0] > v[0])
v[0] = P[i]->f[0]; v[0] = P[i]->f[0];
} }
else if (P[i]->f[0] >= cu[0] && P[i]->f[1] <= cu[1] && P[i]->f[2] >= cu[2]) else if (P[i]->f[0] >= cu[0] && P[i]->f[1] <= cu[1] && P[i]->f[2] >= cu[2]) {
{
if (P[i]->f[1] > v[1])