Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double funnel problems #204

Merged
merged 10 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
run: tests/test_ioh

build-test-python:
runs-on: macos-latest
runs-on: macos-12
strategy:
matrix:
python-version: ["3.6.x", "3.7.x", "3.8.x", "3.9.x", "3.10.x", "3.11.x"]
Expand Down
2 changes: 2 additions & 0 deletions include/ioh/problem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#include "problem/pbo.hpp"
#include "problem/wmodel.hpp"
#include "problem/submodular.hpp"
#include "problem/funnel.hpp"

#ifdef USING_MKLANDSCAPE
#include "problem/mklandscape/cliqueTreeC.hpp"
#endif

#include "problem/star_discrepancy/real.hpp"
#include "problem/star_discrepancy/integer.hpp"

52 changes: 28 additions & 24 deletions include/ioh/problem/bbob/many_affine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ namespace ioh::problem::bbob
}
}

class ManyAffine : public RealSingleObjective
class ManyAffine final : public RealSingleObjective
{
public:
static inline const std::array<double, 24> default_scales{11., 17.5, 12.3, 12.6, 11.5, 15.3, 12.1, 15.3,
15.2, 17.4, 13.4, 20.4, 12.9, 10.4, 12.3, 10.3,
9.8, 10.6, 10., 14.7, 10.7, 10.8, 9., 12.1};
static inline constexpr std::array<double, 24> default_scales{11., 17.5, 12.3, 12.6, 11.5, 15.3, 12.1, 15.3,
15.2, 17.4, 13.4, 20.4, 12.9, 10.4, 12.3, 10.3,
9.8, 10.6, 10., 14.7, 10.7, 10.8, 9., 12.1};

/**
* @brief Construct a new Many Affine object, requires weights and instances to be specified
Expand All @@ -64,11 +64,11 @@ namespace ioh::problem::bbob
const std::array<double, 24> &scale_factors) :
RealSingleObjective(MetaData(0, instances[0], "ManyAffine", n_variables),
Bounds<double>(n_variables, -5, 5)),
weights(weights), instances(instances), scale_factors(scale_factors), problems{}, function_values{}
weights_(weights), instances_(instances), scale_factors_(scale_factors), problems_{}, function_values_{}
{
const auto &problem_factory = ioh::problem::ProblemRegistry<ioh::problem::BBOB>::instance();
for (int fid = 1; fid < 25; fid++)
problems[fid - 1] = problem_factory.create(fid, instances[fid - 1], n_variables);
problems_[fid - 1] = problem_factory.create(fid, instances[fid - 1], n_variables);

this->optimum_.x = xopt;
this->optimum_.y = evaluate(xopt);
Expand Down Expand Up @@ -99,16 +99,16 @@ namespace ioh::problem::bbob
std::vector<double> x0 = x;
for (size_t i = 0; i < x.size(); i++)
{
x0[i] = x[i] + problems[fi]->optimum().x[i] - this->optimum_.x[i];
x0[i] = x[i] + problems_[fi]->optimum().x[i] - this->optimum_.x[i];
}
// evaluate and shift by yopt
double f0 = (*problems[fi])(x0)-problems[fi]->optimum().y;
double f0 = (*problems_[fi])(x0)-problems_[fi]->optimum().y;
// clamp to finite
f0 = std::min(std::max(f0, 1e-12), 1e20);
// apply scaling
f0 = (std::log10(f0) + 8) / scale_factors[fi];
f0 = (std::log10(f0) + 8) / scale_factors_[fi];
// apply weights
f0 = f0 * weights[fi];
f0 = f0 * weights_[fi];
result += f0;
}
// convert to base 10
Expand All @@ -117,27 +117,31 @@ namespace ioh::problem::bbob
}

private:
std::array<double, 24> weights;
std::array<int, 24> instances;
std::array<double, 24> scale_factors;
std::array<std::shared_ptr<ioh::problem::BBOB>, 24> problems;
std::array<double, 24> function_values;
std::array<double, 24> weights_;
std::array<int, 24> instances_;
std::array<double, 24> scale_factors_;
std::array<std::shared_ptr<ioh::problem::BBOB>, 24> problems_;
std::array<double, 24> function_values_;

public:
std::array<double, 24> get_weights(){
return weights;
std::array<double, 24> get_weights() const
{
return weights_;
}
std::array<int, 24> get_instances(){
return instances;
std::array<int, 24> get_instances() const
{
return instances_;
}
std::array<double, 24> get_scale_factors(){
return scale_factors;
std::array<double, 24> get_scale_factors() const
{
return scale_factors_;
}
std::array<std::shared_ptr<ioh::problem::BBOB>, 24> get_problems(){
return problems;
return problems_;
}
std::array<double, 24> get_function_values(){
return function_values;
std::array<double, 24> get_function_values() const
{
return function_values_;
}
};
} // namespace ioh::problem::bbob
5 changes: 2 additions & 3 deletions include/ioh/problem/cec/2013/shubert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ioh::problem

inline std::vector<Solution<double, SingleObjective>> get_optima(const int dimension)
{
const constexpr std::array<double, 6> coords = {-7.08350641, -0.8003211, 5.48286421,
constexpr std::array<double, 6> coords = {-7.08350641, -0.8003211, 5.48286421,
-7.70831374, -1.42512843, 4.85805688};


Expand Down Expand Up @@ -58,8 +58,7 @@ namespace ioh::problem
}
}
}
const size_t n_exp_optima = static_cast<size_t>(dimension * std::pow(3, dimension));
assert(n_exp_optima == result.size());
assert(static_cast<size_t>(dimension * std::pow(3, dimension)) == result.size());
return result;
}
} // namespace shubert
Expand Down
5 changes: 5 additions & 0 deletions include/ioh/problem/funnel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include "funnel/double_funnel.hpp"
#include "funnel/double_sphere.hpp"
#include "funnel/double_rastrigin.hpp"
51 changes: 51 additions & 0 deletions include/ioh/problem/funnel/double_funnel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#include "ioh/problem/single.hpp"


namespace ioh::problem::funnel
{
namespace functions
{
inline double shifted_sum(const std::vector<double> &x, const double u)
{
return std::accumulate(x.begin(), x.end(), 0.0,
[u](const double s, const double xi) { return s + pow(xi - u, 2.0); });
}

inline double double_sphere(const std::vector<double> &x, const double u1, const double u2, const double s,
const double d)
{
return std::min(shifted_sum(x, u1), (d * static_cast<double>(x.size())) + s * shifted_sum(x, u2));
}
} // namespace functions

class DoubleFunnel : public RealSingleObjective
{
double d_;
double s_;
double u1_;
double u2_;

public:
/*
* @brief Construct a new DoubleSphere object
* @param n_variables the dimension of the problem
* @param name the name of the problem
* @param d the depth of the suboptimal basin (higher values decrease the height)
* @param s the size of the suboptimal basin (smaller values increase the size of the suboptimal basin)
*/
DoubleFunnel(const int n_variables, const std::string &name, const double d = 0.0, const double s = 1.0) :
RealSingleObjective(MetaData(0, 1, name, n_variables), Bounds<double>(n_variables, -5, 5), {},
{std::vector<double>(n_variables, 2.5), 0.0}),
d_(d), s_(s), u1_(2.5), u2_(-std::sqrt((std::pow(2.5, 2.0) - d) / s))
{
}

[[nodiscard]] double d() const { return d_; }
[[nodiscard]] double s() const { return s_; }
[[nodiscard]] double u1() const { return u1_; }
[[nodiscard]] double u2() const { return u2_; }
};

} // namespace ioh::problem::funnel
31 changes: 31 additions & 0 deletions include/ioh/problem/funnel/double_rastrigin.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "double_funnel.hpp"

namespace ioh::problem::funnel
{
class DoubleRastrigin final : public DoubleFunnel
{
protected:
double evaluate(const std::vector<double> &x) override
{
double f_rastrigin = 0.0;
for (const double xi : x)
f_rastrigin += 1 - std::cos(2.0 * IOH_PI * (xi - u1()));

return functions::double_sphere(x, u1(), u2(), s(), d()) + (10 * f_rastrigin);
}

public:
/*
* @brief Construct a new DoubleSphere object
* @param n_variables the dimension of the problem
* @param d the depth of the suboptimal basin (higher values decrease the height)
* @param s the size of the suboptimal basin (smaller values increase the size of the suboptimal basin)
*/
DoubleRastrigin(const int n_variables, const double d = 0.0, const double s = 1.0) :
DoubleFunnel(n_variables, "DoubleRastrigin", d, s)
{
}
};
} // namespace ioh::problem::funnel
24 changes: 24 additions & 0 deletions include/ioh/problem/funnel/double_sphere.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "double_funnel.hpp"


namespace ioh::problem::funnel
{
class DoubleSphere final : public DoubleFunnel
{
protected:
double evaluate(const std::vector<double> &x) override
{
return functions::double_sphere(x, u1(), u2(), s(), d());
}
public:
/*
* @brief Construct a new DoubleSphere object
* @param n_variables the dimension of the problem
* @param d the depth of the suboptimal basin (higher values decrease the height)
* @param s the size of the suboptimal basin (smaller values increase the size of the suboptimal basin)
*/
DoubleSphere(const int n_variables, const double d = 0.0, const double s = 1.0) : DoubleFunnel(n_variables, "DoubleSphere", d, s) { }
};
} // namespace ioh::problem::funnel
Loading
Loading