DirectTrajectoryOptimization  v0.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
ConstraintsBase.hpp
Go to the documentation of this file.
1 /***********************************************************************************
2 Copyright (c) 2017, Diego Pardo. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6  * Redistributions of source code must retain the above copyright notice,
7  this list of conditions and the following disclaimer.
8  * Redistributions in binary form must reproduce the above copyright notice,
9  this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of ETH ZURICH nor the names of its contributors may be used
12  to endorse or promote products derived from this software without specific
13  prior written permission.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
16 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
18 SHALL ETH ZURICH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
19 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 ***************************************************************************************/
25 
31 #ifndef _CONSTRAINTSBASE_H
32 #define _CONSTRAINTSBASE_H
33 
34 #include <Eigen/Dense>
35 
36 namespace DirectTrajectoryOptimization {
40 namespace BaseClass{
41 
45 template <class DIMENSIONS>
47 
48 public:
49 
50  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
51 
52  typedef typename DIMENSIONS::state_vector_t state_vector_t;
53  typedef typename DIMENSIONS::control_vector_t control_vector_t;
54 
55  ConstraintsBase(){};
56  virtual ~ConstraintsBase() {};
57 
58  virtual Eigen::VectorXd evalConstraintsFct(const state_vector_t& x, const control_vector_t& u) {
59  return (Eigen::VectorXd::Zero(g_size));
60  }
61  virtual Eigen::VectorXd evalConstraintsFctDerivatives(const state_vector_t& x, const control_vector_t& u) {
62  return (Eigen::VectorXd::Zero(nnz_jac_));
63  }
64 
65  Eigen::VectorXd getConstraintsLowerBound() {return g_low;}
66  Eigen::VectorXd getConstraintsUpperBound() {return g_up;}
67 
68  void setSize(const int & size) {g_size = size;}
69  void setConstraintsLowerBound(const Eigen::VectorXd & g_lb_candidate);
70  void setConstraintsUpperBound(const Eigen::VectorXd & g_ub_candidate);
71 
72  int getNumConstraints() {return g_size;}
73 
78  int getNnzJac() {return nnz_jac_;}
79 
80  Eigen::VectorXi getSparseRow() {return iRow_;}
81  Eigen::VectorXi getSparseCol() {return jCol_;}
82 
83 private:
84  int g_size = 0; /* constraint size */
85  Eigen::VectorXd g_low;
86  Eigen::VectorXd g_up;
87 
88 protected:
89  int nnz_jac_ = 0; /* jacobian size */
90  Eigen::VectorXi iRow_ , jCol_; /* sparsity indexes */
91 };
92 
93 template <class DIMENSIONS>
94 void ConstraintsBase<DIMENSIONS>::setConstraintsLowerBound(const Eigen::VectorXd & g_lb_candidate) {
95 
96  int candidate_size = g_lb_candidate.size();
97 
98  if (candidate_size != g_size) {
99  std::cout << "ERROR : Lower bound vector size " << std::endl;
100  std::exit(EXIT_FAILURE);
101  } else {
102  g_low = g_lb_candidate;
103  }
104 }
105 
106 template <class DIMENSIONS>
107 void ConstraintsBase<DIMENSIONS>::setConstraintsUpperBound(const Eigen::VectorXd & g_ub_candidate) {
108 
109  int candidate_size = g_ub_candidate.size();
110 
111  if (candidate_size != g_size) {
112  std::cout << "ERROR : Lower bound vector size " << std::endl;
113  std::exit(EXIT_FAILURE);
114  } else {
115  g_up = g_ub_candidate;
116  }
117 }
118 }
119 }
120 #endif /* _CONSTRAINTSBASE_H */
Base class for TO constraints.
Definition: ConstraintsBase.hpp:46
int getNnzJac()
Access the number of non-zero elements of the Jacobian of this constraint.
Definition: ConstraintsBase.hpp:78