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.
-
inline explicit CpuTimer(std::string info_msg = "")¶
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)
-
inline FOptimizationType(const OptimizationType type = OptimizationType::MAX)¶
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.
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 whenidis 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.
Public Static Functions
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.
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.
-
virtual std::string repr() const = 0¶
Permutation¶
-
struct Permutation¶
Permutation struct.
Public Functions
-
inline bool operator<(const Permutation &b) const¶
sort operator
Public Static Functions
-
static inline std::vector<Permutation> sorted(const int n, const unsigned long seed)¶
sort a set of random permutations
-
inline bool operator<(const Permutation &b) const¶
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
Enumerations¶
OptimizationType¶
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¶
from_vector¶
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¶
keys¶
ltrim¶
-
inline void ioh::common::ltrim(std::string &s)¶
trim leading whitespace (in place)
- Parameters:
s – the string to trim
print¶
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