robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
time_discretization.hpp
Go to the documentation of this file.
1#ifndef ROBOTOC_TIME_DISCRETIZATION_HPP_
2#define ROBOTOC_TIME_DISCRETIZATION_HPP_
3
4#include <vector>
5#include <memory>
6#include <limits>
7#include <cmath>
8#include <iostream>
9
12
13
14namespace robotoc {
15
21public:
31 TimeDiscretization(const double T, const int N,
32 const int reserved_num_discrete_events=0);
33
38
43
48
53
58
62 TimeDiscretization& operator=(TimeDiscretization&&) noexcept = default;
63
67 int N() const {
68 return N_;
69 }
70
75 inline int size() const {
76 return num_grids_ + 1;
77 }
78
84 inline const GridInfo& grid(const int i) const {
85 assert(i >= 0);
86 assert(i < size());
87 return grid_[i];
88 }
89
95 inline const GridInfo& operator[] (const int i) const {
96 assert(i >= 0);
97 assert(i < size());
98 return grid_[i];
99 }
100
105 inline const GridInfo& front() const {
106 return grid_[0];
107 }
108
113 inline const GridInfo& back() const {
114 return grid_[size()-1];
115 }
116
121 double maxTimeStep() const {
122 double max_dt = grid_[0].dt;
123 for (int i=0; i<num_grids_; ++i) {
124 max_dt = std::max(grid_[i].dt, max_dt);
125 }
126 return max_dt;
127 }
128
134 void reserve(const int reserved_num_discrete_events);
135
140
147 void discretize(const std::shared_ptr<ContactSequence>& contact_sequence, const double t);
148
155 void correctTimeSteps(const std::shared_ptr<ContactSequence>& contact_sequence, const double t);
156
160 void disp(std::ostream& os) const;
161
162 friend std::ostream& operator<<(std::ostream& os,
163 const TimeDiscretization& discretization);
164
165private:
166 double T_, max_dt_, eps_;
167 int N_, num_grids_, reserved_num_discrete_events_;
168 std::vector<GridInfo> grid_;
169 std::vector<bool> sto_event_, sto_phase_;
170};
171
172} // namespace robotoc
173
174#endif // ROBOTOC_TIME_DISCRETIZATION_HPP_
Time discretization of the optimal control problem.
Definition: time_discretization.hpp:20
TimeDiscretization(const TimeDiscretization &)=default
Default copy constructor.
int size() const
Returns the number of grids.
Definition: time_discretization.hpp:75
void disp(std::ostream &os) const
Displays the time discretization onto a ostream.
TimeDiscretization(const double T, const int N, const int reserved_num_discrete_events=0)
Constructor.
const GridInfo & grid(const int i) const
Returns the grid info of the specified stage.
Definition: time_discretization.hpp:84
TimeDiscretization(TimeDiscretization &&) noexcept=default
Default move constructor.
const GridInfo & operator[](const int i) const
Returns the grid info of the specified stage.
Definition: time_discretization.hpp:95
TimeDiscretization()
Default constructor.
double maxTimeStep() const
Gets the maximum time step of the discretization.
Definition: time_discretization.hpp:121
const GridInfo & back() const
Returns the grid info of the terminal stage.
Definition: time_discretization.hpp:113
int reservedNumDiscreteEvents() const
TimeDiscretization & operator=(const TimeDiscretization &)=default
Default copy assign operator.
void correctTimeSteps(const std::shared_ptr< ContactSequence > &contact_sequence, const double t)
Discretizes the finite horizon taking into account the discrete events.
void reserve(const int reserved_num_discrete_events)
Reserve the discrete-event data.
void discretize(const std::shared_ptr< ContactSequence > &contact_sequence, const double t)
Discretizes the finite horizon taking into account the discrete events.
friend std::ostream & operator<<(std::ostream &os, const TimeDiscretization &discretization)
const GridInfo & front() const
Returns the grid info of the initial stage.
Definition: time_discretization.hpp:105
~TimeDiscretization()=default
Default destructor.
int N() const
Definition: time_discretization.hpp:67
Definition: constraint_component_base.hpp:17
Grid information.
Definition: grid_info.hpp:24