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_SCALAR_FUNCTION_LINEAR_HH
14#define OPTIMIST_SCALAR_FUNCTION_LINEAR_HH
15
16#include "Optimist/TestSet.hh"
18
19namespace Optimist
20{
21
22 namespace TestSet
23 {
24
40 template <typename Real>
41 class Linear : public ScalarFunction<Real, Linear<Real>>
42 {
43 Real m_m{1.0};
44 Real m_q{1.0};
45
46 public:
48
49
53 {
54 this->m_solutions.emplace_back(-this->m_q/this->m_m);
55 this->m_guesses.emplace_back(0.0);
56 }
57
62 std::string name_impl() const {return "Linear";}
63
69 void evaluate_impl(Real x, Real & out) const {out = this->m_m*x + this->m_q;}
70
76 void first_derivative_impl(Real /*x*/, Real & out) const {out = this->m_m;}
77
83 void second_derivative_impl(Real /*x*/, Real & out) const {out = 0.0;}
84
85 }; // class Linear
86
87 } // namespace TestSet
88
89} // namespace Optimist
90
91#endif // OPTIMIST_SCALAR_FUNCTION_LINEAR_HH
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:70
std::vector< InputType > m_solutions
Definition Function.hh:52
std::vector< InputType > m_guesses
Definition Function.hh:53
ScalarFunction()
Definition ScalarFunction.hh:38
Real m_m
Definition Linear.hh:43
void evaluate_impl(Real x, Real &out) const
Definition Linear.hh:69
Real m_q
Definition Linear.hh:44
Linear()
Definition Linear.hh:52
void second_derivative_impl(Real, Real &out) const
Definition Linear.hh:83
std::string name_impl() const
Definition Linear.hh:62
void first_derivative_impl(Real, Real &out) const
Definition Linear.hh:76
Namespace for the Optimist library.
Definition Optimist.hh:87