G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsOptimizer.h
Go to the documentation of this file.
1 
14 #include <gsCore/gsLinearAlgebra.h>
16 #include <gsIO/gsOptionList.h>
17 
18 #pragma once
19 
20 namespace gismo
21 {
22 
26 template <typename T>
28 {
29 public:
30 
33  :
34  m_op(nullptr)
35  {};
36 
37  gsOptimizer(gsOptProblem<T> * problem)
38  :
39  m_op(problem)
40  {
41 
42  }
43 
45  virtual ~gsOptimizer() { };
46 
47 public:
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 
66 public:
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 
83 public:
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 
100 protected:
101 
102  gsOptProblem<T> * m_op;
103 
106 
109  index_t m_maxIterations, m_verbose;
110 
111 protected:
112 
113  // Statistics
114  index_t m_numIterations;
115  T m_finalObjective;
116 
117 private:
118 
130  gsOptimizer(const gsOptimizer & );
131  gsOptimizer& operator=(const gsOptimizer & );
133 };
134 
135 } // end namespace gismo
136 
137 // note: must be statically compiled in header-only mode
138 //#ifndef GISMO_BUILD_LIB
139 //#include GISMO_HPP_HEADER(gsOptimizer.hpp)
140 //#endif
Class defining an optimization problem.
Definition: gsOptProblem.h:24
virtual ~gsOptimizer()
Definition: gsOptimizer.h:45
Class defining an optimizer.
Definition: gsOptimizer.h:27
gsOptionList m_options
Options.
Definition: gsOptimizer.h:108
gsOptimizer()
Definition: gsOptimizer.h:32
#define index_t
Definition: gsConfig.h:32
Provides declaration of an optimization problem.
const index_t & getInt(const std::string &label) const
Reads value for option label from options.
Definition: gsOptionList.cpp:37
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
Provides a list of labeled parameters/options that can be set and accessed easily.
virtual bool intermediateCallback()
Callback function is executed after every iteration. Returning false causes premature termination of ...
Definition: gsOptimizer.h:64
This is the main header file that collects wrappers of Eigen for linear algebra.
Class which holds a list of parameters/options, and provides easy access to them. ...
Definition: gsOptionList.h:32
gsMatrix< T > m_curDesign
Current design variables (and starting point )
Definition: gsOptimizer.h:105