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
68 void evaluate_impl(Real x, Real & out) const {out = this->m_m*x + this->m_q;}
69
75 void first_derivative_impl(Real /*x*/, Real & out) const {out = this->m_m;}
76
82 void second_derivative_impl(Real /*x*/, Real & out) const {out = 0.0;}
83
84 }; // class Linear
85
86 } // namespace TestSet
87
88} // namespace Optimist
89
90#endif // OPTIMIST_TESTSET_LINEAR_HH
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:70
std::vector< InputType > m_guesses
Definition Function.hh:63
std::vector< InputType > m_solutions
Definition Function.hh:62
Real m_m
Definition Linear.hh:42
void evaluate_impl(Real x, Real &out) const
Definition Linear.hh:68
Real m_q
Definition Linear.hh:43
Linear()
Definition Linear.hh:51
void second_derivative_impl(Real, Real &out) const
Definition Linear.hh:82
std::string name_impl() const
Definition Linear.hh:61
void first_derivative_impl(Real, Real &out) const
Definition Linear.hh:75
Namespace for the Optimist library.
Definition Optimist.hh:87