time_discretization_constraint.cc
Go to the documentation of this file.
1 /******************************************************************************
2 Copyright (c) 2018, 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 
31 
32 #include <cmath>
33 
34 namespace towr {
35 
36 
38  std::string name)
39  :ConstraintSet(kSpecifyLater, name)
40 {
41  double t = 0.0;
42  dts_ = {t};
43 
44  for (int i=0; i<floor(T/dt); ++i) {
45  t += dt;
46  dts_.push_back(t);
47  }
48 
49  dts_.push_back(T); // also ensure constraints at very last node/time.
50 }
51 
53  std::string name)
54  :ConstraintSet(kSpecifyLater, name) // just placeholder
55 {
56  dts_ = times;
57 }
58 
59 int
61 {
62  return dts_.size();
63 }
64 
67 {
68  VectorXd g = VectorXd::Zero(GetRows());
69 
70  int k = 0;
71  for (double t : dts_)
72  UpdateConstraintAtInstance(t, k++, g);
73 
74  return g;
75 }
76 
77 TimeDiscretizationConstraint::VecBound
79 {
80  VecBound bounds(GetRows());
81 
82  int k = 0;
83  for (double t : dts_)
84  UpdateBoundsAtInstance(t, k++, bounds);
85 
86  return bounds;
87 }
88 
89 void
91  Jacobian& jac) const
92 {
93  int k = 0;
94  for (double t : dts_)
95  UpdateJacobianAtInstance(t, k++, var_set, jac);
96 }
97 
98 } /* namespace towr */
99 
100 
virtual void UpdateBoundsAtInstance(double t, int k, VecBound &b) const =0
Sets upper/lower bound a specific time t, corresponding to node k.
void FillJacobianBlock(std::string var_set, Jacobian &) const override
TimeDiscretizationConstraint(double T, double dt, std::string constraint_name)
Constructs a constraint for ifopt.
Eigen::VectorXd GetValues() const override
virtual void UpdateJacobianAtInstance(double t, int k, std::string var_set, Jacobian &jac) const =0
Sets Jacobian rows at a specific time t, corresponding to node k.
Eigen::VectorXd VectorXd
VecTimes dts_
times at which the constraint is evaluated.
virtual void UpdateConstraintAtInstance(double t, int k, VectorXd &g) const =0
Sets the constraint value a specific time t, corresponding to node k.


towr_core
Author(s): Alexander W. Winkler
autogenerated on Sat Apr 7 2018 02:15:57