G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsOptimizer.h
Go to the documentation of this file.
1
16#include <gsIO/gsOptionList.h>
17
18#pragma once
19
20namespace gismo
21{
22
26template <typename T>
28{
29public:
30
33 :
34 m_op(nullptr)
35 {};
36
38 :
39 m_op(problem)
40 {
41
42 }
43
45 virtual ~gsOptimizer() { };
46
47public:
48
49 virtual void defaultOptions()
50 {
51 m_options.addInt("MaxIterations","Maximum iterations",100);
52 m_options.addInt("Verbose","Verbosity level",0);
53 }
54
55 virtual void getOptions()
56 {
57 m_maxIterations = m_options.getInt("MaxIterations");
58 m_verbose = m_options.getInt("Verbose");
59 }
60
64 virtual bool intermediateCallback() { return true;}
65
66public:
67
68 const gsMatrix<T> & currentDesign() const { return m_curDesign; }
69 gsMatrix<T> & currentDesign() { return m_curDesign; }
70
71 T currentObjValue() const
72 {
73 gsAsConstVector<T> tmp(m_curDesign.data(), m_op->numDesignVars());
74 return m_op->evalObj(tmp);
75 }
76
77 T objective() const { return m_finalObjective; }
78
79 int iterations() const { return m_numIterations; }
80
81 gsOptionList & options() { return m_options; }
82
83public:
84
85 virtual void solve (const gsMatrix<T> & initialGuess) = 0;
86 virtual void solve ()
87 {
88 m_curDesign.resize(m_op->numDesignVars(),1);
89 m_curDesign.setZero();
90 this->solve(m_curDesign);
91 }
92
93 std::ostream &print(std::ostream &os) const
94 {
95 os << "gsOptimizer";
96 return os;
97 }
98
99
100protected:
101
102 gsOptProblem<T> * m_op;
103
106
109 index_t m_maxIterations, m_verbose;
110
111protected:
112
113 // Statistics
114 index_t m_numIterations;
115 T m_finalObjective;
116
117private:
118
130 gsOptimizer(const gsOptimizer & );
131 gsOptimizer& operator=(const gsOptimizer & );
133};
134
135} // end namespace gismo
137// note: must be statically compiled in header-only mode
138//#ifndef GISMO_BUILD_LIB
139//#include GISMO_HPP_HEADER(gsOptimizer.hpp)
140//#endif
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Class defining an optimization problem.
Definition gsOptProblem.h:25
Class defining an optimizer.
Definition gsOptimizer.h:28
gsOptimizer()
Definition gsOptimizer.h:32
virtual ~gsOptimizer()
Definition gsOptimizer.h:45
gsOptionList m_options
Options.
Definition gsOptimizer.h:108
virtual bool intermediateCallback()
Callback function is executed after every iteration. Returning false causes premature termination of ...
Definition gsOptimizer.h:64
gsMatrix< T > m_curDesign
Current design variables (and starting point )
Definition gsOptimizer.h:105
Class which holds a list of parameters/options, and provides easy access to them.
Definition gsOptionList.h:33
void addInt(const std::string &label, const std::string &desc, const index_t &value)
Adds a option named label, with description desc and value value.
Definition gsOptionList.cpp:201
const index_t & getInt(const std::string &label) const
Reads value for option label from options.
Definition gsOptionList.cpp:37
#define index_t
Definition gsConfig.h:32
This is the main header file that collects wrappers of Eigen for linear algebra.
Provides declaration of an optimization problem.
Provides a list of labeled parameters/options that can be set and accessed easily.
The G+Smo namespace, containing all definitions for the library.