Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Booth.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_BOOTH_HH
14#define OPTIMIST_TESTSET_BOOTH_HH
15
16#include "Optimist/TestSet.hh"
17
18namespace Optimist
19{
20
21 namespace TestSet
22 {
23
35 template <typename Real>
36 class Booth : public Function<Real, 2, 2, Booth<Real>>
37 {
38 public:
40
45
50 {
51 this->m_solutions.emplace_back(1.0, 3.0);
52 for (Real x{-10.0}; x < 10.0 + EPSILON; x += 5.0) {
53 for (Real y{-10.0}; y < 10.0 + EPSILON; y += 5.0) {
54 this->m_guesses.emplace_back(x, y);
55 }
56 }
57 }
58
63 std::string name_impl() const {return "Booth";}
64
71 bool evaluate_impl(InputVector const & x, OutputVector & out) const
72 {
73 out << x(0) + 2.0*x(1) - 7.0, 2.0*x(0) + x(1) - 5.0;
74 return out.allFinite();
75 }
76
83 bool first_derivative_impl(InputVector const & /*x*/, Matrix & out) const
84 {
85 out << 1.0, 2.0, 2.0, 1.0;
86 return out.allFinite();
87 }
88
95 bool second_derivative_impl(InputVector const & /*x*/, Tensor & out) const
96 {
97 out.resize(this->output_dimension());
98 std::for_each(out.begin(), out.end(), [] (Matrix& m) {m.setZero();});
99 return true;
100 }
101
102 }; // class Booth
103
104 } // namespace TestSet
105
106} // namespace Optimist
107
108#endif // OPTIMIST_TESTSET_BOOTH_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
constexpr Integer output_dimension() const
Definition Function.hh:123
typename FunctionBase< Real, N, M, Booth< Real >, false >::OutputType OutputVector
Definition Function.hh:200
typename FunctionBase< Real, N, M, Booth< Real >, false >::InputType InputVector
Definition Function.hh:199
typename FunctionBase< Real, N, M, Booth< Real >, false >::FirstDerivativeType Matrix
Definition Function.hh:203
typename FunctionBase< Real, N, M, Booth< Real >, false >::SecondDerivativeType Tensor
Definition Function.hh:204
Booth()
Definition Booth.hh:49
bool evaluate_impl(InputVector const &x, OutputVector &out) const
Definition Booth.hh:71
std::string name_impl() const
Definition Booth.hh:63
bool first_derivative_impl(InputVector const &, Matrix &out) const
Definition Booth.hh:83
bool second_derivative_impl(InputVector const &, Tensor &out) const
Definition Booth.hh:95
Namespace for the Optimist library.
Definition Optimist.hh:88