common

Namespaces

Classes

CpuTimer

class CpuTimer

A simple timer class, logging elapsed CPU time to stdout.

Public Functions

inline explicit CpuTimer(std::string info_msg = "")

Constructs a timer, sets start time.

Parameters:

info_msg – The value for info_msg_

inline ~CpuTimer()

Destructs a timer, prints time elapsed to stdout.

Private Types

using Clock = std::chrono::high_resolution_clock

The start time of the timer.

Private Members

std::string info_msg_

A info message to be logged to stdout when the timer completes.

Clock::time_point start_time_

FOptimizationType

class FOptimizationType : public ioh::common::HasRepr

Wrapper class for optimization type, contains comparison operator.

Public Functions

inline FOptimizationType(const OptimizationType type = OptimizationType::MAX)

Construct a new FOptimizationType object.

Parameters:

type – The optimization type

FOptimizationType(const FOptimizationType&) = default

Copy constructor.

inline OptimizationType type() const

Accessor for type_.

inline double initial_value() const

Accesor for initial_value_.

inline virtual std::string repr() const override

String representation.

inline bool operator()(const double v1, const double v2) const

Comparison operator between two values v1 & v2.

> When OptimizationType is MAX, < otherwise.

Returns:

true if v1 is better than v2

inline bool operator==(const FOptimizationType &other) const

Equality operato.

Parameters:

other – an FOptimizationType

inline bool operator==(const OptimizationType &other) const

Equality operato.

Parameters:

other – an OptimizationType

FOptimizationType &operator=(const FOptimizationType&) = default

Copy.

Private Members

OptimizationType type_

The underlying optimization type.

std::function<bool(double, double)> comparator_

The comparison operator.

double initial_value_

Default (worst possible value)

Structs

Factory

template<class AbstractType, typename ...Args>
struct Factory

Class for generating classes for a given abtract type.

Template Parameters:
  • AbstractType – the parent type of the classes to be generator

  • Args – the arguments of the common constructor for children of AbtractType

Public Types

using Type = std::shared_ptr<AbstractType>

A shared ptr to AbstractType.

using Creator = std::function<Type(Args&&...)>

Creator method for instances of Type.

Public Functions

inline void include(const std::string &name, const int id, Creator creator, const bool keep_id = false)

Include a new element to the factory.

A new name gets id, or the next free id when id is taken; with keep_id, an id that belongs to another name, or a registered name with another id, throws std::invalid_argument instead (checked under the same lock as the insertion). An existing name keeps its id and gets the new creator, except the name of a built-in entry, which throws std::invalid_argument. Built-in entries must be unique: a duplicate name or id among them throws std::logic_error. (register_problem adds the rules for the ids of problems.)

template<typename MakeCreator>
inline int include_with_id(const std::string &name, const int first, MakeCreator make)

Include a new element under the id of its name if the name is registered, otherwise under the first free id from first, and return that id.

Choosing the id and including the element happen under one lock, so that concurrent registrations get different ids. make(id) returns the creator, which may need the id. The rules of include apply.

inline int check_or_get_next_available(const int id) const

Get the next available id.

inline int check_or_get_next_available(const int id, const std::string &name) const

Get the next available id.

inline bool is_builtin(const std::string &name) const

Whether name is the name of a built-in entry.

inline std::vector<std::string> names() const

Accessor for the list of registered names.

inline std::vector<int> ids() const

Accessor for the list of registered ids.

inline std::map<int, std::string> map() const

Accessor for the map from id to name.

inline Type create(const std::string &name, Args... params) const

Create a new instance of Type using the Creator registered; throws std::out_of_range for unknown names.

inline Type create(const int id, Args... params) const

Create a new instance of Type using the Creator registered; throws std::out_of_range for unknown ids.

Public Static Functions

static inline Factory &instance()

Accessor to static instance; the first call adds the built-in entries (see builtins.hpp)

Private Functions

inline Factory()

Adds the built-in entries before anything else can register, so their ids are deterministic.

add_builtins must not call instance() of the factory it populates.

Factory(const Factory&) = delete
Factory &operator=(const Factory&) = delete

Private Members

std::map<std::string, Creator> name_map
std::map<int, std::string> id_map
std::set<std::string> builtin_names_
bool adding_builtins_ = false
mutable std::recursive_mutex mutex_

HasRepr

struct HasRepr

Interface which defines a repr method.

Subclassed by ioh::problem::Constraint< int >, ioh::common::FOptimizationType, ioh::logger::analyzer::structures::AlgorithmInfo, ioh::logger::analyzer::structures::Attribute< T >, ioh::logger::analyzer::structures::BestPoint, ioh::logger::analyzer::structures::ExperimentInfo, ioh::logger::analyzer::structures::RunInfo, ioh::logger::analyzer::structures::ScenarioInfo, ioh::problem::Constraint< T >, ioh::problem::ConstraintSet< T >, ioh::problem::MetaData, ioh::problem::Solution< T, MultiObjective >, ioh::problem::Solution< T, SingleObjective >, ioh::problem::State< T, MultiObjective >, ioh::problem::State< T, double >, ioh::problem::submodular::graph::Graph

Public Functions

virtual std::string repr() const = 0

Representation of the object.

Friends

inline friend std::ostream &operator<<(std::ostream &os, const HasRepr &obj)

Default string stream method.

Permutation

struct Permutation

Permutation struct.

Public Functions

inline bool operator<(const Permutation &b) const

sort operator

Public Members

double value

value

int index

index

Public Static Functions

static inline std::vector<Permutation> sorted(const int n, const unsigned long seed)

sort a set of random permutations

RegisterWithFactory

template<typename Parent, typename ...Args>
struct RegisterWithFactory

Access to the factory of Parent (see problem::ProblemRegistry and suite::SuiteRegistry)

Template Parameters:
  • Parent – Abstract type

  • Args – Parent constructor args

Public Static Functions

static inline Factory<Parent, Args...> &instance()

Accessor to static instance.

Enumerations

OptimizationType

enum class ioh::common::OptimizationType

Enum containing minimization = 0 and maximization = 1 flags.

Values:

enumerator MIN
enumerator MAX

Functions

add_builtins

Warning

doxygenfunction: Unable to resolve function “ioh::common::add_builtins” with arguments None in doxygen xml output for project “iohcpp” from directory: ../../build/xml/. Potential matches:

- template<class AbstractType, typename ...Args> void add_builtins(Factory<AbstractType, Args...>&)
- void add_builtins(Factory<problem::BBOB, int, int>&)
- void add_builtins(Factory<problem::CEC2013, int, int>&)
- void add_builtins(Factory<problem::CEC2022, int, int>&)
- void add_builtins(Factory<problem::DynamicBinVal, int, int>&)
- void add_builtins(Factory<problem::PBO, int, int>&)
- void add_builtins(Factory<problem::SBOX, int, int>&)
- void add_builtins(Factory<problem::SingleObjectiveProblem<double>, int, int>&)
- void add_builtins(Factory<problem::SingleObjectiveProblem<int>, int, int>&)
- void add_builtins(Factory<problem::star_discrepancy::integer::StarDiscrepancy, int, int>&)
- void add_builtins(Factory<problem::star_discrepancy::real::StarDiscrepancy, int, int>&)
- void add_builtins(Factory<problem::submodular::GraphProblem, int, int>&)
- void add_builtins(Factory<suite::Suite<problem::SingleObjectiveProblem<double>>, std::vector<int>, std::vector<int>, std::vector<int>>&)
- void add_builtins(Factory<suite::Suite<problem::SingleObjectiveProblem<int>>, std::vector<int>, std::vector<int>, std::vector<int>>&)

all_finite

inline bool ioh::common::all_finite(const std::vector<double> &x)

Checks a vector of doubles for nan values.

Parameters:

x – vector to be checked

Returns:

true if x contains a nan value

as_vector

Warning

doxygenfunction: Unable to resolve function “ioh::common::as_vector” with arguments None in doxygen xml output for project “iohcpp” from directory: ../../build/xml/. Potential matches:

- template<typename K, typename V, typename P = std::pair<K, V>> std::vector<P> as_vector(const std::map<K, V*> &m)
- template<typename K, typename V, typename P = std::pair<K, V>> std::vector<P> as_vector(const std::map<K, V> &m)

concatenate

template<typename T>
std::vector<T> ioh::common::concatenate(std::vector<T> a, const std::vector<T> &b)

concatenates two vectors

Template Parameters:

T – the type of the vectors

Parameters:
  • a – the first vector

  • b – the second vector

Returns:

the resulting vector, containing the elements of both a and b

erase_substring

inline void ioh::common::erase_substring(std::string &str, const std::string &substr)

Inplace remove substring from string.

Parameters:
  • str – string to remove substr from

  • substr – the substring to remove

eye

inline std::vector<std::vector<double>> ioh::common::eye(const size_t n)

Create an identity n x n matrix.

Parameters:

n – the size of the matrix

Returns:

an identity matrix

fill_array

template<typename T, size_t N>
std::array<T, N> ioh::common::fill_array(const T value)

Makes an array and fills it with a specific value.

Template Parameters:
  • T – the type of the elements

  • N – the number of elements

Parameters:

value – the value

Returns:

std::array<T, N> the filled array

from_vector

template<typename T, size_t N>
std::array<T, N> ioh::common::from_vector(const std::vector<T> &v)

Convert vector into a std::array.

Template Parameters:
  • T – the type of the elements

  • N – the number of elements

Parameters:

v – the vector to convert from

Returns:

std::array<T, N> the array

get_next_id

inline int ioh::common::get_next_id(const std::vector<int> &ids)

Function to get the next non zero value in an array of integers.

has_inf

inline bool ioh::common::has_inf(const std::vector<double> &x)

Checks a vector of doubles for inf values.

Parameters:

x – vector to be checked

Returns:

true if x contains a nan value

has_nan

inline bool ioh::common::has_nan(const std::vector<double> &x)

Checks a vector of doubles for nan values.

Parameters:

x – vector to be checked

Returns:

true if x contains a nan value

is_equal

template<typename T>
bool ioh::common::is_equal(const std::vector<T> &x, const std::vector<T> &y)

Checks if two vectors are equal.

Parameters:
  • x – vector to be checked

  • y – vector to be checked

Returns:

true if all elements of x == y

keys

template<typename K, typename V>
std::vector<K> ioh::common::keys(const std::map<K, V> &m)

Retrieve the keys from a map.

ltrim

inline void ioh::common::ltrim(std::string &s)

trim leading whitespace (in place)

Parameters:

s – the string to trim

print

template<typename Iterator>
void ioh::common::print(const Iterator x, const std::string &del = " ")

Helper to print the contents of iterator to stdout.

Template Parameters:

Iterator –

Parameters:
  • x – the iterators to print, for example a std::vector

  • del – the delimeter between each element

range

inline std::vector<int> ioh::common::range(const int start, const int stop, const int step = 1)

Returns a range of integers.

Parameters:
  • start – start of the range

  • stop – end of the range

  • step – stepsize of the range

Returns:

a vector filled with numbers

rtrim

inline void ioh::common::rtrim(std::string &s)

trim from end (in place)

Parameters:

s – the string to trim

sort_colwise

template<typename T>
std::vector<std::vector<T>> ioh::common::sort_colwise(const std::vector<std::vector<T>> &vect)

Sort a 2D vector colwise (copy), assumes constant length rows.

Template Parameters:

T – the type of the vector elements

Parameters:

vect – the vector to be sorted

Returns:

std::vector<std::vector<T>> a copy of the vector with each column sorted

to_matrix

Warning

doxygenfunction: Unable to resolve function “ioh::common::to_matrix” with arguments None in doxygen xml output for project “iohcpp” from directory: ../../build/xml/. Potential matches:

- template<typename T> std::vector<std::vector<T>> to_matrix(const std::vector<T> &v)
- template<typename T> std::vector<std::vector<T>> to_matrix(const std::vector<T> &v, const size_t n, const size_t m)

trim

inline void ioh::common::trim(std::string &s)

trim from both ends (in pla0ce)

Parameters:

s – the string to trim

values

template<typename K, typename V>
std::vector<V> ioh::common::values(const std::map<K, V> &m)

Retrieve the values from a map.