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 <limits>
23#include <vector>
24#include <map>
25#include <memory>
26#include <numeric>
27#include <algorithm>
28
29// Eigen library
30#include <Eigen/Dense>
31
32// Print Optimist errors
33#ifndef OPTIMIST_ERROR
34#define OPTIMIST_ERROR(MSG) \
35 { \
36 std::ostringstream os; \
37 os << MSG; \
38 throw std::runtime_error(os.str()); \
39 }
40#endif
41
42// Assert for Optimist
43#ifndef OPTIMIST_ASSERT
44#define OPTIMIST_ASSERT(COND, MSG) \
45 if (!(COND)) \
46 { \
47 OPTIMIST_ERROR(MSG); \
48 }
49#endif
50
51// Warning for Optimist
52#ifndef OPTIMIST_WARNING
53#define OPTIMIST_WARNING(MSG) \
54 { \
55 std::cout << MSG << std::endl; \
56 }
57#endif
58
59// Warning assert for Optimist
60#ifndef OPTIMIST_ASSERT_WARNING
61#define OPTIMIST_ASSERT_WARNING(COND, MSG) \
62 if (!(COND)) \
63 { \
64 OPTIMIST_WARNING(MSG); \
65 }
66#endif
67
68
69// Define the basic constants for Optimist
70#ifndef OPTIMIST_BASIC_CONSTANTS
71#define OPTIMIST_BASIC_CONSTANTS(Real) \
72 static constexpr Real EPSILON{std::numeric_limits<Real>::epsilon()}; \
73 static constexpr Real EPSILON_HIGH{1.0e-12}; \
74 static constexpr Real EPSILON_MEDIUM{1.0e-10}; \
75 static constexpr Real EPSILON_LOW{1.0e-08}; \
76 static constexpr Real INFTY{std::numeric_limits<Real>::infinity()}; \
77 static constexpr Real QUIET_NAN{std::numeric_limits<Real>::quiet_NaN()};
78#endif
79
80#ifndef OPTIMIST_DEFAULT_INTEGER_TYPE
81#define OPTIMIST_DEFAULT_INTEGER_TYPE int
82#endif
83
87namespace Optimist
88{
89
97
102 static inline std::string table_top_left_corner() {return std::string("┌");}
103
108 static inline std::string table_top_right_corner() {return std::string("┐");}
109
114 static inline std::string table_bottom_left_corner() {return std::string("└");}
115
120 static inline std::string table_bottom_right_corner() {return std::string("┘");}
121
126 static inline std::string table_left_junction() {return std::string("├");}
127
132 static inline std::string table_right_junction() {return std::string("┤");}
133
138 static inline std::string table_top_junction() {return std::string("┬");}
139
144 static inline std::string table_bottom_junction() {return std::string("┴");}
145
150 static inline std::string table_center_cross() {return std::string("┼");}
151
156 static inline std::string table_horizontal_line() {return std::string("─");}
157
163 template <Integer N>
164 static inline std::string table_horizontal_line() {
165 std::string line;
166 for (Integer i{0}; i < N; ++i) {line += table_horizontal_line();}
167 return line;
168 }
169
174 static inline std::string table_vertical_line() {return std::string("│");}
175
176} // namespace Optimist
177
178#endif // INCLUDE_OPTIMIST_HH
#define OPTIMIST_DEFAULT_INTEGER_TYPE
Definition Optimist.hh:81
Namespace for the Optimist library.
Definition Optimist.hh:88
static std::string table_vertical_line()
Retrieve the Unicode character for the vertical line of a table.
Definition Optimist.hh:174
static std::string table_bottom_right_corner()
Retrieve the Unicode character for the bottom-right corner of a table.
Definition Optimist.hh:120
static std::string table_top_left_corner()
Retrieve the Unicode character for the top-left corner of a table.
Definition Optimist.hh:102
static std::string table_bottom_left_corner()
Retrieve the Unicode character for the bottom-left corner of a table.
Definition Optimist.hh:114
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:96
static std::string table_center_cross()
Retrieve the Unicode character for the center cross of a table.
Definition Optimist.hh:150
static std::string table_bottom_junction()
Retrieve the Unicode character for the bottom junction of a table.
Definition Optimist.hh:144
static std::string table_top_junction()
Retrieve the Unicode character for the top junction of a table.
Definition Optimist.hh:138
static std::string table_top_right_corner()
Retrieve the Unicode character for the top-right corner of a table.
Definition Optimist.hh:108
static std::string table_horizontal_line()
Retrieve the Unicode character for the horizontal line of a table.
Definition Optimist.hh:156
static std::string table_right_junction()
Retrieve the Unicode character for the right junction of a table.
Definition Optimist.hh:132
static std::string table_left_junction()
Retrieve the Unicode character for the left junction of a table.
Definition Optimist.hh:126