Skip to content

Commit

Permalink
Merge pull request #183 from IOHprofiler/dynamic-bin-val
Browse files Browse the repository at this point in the history
DynamicBinVal
  • Loading branch information
jacobdenobel authored May 14, 2024
2 parents 35b5f20 + c754594 commit 917d1e2
Show file tree
Hide file tree
Showing 35 changed files with 2,244 additions and 79 deletions.
25 changes: 10 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,13 @@ compile_commands.json
debug
release
ioh_data
run.py
py10/

gsemo.cpp

.BUILD_CPP
.BUILD_PYTHON
.conda.yaml
.conda_environment/
.pip.txt
.RUN_CPP
.RUN_PYTHON
.workstory.md

external/
run.py
py10/

gsemo.cpp

2022-SO-BO-main
.conda_environment
concepts
tests/python/nevergrad.benchmark.Experiment/
.deploy/conda_environment/
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ option(ENABLE_MKLANDSCAPE_PROBLEMS "Enbale to build mk-landscape problems" OFF)

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /bigobj")
endif()
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -std=c++17 -lstdc++fs")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconversion -Wall -Wextra -pedantic -std=c++17 -lstdc++fs")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 ")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
link_libraries(stdc++fs)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* Flexible interface for adding new suites and problems.
* Advanced logging module that takes care of registering the data in a seamless manner.
* Data format is compatible with [IOHanalyzer](https://github.com/IOHprofiler/IOHanalyzer).
* Dynamic BinVal functions ([paper](https://link.springer.com/article/10.1007/s42979-022-01203-z))
* Double funnel functions ([paper](https://link.springer.com/chapter/10.1007/978-3-540-87700-4_50))


**Available Problem Suites:**

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.15
0.3.16
11 changes: 6 additions & 5 deletions include/ioh/common/clutchlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ namespace fs = std::experimental::filesystem;
namespace fs = std::filesystem;
#endif

#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdlib>
#include <string>
#include <fstream>
#include <iostream>
#include <iterator>
#include <limits>
#include <regex>
#include <map>
#include <regex>
#include <sstream>
#include <string>

#if __has_include(<execinfo.h>) && __has_include(<stdlib.h>) && __has_include(<libgen.h>)
#include <execinfo.h> // execinfo
Expand Down
2 changes: 1 addition & 1 deletion include/ioh/common/container_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ namespace ioh
bool operator<(const Permutation &b) const { return value < b.value; }

//! sort a set of random permutations
static std::vector<Permutation> sorted(const int n, const int seed)
static std::vector<Permutation> sorted(const int n, const unsigned long seed)
{
const auto random_numbers = random::bbob2009::uniform(n, seed);
std::vector<Permutation> permutations(n);
Expand Down
18 changes: 9 additions & 9 deletions include/ioh/common/random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ namespace ioh::common::random
{

/**
* \brief Fills a rand_vec with n uniform random numbers, generated using in_seed
* \brief Fills a rand_vec with n uniform random numbers, generated using in_seed.
* \param n The size of rand_vec
* \param seed The random seed
* \param lb lower bound for the random numbers
* \param ub upper bound for the random numbers
*/
inline std::vector<double> uniform(const size_t &n, long seed, const double lb = 0, const double ub = 1)
inline std::vector<double> uniform(const size_t &n, unsigned long seed, const double lb = 0, const double ub = 1)
{
auto rand_vec = std::vector<double>(n);
long rand_seed[32] = {};
Expand Down Expand Up @@ -245,11 +245,11 @@ namespace ioh::common::random

namespace bbob2009
{
inline std::vector<double> uniform(const size_t n, const int initial_seed, const double lb = 0,
inline std::vector<double> uniform(const size_t n, const unsigned long initial_seed, const double lb = 0,
const double ub = 1)
{
auto generators = std::array<int, 32>();
auto seed = std::max(1, abs(initial_seed));
auto generators = std::array<unsigned long, 32>();
auto seed = std::max(initial_seed, {1});

// Initialize the seed and generator
for (auto i = 39; i >= 0; i--)
Expand All @@ -261,14 +261,14 @@ namespace ioh::common::random


auto x = std::vector<double>(n);
auto random_number = generators.front();
auto random_number = static_cast<double>(generators.front());

for (size_t i = 0; i < n; i++)
{
const auto index = static_cast<int>(floor(random_number / 67108865.0));

seed = lcg_rand(seed);
random_number = generators[index];
random_number = static_cast<double>(generators[index]);
generators[index] = seed;

x[i] = random_number / 2.147483647e9;
Expand All @@ -280,10 +280,10 @@ namespace ioh::common::random
return x;
}

inline std::vector<double> normal(const size_t n, const long seed, const double lb = 0, const double ub = 1)
inline std::vector<double> normal(const size_t n, const unsigned long seed, const double lb = 0, const double ub = 1)
{
assert(2 * n < 6000);
const auto uniform_random = uniform(2 * n, seed);
const auto uniform_random = uniform(2 * n, static_cast<int>(seed));

std::vector<double> x(n);

Expand Down
2 changes: 1 addition & 1 deletion include/ioh/logger/eaf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ namespace logger {

}
assert(nb_runs > 0);
return v / (nb_runs * (error_max-error_min) * (evals_max-evals_min));
return v / (static_cast<double>(nb_runs) * (error_max-error_min) * static_cast<double>(evals_max-evals_min));
}

/** Computes the absolute "hypervolume" of the whole empirical attainement function.
Expand Down
14 changes: 8 additions & 6 deletions include/ioh/logger/eah.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ namespace ioh
assert(0 < _size);
}

virtual ~Scale() = default; // Virtual destructor

/** Minimum value on the axis. */
R min() const { return _min; }

Expand Down Expand Up @@ -206,7 +208,7 @@ namespace ioh
{
assert(this->_min <= x);
assert(x <= this->max()); // FIXME do we want that?
if (x >= this->max())
if (x >= static_cast<double>(this->max()))
{
return this->size() - 1;
}
Expand Down Expand Up @@ -281,7 +283,7 @@ namespace ioh
{
assert(this->_min <= x);
assert(x <= this->max()); // FIXME do we want that?
if (x >= this->max())
if (x >= static_cast<double>(this->max()))
{
return this->size() - 1;
}
Expand Down Expand Up @@ -547,8 +549,8 @@ namespace ioh
}

// If this target is worst than the domain.
if (evaluations.value() < _range_evals.min() || _range_evals.max() < evaluations.value()
|| err < _range_error.min() || _range_error.max() < err)
if (evaluations.value() < static_cast<double>(_range_evals.min()) || static_cast<double>(_range_evals.max()) < evaluations.value()
|| err < static_cast<double>(_range_error.min()) || static_cast<double>(_range_error.max()) < err)
{
// Discard it.
// FIXME we should use a more generic debug log system
Expand Down Expand Up @@ -1103,10 +1105,10 @@ namespace ioh
assert(0 <= w_proba and w_proba <= 1);
// Within the loop because widths of buckets vary for log ranges.
const double w_error = (range_error.bounds(i).second - range_error.bounds(i).first) /
range_error.length();
static_cast<double>(range_error.length());
assert(0 <= w_error and w_error <= 1);
const double w_evals = (range_evals.bounds(j).second - range_evals.bounds(j).first) /
range_evals.length();
static_cast<double>(range_evals.length());
assert(0 <= w_evals and w_evals <= 1);
// TODO allow to multiply by a weight each axis?
res = op(res, w_proba * w_error * w_evals);
Expand Down
1 change: 1 addition & 0 deletions include/ioh/problem.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "problem/dynamic_bin_val.hpp"
#include "problem/transformation.hpp"
#include "problem/cec.hpp"
#include "problem/problem.hpp"
Expand Down
2 changes: 1 addition & 1 deletion include/ioh/problem/bbob/bbob_problem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace ioh::problem
struct TransformationState
{
//! The seed
long seed;
unsigned long seed;

//! A vector with exponents
std::vector<double> exponents{};
Expand Down
4 changes: 2 additions & 2 deletions include/ioh/problem/bbob/gallagher101.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace ioh::problem::bbob
double value;
std::vector<double> scales;

Peak(const double value, const int seed, const int n_variables, const double condition) :
Peak(const double value, const unsigned long seed, const int n_variables, const double condition) :
value(value), scales(n_variables)
{
auto permutations = common::Permutation::sorted(n_variables, seed);
Expand All @@ -24,7 +24,7 @@ namespace ioh::problem::bbob
static_cast<double>(permutations[i].index) / (static_cast<double>(n_variables) - 1.) - 0.5);
}

static std::vector<Peak> get_peaks(const int n, const int n_variables, const int seed,
static std::vector<Peak> get_peaks(const int n, const int n_variables, const unsigned long seed,
const double max_condition)
{
static const auto f0 = 1.1, f1 = 9.1, mc = 1000.;
Expand Down
11 changes: 7 additions & 4 deletions include/ioh/problem/bbob/many_affine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,25 @@ namespace ioh::problem::bbob
std::array<double, 24> function_values_;

public:
std::array<double, 24> get_weights() const
[[nodiscard]] std::array<double, 24> get_weights() const
{
return weights_;
}
std::array<int, 24> get_instances() const

[[nodiscard]] std::array<int, 24> get_instances() const
{
return instances_;
}
std::array<double, 24> get_scale_factors() const

[[nodiscard]] std::array<double, 24> get_scale_factors() const
{
return scale_factors_;
}
std::array<std::shared_ptr<ioh::problem::BBOB>, 24> get_problems(){
return problems_;
}
std::array<double, 24> get_function_values() const

[[nodiscard]] std::array<double, 24> get_function_values() const
{
return function_values_;
}
Expand Down
6 changes: 4 additions & 2 deletions include/ioh/problem/constraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace ioh::problem
violation_(0.), is_feasible_(true), enforced(enforced), weight(weight), exponent(exponent)
{
}

virtual ~Constraint() = default; // Virtual destructor

/**
* @brief apply the constraint, and return a (potentially) penalized value for y
Expand Down Expand Up @@ -330,13 +332,13 @@ namespace ioh::problem
}

//! Return resize version of BoxConstraint
BoxConstraint<T> resize(const int s) const
[[nodiscard]] BoxConstraint<T> resize(const int s) const
{
return BoxConstraint<T>(std::vector<T>(s, lb.at(0)), std::vector<T>(s, ub.at(0)));
}

//! String representation
std::string repr() const override { return fmt::format("<BoxConstraint lb: [{}] ub: [{}]>", lb, ub); }
[[nodiscard]] std::string repr() const override { return fmt::format("<BoxConstraint lb: [{}] ub: [{}]>", lb, ub); }


bool operator==(const BoxConstraint<T>& other) const {
Expand Down
6 changes: 6 additions & 0 deletions include/ioh/problem/dynamic_bin_val.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "dynamic_bin_val/dynamic_bin_val_pareto.hpp"
#include "dynamic_bin_val/dynamic_bin_val_powers_of_two.hpp"
#include "dynamic_bin_val/dynamic_bin_val_ranking.hpp"
#include "dynamic_bin_val/dynamic_bin_val_uniform.hpp"
80 changes: 80 additions & 0 deletions include/ioh/problem/dynamic_bin_val/dynamic_bin_val.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#pragma once

#include "ioh/problem/single.hpp"
#include "ioh/problem/transformation.hpp"

namespace ioh::problem
{
// NOTE: It's important to give `seed` the type uint64_t instead of long;
// otherwise not the same pseudo-random numbers will be generated from the seed between Ubuntu and Windows.
constexpr long max_long_value = 1782677537L;

namespace dynamic_bin_val
{
struct rng
{
std::mt19937 gen;
rng(const int seed) : gen(seed) {}
long operator()() { return (gen() & max_long_value); }
};


} // namespace dynamic_bin_val

class DynamicBinVal : public IntegerSingleObjective
{

protected:
double evaluate(const std::vector<int> &x) override { return std::accumulate(x.begin(), x.end(), 0.0); }

std::vector<int> transform_variables(std::vector<int> x) override
{
transformation::variables::random_flip(x, this->meta_data_.instance);
return x;
}

double transform_objectives(const double /* y */) override
{
double value = 0.0;
for (size_t i = 0; i < this->state_.current_internal.x.size(); ++i)
value += this->state_.current_internal.x[i] * this->weights[i];
return value;
}

virtual void update_weights() {}

public:
int time_step;
dynamic_bin_val::rng random_generator;
std::vector<double> weights;

DynamicBinVal(const int problem_id, const int instance, const int n_variables, const std::string &name) :
IntegerSingleObjective(MetaData(problem_id, instance, name, n_variables, common::OptimizationType::MAX),
Bounds<int>(n_variables, 0, 1)),
time_step(-1), random_generator(instance), weights(n_variables)
{
this->optimum_.x.assign(meta_data_.n_variables, 1);
transformation::variables::random_flip(this->optimum_.x, this->meta_data_.instance);
}

virtual int step()
{
this->time_step += 1;
update_weights();

const auto tmp_x = this->state_.current_internal.x;
this->state_.current_internal.x.assign(meta_data_.n_variables, 1);
this->optimum_.y = transform_objectives(0);
this->state_.current_internal.x = tmp_x;
return this->time_step;
}
};

template <typename ProblemType>
struct DynamicBinValProblem : DynamicBinVal,
AutomaticProblemRegistration<ProblemType, DynamicBinVal>,
AutomaticProblemRegistration<ProblemType, IntegerSingleObjective>
{
using DynamicBinVal::DynamicBinVal;
};
} // namespace ioh::problem
Loading

0 comments on commit 917d1e2

Please sign in to comment.