Monte Carlo Integration Library 1.0
High-performance Monte Carlo methods for numerical integration and optimization
types.hpp
Go to the documentation of this file.
1#pragma once
2#include <vector>
3#include <functional>
4#include <limits>
5#include <iostream>
6
19namespace mc{
20namespace optim{
21
26 using Real = double;
27
31 using Coordinates = std::vector<Real>;
32
37 using ObjectiveFunction = std::function<Real(const Coordinates&)>;
38
42 enum class OptimizationMode {
45 };
46
51 struct Solution {
56
63 if (mode == OptimizationMode::MINIMIZE) {
64 return { {}, std::numeric_limits<Real>::infinity() };
65 } else {
66 return { {}, -std::numeric_limits<Real>::infinity() };
67 }
68 }
69
74 bool isBetterThan(const Solution& other, OptimizationMode mode) const {
75 if (mode == OptimizationMode::MINIMIZE) return value < other.value;
76 return value > other.value;
77 }
78 };
79} //namespace mc
80} //namespace optim
OptimizationMode
Optimization goal.
Definition types.hpp:42
std::function< Real(const Coordinates &)> ObjectiveFunction
Objective function signature.
Definition types.hpp:37
std::vector< Real > Coordinates
A point in the N-dimensional search space.
Definition types.hpp:31
double Real
Scalar precision used across optimizers.
Definition types.hpp:26
Represents a candidate solution in the search space.
Definition types.hpp:51
static Solution make_worst(OptimizationMode mode)
Helper to create a worst-case solution for initialization.
Definition types.hpp:62
Coordinates params
Parameter vector (coordinates in the search space).
Definition types.hpp:53
bool isBetterThan(const Solution &other, OptimizationMode mode) const
Compare two solutions according to the optimization mode.
Definition types.hpp:74
Real value
Evaluated objective value for params.
Definition types.hpp:55