- 3.0.2 optimal control module.
InitStateConstraint.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
10 
11 namespace ct {
12 namespace optcon {
13 
22 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
24 {
25 public:
26  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
28 
30  typedef typename DIMENSIONS::state_vector_t state_vector_t;
31  typedef Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> VectorXs;
32 
36  InitStateConstraint() = default;
43  InitStateConstraint(const state_vector_t& x0, std::shared_ptr<OptVectorDms<STATE_DIM, CONTROL_DIM, SCALAR>> w)
44  : w_(w), x_0_(x0)
45  {
46  lb_.setConstant(SCALAR(0.0));
47  ub_.setConstant(SCALAR(0.0));
48  }
49 
55  void updateConstraint(const state_vector_t& x0) { x_0_ = x0; }
56  VectorXs eval() override { return w_->getOptimizedState(0) - x_0_; }
57  VectorXs evalSparseJacobian() override { return state_vector_t::Ones(); }
58  size_t getNumNonZerosJacobian() override { return (size_t)STATE_DIM; }
59  void genSparsityPattern(Eigen::VectorXi& iRow_vec, Eigen::VectorXi& jCol_vec) override
60  {
61  size_t indexNumber = 0;
62  indexNumber += BASE::genDiagonalIndices(w_->getStateIndex(0), STATE_DIM, iRow_vec, jCol_vec, indexNumber);
63  }
64 
65  VectorXs getLowerBound() override { return lb_; }
66  VectorXs getUpperBound() override { return ub_; }
67  size_t getConstraintSize() override { return STATE_DIM; }
68 private:
69  std::shared_ptr<OptVectorDms<STATE_DIM, CONTROL_DIM, SCALAR>> w_;
70  state_vector_t x_0_;
71 
72  //Constraint bounds
73  state_vector_t lb_; // lower bound
74  state_vector_t ub_; // upper bound
75 };
76 
77 } // namespace optcon
78 } // namespace ct
void genSparsityPattern(Eigen::VectorXi &iRow_vec, Eigen::VectorXi &jCol_vec) override
Returns the sparsity structure of the constraint jacobian.
Definition: InitStateConstraint.h:59
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef DmsDimensions< STATE_DIM, CONTROL_DIM, SCALAR > DIMENSIONS
Definition: InitStateConstraint.h:27
InitStateConstraint()=default
Default constructor.
tpl::DiscreteConstraintBase< SCALAR > BASE
Definition: InitStateConstraint.h:29
Implements an abstract base class from which all the discrete custom NLP constraints should derive...
Definition: DiscreteConstraintBase.h:21
This class is a wrapper around the NLP Optvector. It wraps the Vectors from the NLP solvers into stat...
Definition: OptVectorDms.h:37
size_t getNumNonZerosJacobian() override
Returns the number of non zero elements of the jacobian.
Definition: InitStateConstraint.h:58
CppAD::AD< CppAD::cg::CG< double > > SCALAR
Defines basic types used in the DMS algorithm.
Definition: DmsDimensions.h:18
DIMENSIONS::state_vector_t state_vector_t
Definition: InitStateConstraint.h:30
VectorXs eval() override
Evaluates the constraint violation.
Definition: InitStateConstraint.h:56
VectorXs evalSparseJacobian() override
Returns the non zero elements of the eval method with respect to the optimization variables...
Definition: InitStateConstraint.h:57
The implementation of the DMS initial state constraint.
Definition: InitStateConstraint.h:23
InitStateConstraint(const state_vector_t &x0, std::shared_ptr< OptVectorDms< STATE_DIM, CONTROL_DIM, SCALAR >> w)
Custom constructor.
Definition: InitStateConstraint.h:43
size_t getConstraintSize() override
Returns size of the constraint vector.
Definition: InitStateConstraint.h:67
StateVector< state_dim > x0
Definition: ConstrainedNLOCTest.cpp:14
VectorXs getLowerBound() override
Returns the lower bound of the constraint.
Definition: InitStateConstraint.h:65
size_t genDiagonalIndices(const size_t col_start, const size_t num_elements, Eigen::VectorXi &iRow_vec, Eigen::VectorXi &jCol_vec, const size_t indexNumber)
This method generates Row and Column vectors which indicate the sparsity pattern of the constraint ja...
Definition: DiscreteConstraintBase.h:172
void updateConstraint(const state_vector_t &x0)
Updates the constraint.
Definition: InitStateConstraint.h:55
VectorXs getUpperBound() override
Returns the upper bound of the constraint.
Definition: InitStateConstraint.h:66
Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > VectorXs
Definition: InitStateConstraint.h:31