Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Optimist.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2025, Davide Stocco, Mattia Piazza and Enrico Bertolazzi. *
3 * *
4 * The Optimist project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Mattia Piazza Enrico Bertolazzi *
7 * University of Trento University of Trento University of Trento *
8 * davide.stocco@unitn.it mattia.piazza@unitn.it enrico.bertolazzi@unitn.it *
9\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10
11#pragma once
12
13#ifndef INCLUDE_OPTIMIST_HH
14#define INCLUDE_OPTIMIST_HH
15
16// C++ standard libraries
17#include <iostream>
18#include <ios>
19#include <iomanip>
20#include <string>
21#include <cmath>
22#include <vector>
23#include <map>
24#include <memory>
25#include <numeric>
26#include <algorithm>
27
28// Eigen library
29#include <Eigen/Dense>
30
31// Print Optimist errors
32#ifndef OPTIMIST_ERROR
33#define OPTIMIST_ERROR(MSG) \
34 { \
35 std::ostringstream os; \
36 os << MSG; \
37 throw std::runtime_error(os.str()); \
38 }
39#endif
40
41// Assert for Optimist
42#ifndef OPTIMIST_ASSERT
43#define OPTIMIST_ASSERT(COND, MSG) \
44 if (!(COND)) \
45 { \
46 OPTIMIST_ERROR(MSG); \
47 }
48#endif
49
50// Warning for Optimist
51#ifndef OPTIMIST_WARNING
52#define OPTIMIST_WARNING(MSG) \
53 { \
54 std::cout << MSG << std::endl; \
55 }
56#endif
57
58// Warning assert for Optimist
59#ifndef OPTIMIST_ASSERT_WARNING
60#define OPTIMIST_ASSERT_WARNING(COND, MSG) \
61 if (!(COND)) \
62 { \
63 OPTIMIST_WARNING(MSG); \
64 }
65#endif
66
67
68// Define the basic constants for Optimist
69#ifndef OPTIMIST_BASIC_CONSTANTS
70#define OPTIMIST_BASIC_CONSTANTS(Real) \
71 static constexpr Real EPSILON{std::numeric_limits<Real>::epsilon()}; \
72 static constexpr Real EPSILON_HIGH{1.0e-12}; \
73 static constexpr Real EPSILON_MEDIUM{1.0e-10}; \
74 static constexpr Real EPSILON_LOW{1.0e-08}; \
75 static constexpr Real INFTY{std::numeric_limits<Real>::infinity()}; \
76 static constexpr Real QUIET_NAN{std::numeric_limits<Real>::quiet_NaN()};
77#endif
78
79#ifndef OPTIMIST_DEFAULT_INTEGER_TYPE
80#define OPTIMIST_DEFAULT_INTEGER_TYPE int
81#endif
82
86namespace Optimist
87{
88
96
101 static inline std::string table_top_left_corner() {return "┌";}
102
107 static inline std::string table_top_right_corner() {return "┐";}
108
113 static inline std::string table_bottom_left_corner() {return "└";}
114
119 static inline std::string table_bottom_right_corner() {return "┘";}
120
125 static inline std::string table_left_junction() {return "├";}
126
131 static inline std::string table_right_junction() {return "┤";}
132
137 static inline std::string table_top_junction() {return "┬";}
138
143 static inline std::string table_bottom_junction() {return "┴";}
144
149 static inline std::string table_center_cross() {return "┼";}
150
155 static inline std::string table_horizontal_line() {return "─";}
156
162 template <Integer N>
163 static inline std::string table_horizontal_line() {
164 std::string line;
165 for (Integer i{0}; i < N; ++i) {line += table_horizontal_line();}
166 return line;
167 }
168
173 static inline std::string table_vertical_line() {return "│";}
174
175} // namespace Optimist
176
177#endif // INCLUDE_OPTIMIST_HH
#define OPTIMIST_DEFAULT_INTEGER_TYPE
Definition Optimist.hh:80
Namespace for the Optimist library.
Definition Optimist.hh:87
static std::string table_vertical_line()
Retrieve the Unicode character for the vertical line of a table.
Definition Optimist.hh:173
static std::string table_bottom_right_corner()
Retrieve the Unicode character for the bottom-right corner of a table.
Definition Optimist.hh:119
static std::string table_top_left_corner()
Retrieve the Unicode character for the top-left corner of a table.
Definition Optimist.hh:101
static std::string table_bottom_left_corner()
Retrieve the Unicode character for the bottom-left corner of a table.
Definition Optimist.hh:113
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:95
static std::string table_center_cross()
Retrieve the Unicode character for the center cross of a table.
Definition Optimist.hh:149
static std::string table_bottom_junction()
Retrieve the Unicode character for the bottom junction of a table.
Definition Optimist.hh:143
static std::string table_top_junction()
Retrieve the Unicode character for the top junction of a table.
Definition Optimist.hh:137
static std::string table_top_right_corner()
Retrieve the Unicode character for the top-right corner of a table.
Definition Optimist.hh:107
static std::string table_horizontal_line()
Retrieve the Unicode character for the horizontal line of a table.
Definition Optimist.hh:155
static std::string table_right_junction()
Retrieve the Unicode character for the right junction of a table.
Definition Optimist.hh:131
static std::string table_left_junction()
Retrieve the Unicode character for the left junction of a table.
Definition Optimist.hh:125