Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
EllipticParaboloid.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2025, Davide Stocco and Enrico Bertolazzi. *
3 * *
4 * The Optimist project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Enrico Bertolazzi *
7 * University of Trento University of Trento *
8 * davide.stocco@unitn.it enrico.bertolazzi@unitn.it *
9\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10
11#pragma once
12
13#ifndef OPTIMIST_TESTSET_ELLIPTICPARABOLOID_HH
14#define OPTIMIST_TESTSET_ELLIPTICPARABOLOID_HH
15
16#include "Optimist/Function.hh"
17
18namespace Optimist {
19
20 namespace TestSet {
21
34 template <typename Vector>
35 requires TypeTrait<Vector>::IsEigen && (!TypeTrait<Vector>::IsFixed ||
36 TypeTrait<Vector>::Dimension == 2)
37 class EllipticParaboloid : public Function<Vector,
38 typename Vector::Scalar,
39 EllipticParaboloid<Vector>> {
40 public:
42 using Scalar = typename Vector::Scalar;
44 FirstDerivative;
46 SecondDerivative;
47
49
50 private:
51 Scalar m_a{1.0};
52 Scalar m_b{1.0};
53
54 public:
59 this->m_solutions.emplace_back(0.0, 0.0);
60 for (Scalar x{-100}; x < 100 + EPSILON; x += 100 / 25.0) {
61 for (Scalar y{-100}; y < 100 + EPSILON; y += 100 / 25.0) {
62 this->m_guesses.emplace_back(x, y);
63 }
64 }
65 }
66
71 constexpr std::string name_impl() const {
72 return "EllipticParaboloid";
73 }
74
80 bool evaluate_impl(const Vector &x, Scalar &out) const {
81 out = this->m_a * x(0) * x(0) + this->m_b * x(1) * x(1);
82 return std::isfinite(out);
83 }
84
90 bool first_derivative_impl(const Vector &x, FirstDerivative &out) const {
91 out << 2.0 * this->m_a * x(0), 2.0 * this->m_b * x(1);
92 return out.allFinite();
93 }
94
100 bool second_derivative_impl(const Vector & /*x*/,
101 SecondDerivative &out) const {
102 out << 2.0 * this->m_a, 0.0, 0.0, 2.0 * this->m_b;
103 return out.allFinite();
104 }
105
106 }; // class EllipticParaboloid
107
108 } // namespace TestSet
109
110} // namespace Optimist
111
112#endif // OPTIMIST_TESTSET_ELLIPTICPARABOLOID_HH
#define OPTIMIST_BASIC_CONSTANTS(Scalar)
Definition Optimist.hh:70
std::conditional_t< InputTrait::IsEigen||OutputTrait::IsEigen, std::conditional_t< InputTrait::IsSparse||OutputTrait::IsSparse, std::vector< Eigen::SparseMatrix< Scalar > >, std::vector< Eigen::Matrix< Scalar, OutputTrait::Dimension, InputTrait::Dimension > > >, Scalar > SecondDerivative
Definition Function.hh:64
std::conditional_t< InputTrait::IsEigen||OutputTrait::IsEigen, std::conditional_t< InputTrait::IsSparse||OutputTrait::IsSparse, Eigen::SparseMatrix< Scalar >, Eigen::Matrix< Scalar, OutputTrait::Dimension, InputTrait::Dimension > >, Scalar > FirstDerivative
Definition Function.hh:56
bool evaluate_impl(const Vector &x, Scalar &out) const
Definition EllipticParaboloid.hh:80
typename Vector::Scalar Scalar
Definition EllipticParaboloid.hh:42
bool second_derivative_impl(const Vector &, SecondDerivative &out) const
Definition EllipticParaboloid.hh:100
Scalar m_b
Definition EllipticParaboloid.hh:52
Scalar m_a
Definition EllipticParaboloid.hh:51
bool first_derivative_impl(const Vector &x, FirstDerivative &out) const
Definition EllipticParaboloid.hh:90
TypeTrait< Vector > VectorTrait
Definition EllipticParaboloid.hh:41
EllipticParaboloid()
Definition EllipticParaboloid.hh:58
constexpr std::string name_impl() const
Definition EllipticParaboloid.hh:71
Namespace for the Optimist library.
Definition Optimist.hh:90
Definition Optimist.hh:114