Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Linear.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 OPTIMIST_TESTSET_LINEAR_HH
14#define OPTIMIST_TESTSET_LINEAR_HH
15
16#include "Optimist/TestSet.hh"
17
18namespace Optimist
19{
20
21 namespace TestSet
22 {
23
39 template <typename Real>
40 class Linear : public Function<Real, 1, 1, Linear<Real>>
41 {
42 Real m_m{1.0};
43 Real m_q{1.0};
44
45 public:
47
48
52 {
53 this->m_solutions.emplace_back(-this->m_q/this->m_m);
54 this->m_guesses.emplace_back(0.0);
55 }
56
61 std::string name_impl() const {return "Linear";}
62
69 bool evaluate_impl(Real x, Real & out) const
70 {
71 out = this->m_m*x + this->m_q;
72 return std::isfinite(out);
73 }
74
81 bool first_derivative_impl(Real /*x*/, Real & out) const
82 {
83 out = this->m_m;
84 return std::isfinite(out);
85 }
86
93 bool second_derivative_impl(Real /*x*/, Real & out) const
94 {
95 out = 0.0;
96 return std::isfinite(out);
97 }
98
99 }; // class Linear
100
101 } // namespace TestSet
102
103} // namespace Optimist
104
105#endif // OPTIMIST_TESTSET_LINEAR_HH
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:71
std::vector< InputType > m_guesses
Definition Function.hh:66
std::vector< InputType > m_solutions
Definition Function.hh:65
Real m_m
Definition Linear.hh:42
bool evaluate_impl(Real x, Real &out) const
Definition Linear.hh:69
Real m_q
Definition Linear.hh:43
bool first_derivative_impl(Real, Real &out) const
Definition Linear.hh:81
Linear()
Definition Linear.hh:51
bool second_derivative_impl(Real, Real &out) const
Definition Linear.hh:93
std::string name_impl() const
Definition Linear.hh:61
Namespace for the Optimist library.
Definition Optimist.hh:88