DirectTrajectoryOptimization  v0.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
nonlinear_program.hpp
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 NONLINEARPROGRAM_HPP_
32 #define NONLINEARPROGRAM_HPP_
33 
34 #include <Eigen/Dense>
35 
36 namespace DirectTrajectoryOptimization {
37 
45 
46 public:
47 
48  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
49 
50  nonlinearprogram(bool v=false);
51  ~nonlinearprogram(){ };
52 
53  void SetVariablesSize(const int & n_vars);
54  void SetConstraintsSize(const int & n_const);
55  void SetVariablesBounds(const Eigen::VectorXd & lb, const Eigen::VectorXd & ub);
56  void SetConstraintsBounds(const Eigen::VectorXd & lb, const Eigen::VectorXd & ub);
57 
58  void SetGSize(const int & g_size);
59  void setGcostSize(const int & gcost_size);
60 
61  inline int GetNumVars() {
62  return num_vars;
63  }
64  inline int GetNumF() {
65  return num_F;
66  }
67  inline int GetDimG() {
68  return lenG;
69  }
70  inline int GetDimGCost() {
71  return lenG_cost;
72  }
73  double* GetXlb_p() {
74  return x_lb.data();
75  }
76  double* GetXub_p() {
77  return x_ub.data();
78  }
79  double* GetFlb_p() {
80  return Flb.data();
81  }
82  double* GetFub_p() {
83  return Fub.data();
84  }
85  int* GetiGfun_p() {
86  return iGfun.data();
87  }
88  int* GetjGvar_p() {
89  return jGvar.data();
90  }
91 
92  // I think I can delete these
93  Eigen::VectorXd GetFlb() {
94  return Flb;
95  }
96  Eigen::VectorXd GetFub() {
97  return Fub;
98  }
99  Eigen::VectorXi GetiGfun() {
100  return iGfun;
101  }
102  Eigen::VectorXi GetjGvar() {
103  return jGvar;
104  }
105  Eigen::VectorXi GetjGvarCost() {
106  return jG_cost;
107  }
108  Eigen::VectorXd GetDecisionVariables() {
109  return x_decision_variables;
110  }
111 
112  /* size of problem */
113  int num_vars = 0;
114  int num_F = 0;
115  int lenG = 0;
116  int lenG_cost = 0;
117 
118  // constraints vector value/bounds
119  Eigen::VectorXd F;
120  Eigen::VectorXd Flb;
121  Eigen::VectorXd Fub;
122 
123  // constraint Jacobian matrix and nnz element indices
124  Eigen::VectorXd G;
125  Eigen::VectorXi iGfun;
126  Eigen::VectorXi jGvar;
127 
128  Eigen::VectorXd G_cost;
129  Eigen::VectorXi jG_cost;
130 
131  // Optimization vector bounds
132  Eigen::VectorXd x_lb;
133  Eigen::VectorXd x_ub;
134 
135  // Decision variables
136  Eigen::VectorXd x_decision_variables;
137 
138  bool nlp_verbosity;
139 };
140 
141 nonlinearprogram::nonlinearprogram(bool verb /*= false */):nlp_verbosity(verb) {
142 
143  //during construction
144  std::cout << "dummy" << std::endl;
145 
146 }
147 
148 void nonlinearprogram::SetVariablesSize(const int & n_vars) {
149 
150  num_vars = n_vars;
151  x_lb.resize(n_vars);
152  x_ub.resize(n_vars);
153 
154  if(nlp_verbosity) {
155  std::cout << "[VERBOSE] num_vars : " << num_vars << std::endl;
156  }
157 
158 }
159 
160 void nonlinearprogram::SetConstraintsSize(const int & n_const) {
161 
162  num_F = n_const;
163  F.resize(n_const);
164  Flb.resize(n_const);
165  Fub.resize(n_const);
166 
167  if(nlp_verbosity) {
168  std::cout << " [VERBOSE] num_F : " << num_F << std::endl;
169  }
170 }
171 
172 void nonlinearprogram::SetVariablesBounds(const Eigen::VectorXd & lb , const Eigen::VectorXd &ub) {
173 
174  x_lb = lb;
175  x_ub = ub;
176 
177  if(nlp_verbosity) {
178  std::cout << " [VERBOSE] xlb : " << x_lb.transpose() << std::endl;
179  std::cout << " [VERBOSE] xup : " << x_ub.transpose() << std::endl;
180  }
181 }
182 
183 void nonlinearprogram::SetConstraintsBounds(const Eigen::VectorXd & lb, const Eigen::VectorXd & ub) {
184 
185  Flb = lb;
186  Fub = ub;
187 
188  if(nlp_verbosity) {
189  std::cout << " [VERBOSE] Fub : " << Fub.transpose() << std::endl;
190  std::cout << " [VERBOSE] Flb : " << Flb.transpose() << std::endl;
191  }
192 }
193 
194 void nonlinearprogram::SetGSize(const int & g_size) {
195 
196  lenG = g_size;
197 
198  G.resize(g_size);
199  iGfun.resize(g_size);
200  jGvar.resize(lenG);
201 
202 }
203 
204 void nonlinearprogram::setGcostSize(const int & gcost_size) {
205 
206  lenG_cost = gcost_size;
207 
208  G_cost.resize(gcost_size);
209  jG_cost.resize(gcost_size);
210 }
211 
212 
213 }
214 #endif /* NONLINEARPROGRAM_HPP_ */
This class contains all the information related to the NLP.
Definition: nonlinear_program.hpp:44