problem.h
Go to the documentation of this file.
1 /******************************************************************************
2 Copyright (c) 2017, Alexander W Winkler. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6 
7 * Redistributions of source code must retain the above copyright notice, this
8  list of conditions and the following disclaimer.
9 
10 * Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 
14 * Neither the name of the copyright holder nor the names of its
15  contributors may be used to endorse or promote products derived from
16  this software without specific prior written permission.
17 
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ******************************************************************************/
29 
30 #ifndef IFOPT_INCLUDE_OPT_PROBLEM_H_
31 #define IFOPT_INCLUDE_OPT_PROBLEM_H_
32 
33 #include "variable_set.h"
34 #include "constraint_set.h"
35 #include "cost_term.h"
36 
40 namespace ifopt {
41 
42 
97 class Problem {
98 public:
102 
106  Problem ();
107  virtual ~Problem () = default;
108 
118  void AddVariableSet(VariableSet::Ptr variable_set);
119 
128  void AddConstraintSet(ConstraintSet::Ptr constraint_set);
129 
138  void AddCostSet(CostTerm::Ptr cost_set);
139 
143  void SetVariables(const double* x);
144 
149 
154  bool HasCostTerms() const;
155 
161 
165  VectorXd GetVariableValues() const;
166 
170  double EvaluateCostFunction(const double* x);
171 
177  VectorXd EvaluateCostFunctionGradient(const double* x,
178  bool use_finite_difference_approximation = false,
179  double epsilon = std::numeric_limits<double>::epsilon());
180 
184  int GetNumberOfConstraints() const;
185 
190 
194  VectorXd EvaluateConstraints(const double* x);
195 
201  void EvalNonzerosOfJacobian(const double* x, double* values);
202 
210 
217  Jacobian GetJacobianOfCosts () const;
218 
224  void SaveCurrent();
225 
230 
234  void SetOptVariables(int iter);
235 
239  void SetOptVariablesFinal();
240 
244  int GetIterationCount() const { return x_prev.size(); };
245 
249  void PrintCurrent() const;
250 
255  const Composite& GetConstraints() const { return constraints_; };
256 
261  const Composite& GetCosts() const { return costs_; };
262 
267  const std::vector<VectorXd> &GetIterations() const { return x_prev; };
268 
269 private:
273 
274  std::vector<VectorXd> x_prev;
275 
276  VectorXd ConvertToEigen(const double* x) const;
277 };
278 
279 } /* namespace opt */
280 
281 #endif /* IFOPT_INCLUDE_OPT_PROBLEM_H_ */
ifopt::Problem::GetJacobianOfCosts
Jacobian GetJacobianOfCosts() const
The sparse-matrix representation of Jacobian of the costs.
Definition: problem.cc:195
ifopt::Problem::GetNumberOfOptimizationVariables
int GetNumberOfOptimizationVariables() const
The number of optimization variables.
Definition: problem.cc:92
ifopt::Problem::EvaluateCostFunction
double EvaluateCostFunction(const double *x)
The scalar cost for current optimization variables x.
Definition: problem.cc:116
ifopt::Problem::GetIterations
const std::vector< VectorXd > & GetIterations() const
Read access to the history of iterations.
Definition: problem.h:294
ifopt::Problem::SetVariables
void SetVariables(const double *x)
Updates the variables with the values of the raw pointer x.
Definition: problem.cc:110
ifopt::Problem::EvaluateCostFunctionGradient
VectorXd EvaluateCostFunctionGradient(const double *x, bool use_finite_difference_approximation=false, double epsilon=std::numeric_limits< double >::epsilon())
The column-vector of derivatives of the cost w.r.t. each variable.
Definition: problem.cc:127
ifopt::Problem::VecBound
Component::VecBound VecBound
Definition: problem.h:126
ifopt::Component::VecBound
std::vector< Bounds > VecBound
Definition: composite.h:69
ifopt::Problem::GetBoundsOnConstraints
VecBound GetBoundsOnConstraints() const
The upper and lower bound of each individual constraint.
Definition: problem.cc:154
ifopt::Problem::HasCostTerms
bool HasCostTerms() const
True if the optimization problem includes a cost, false if merely a feasibility problem is defined.
Definition: problem.cc:173
ifopt::Problem::VectorXd
Component::VectorXd VectorXd
Definition: problem.h:128
ifopt::Problem::EvalNonzerosOfJacobian
void EvalNonzerosOfJacobian(const double *x, double *values)
Extracts those entries from constraint Jacobian that are not zero.
Definition: problem.cc:179
ifopt::Problem::AddConstraintSet
void AddConstraintSet(ConstraintSet::Ptr constraint_set)
Add a set of multiple constraints to the optimization problem.
Definition: problem.cc:78
ifopt::Problem::x_prev
std::vector< VectorXd > x_prev
the pure variables for every iteration.
Definition: problem.h:301
ifopt::Problem::SetOptVariablesFinal
void SetOptVariablesFinal()
Sets the optimization variables to those of the final iteration.
Definition: problem.cc:219
ifopt::Problem::Jacobian
Component::Jacobian Jacobian
Definition: problem.h:127
constraint_set.h
ifopt::Problem::GetNumberOfConstraints
int GetNumberOfConstraints() const
The number of individual constraints.
Definition: problem.cc:160
ifopt::Problem::GetJacobianOfConstraints
Jacobian GetJacobianOfConstraints() const
The sparse-matrix representation of Jacobian of the constraints.
Definition: problem.cc:189
cost_term.h
ifopt::Problem::EvaluateConstraints
VectorXd EvaluateConstraints(const double *x)
Each constraint value g(x) for current optimization variables x.
Definition: problem.cc:166
ifopt::Problem::Problem
Problem()
Creates a optimization problem with no variables, costs or constraints.
Definition: problem.cc:64
ifopt::Problem::costs_
Composite costs_
Definition: problem.h:299
ifopt::Problem::SetOptVariables
void SetOptVariables(int iter)
Sets the optimization variables to those at iteration iter.
Definition: problem.cc:213
ifopt::Problem::GetVariableValues
VectorXd GetVariableValues() const
The current value of the optimization variables.
Definition: problem.cc:104
ifopt::Problem::GetBoundsOnOptimizationVariables
VecBound GetBoundsOnOptimizationVariables() const
The maximum and minimum value each optimization variable is allowed to have.
Definition: problem.cc:98
ifopt::Problem::AddCostSet
void AddCostSet(CostTerm::Ptr cost_set)
Add a cost term to the optimization problem.
Definition: problem.cc:85
ifopt::Composite::Ptr
std::shared_ptr< Composite > Ptr
Definition: composite.h:164
ifopt::Problem::GetIterationCount
int GetIterationCount() const
The number of iterations it took to solve the problem.
Definition: problem.h:271
ifopt::Component::Ptr
std::shared_ptr< Component > Ptr
Definition: composite.h:65
ifopt::Problem::AddVariableSet
void AddVariableSet(VariableSet::Ptr variable_set)
Add one individual set of variables to the optimization problem.
Definition: problem.cc:72
ifopt::Problem::variables_
Composite::Ptr variables_
Definition: problem.h:294
variable_set.h
ifopt
common namespace for all elements in this library.
Definition: bounds.h:33
ifopt::Problem::SaveCurrent
void SaveCurrent()
Saves the current values of the optimization variables in x_prev.
Definition: problem.cc:201
ifopt::Problem::~Problem
virtual ~Problem()=default
ifopt::Composite
A collection of components which is treated as another Component.
Definition: composite.h:162
ifopt::Component::VectorXd
Eigen::VectorXd VectorXd
Definition: composite.h:68
ifopt::Problem::GetConstraints
const Composite & GetConstraints() const
Read access to the constraints composite.
Definition: problem.h:282
ifopt::ConstraintSet::Ptr
std::shared_ptr< ConstraintSet > Ptr
Definition: constraint_set.h:107
ifopt::Component::Jacobian
Eigen::SparseMatrix< double, Eigen::RowMajor > Jacobian
Definition: composite.h:67
ifopt::Problem::GetOptVariables
Composite::Ptr GetOptVariables() const
Read/write access to the current optimization variables.
Definition: problem.cc:207
ifopt::Problem::PrintCurrent
void PrintCurrent() const
Prints the variables, costs and constraints.
Definition: problem.cc:225
ifopt::Problem::GetCosts
const Composite & GetCosts() const
Read access to the costs composite.
Definition: problem.h:288
ifopt::Problem::ConvertToEigen
VectorXd ConvertToEigen(const double *x) const
Definition: problem.cc:254
ifopt::Problem::constraints_
Composite constraints_
Definition: problem.h:298


ifopt
Author(s): Alexander W. Winkler
autogenerated on Thu Sep 15 2022 02:14:55