67 "Structure of the solution in ControlProblem class is not properly initialized.");
85 solution_guess.
initialize(sol_structure_, old_solution);
125 template<
int t_num_vars,
133 const std::vector<t_DMatrix> &D,
134 const std::vector<t_EMatrix> &E,
142 "Wrong size of Ux matrix.")
143 HUMOTO_ASSERT(D.size() == E.size(),
"Mismatching number of D and E matrices.")
144 HUMOTO_ASSERT(E.size() ==
static_cast<std::size_t
>(N),
"Wrong number of matrices.")
147 std::ptrdiff_t num_controls = 0;
148 std::vector<std::ptrdiff_t> control_offsets;
154 Ou.resize(Uu.size());
155 control_offsets.resize(Uu.size());
156 for (std::size_t i = 0; i < Uu.size(); ++i)
158 control_offsets[i] = num_controls;
159 num_controls += Uu[i].getBlockColsNum();
164 for (std::size_t i = 0; i < Uu.size(); ++i)
166 Ou[i](N-1, N-1) = E[0].block( 0,
169 Uu[i].getBlockColsNum());
172 for (std::ptrdiff_t i = 1; i < N; ++i)
174 Ox(i, 0).noalias() = D[i] * Ux(i-1, 0);
176 for (std::size_t j = 0; j < Uu.size(); ++j)
178 Ou[j].row(i, 0, i).noalias() = D[i] * Uu[j].row(i-1, 0, i);
179 Ou[j](i, i) = E[i].block( 0,
182 Uu[j].getBlockColsNum());
207 template<
typename t_DMatrix,
214 const Eigen::MatrixXd &Ux,
215 const Eigen::MatrixXd &Uu)
217 size_t Nu = E.cols();
218 size_t Nx = D.cols();
219 size_t Ny = D.rows();
220 size_t N = Ux.rows()/Nx;
222 "Mismatching sizes between Ux and D matrix.")
224 "Mismatching sizes between Ux and D matrix.")
226 "Mismatching sizes between Uu and E matrix.")
228 "Mismatching sizes between Uu and E matrix.")
231 Ox.block(0, 0, Ny, Nx) = D;
233 Ou.setZero(N*Ny, N*Nu);
234 Ou.block(0, 0, Ny, Nu) = E;
236 for (
size_t i = 1; i < N; ++i)
238 Ox.block(i*Ny, 0, Ny, Nx).noalias() =
239 D * Ux.block((i-1)*Nx, 0, Nx, Nx);
241 Ou.middleRows(i*Ny, Ny).noalias() = D * Uu.middleRows((i-1)*Nx, Nx);
242 Ou.block(i*Ny, i*Nu, Ny, Nu) = E;
263 template<
int t_num_vars,
271 const std::vector<t_DMatrix> &D,
272 const std::vector<t_EMatrix> &E,
279 "Wrong size of Ux matrix.")
282 "Mismatching size of input matrices.")
283 HUMOTO_ASSERT(D.size() == E.size(),
"Mismatching number of D and E matrices.")
284 HUMOTO_ASSERT(E.size() ==
static_cast<std::size_t
>(N),
"Wrong number of matrices.")
293 for (std::ptrdiff_t i = 1; i < N; ++i)
295 Ox(i, 0).noalias() = D[i] * Ux(i-1, 0);
297 Ou.
row(i, 0, i).noalias() = D[i] * Uu.
row(i-1, 0, i);
316 template<
int t_num_vars,
324 const std::vector<t_AMatrix> &A,
325 const std::vector<t_BMatrix> &B)
327 HUMOTO_ASSERT(A.size() == B.size(),
"Mismatching number of A and B matrices.")
330 std::ptrdiff_t N = A.size();
337 S(N-1, 0).setIdentity();
339 U(N-1, N-1) = B[N-1];
341 for(std::ptrdiff_t k=N-2; k>=0; --k)
345 for (std::ptrdiff_t i = k+1; i < N; ++i)
349 S(k, 0).setIdentity();
354 for (std::ptrdiff_t i = k+1; i < N; ++i)
356 U(i, k).noalias() = S(i, 0) * B[k];
377 template<
typename t_AMatrix,
typename t_BMatrix>
381 const std::vector<t_AMatrix> &A,
382 const std::vector<t_BMatrix> &B)
384 HUMOTO_ASSERT(A.size() == B.size(),
"Mismatching number of A and B matrices.")
386 HUMOTO_ASSERT((A[0].rows() == B[0].rows()) && (A[0].cols() == B[0].rows()),
"Wrong size of matrices.");
389 int Ns = B[0].rows();
390 int Nu = B[0].cols();
393 S.resize(Ns * N, Ns);
394 U.resize(Ns*N, Nu*N);
399 S.block((N-1)*Ns, 0, Ns, Ns).setIdentity();
401 U.block((N-1)*Ns, (N-1)*Nu, Ns, Nu) = B[N-1];
403 for(
int k=N-2; k>=0; --k)
405 S.block((k+1)*Ns, 0, (N-k-1)*Ns, Ns) *= A[k+1];
406 S.block(k*Ns, 0, Ns, Ns).setIdentity();
408 U.block((k)*Ns, k*Nu, Ns, Nu) = B[k];
409 U.block((k+1)*Ns, k*Nu, (N-k-1)*Ns, Nu).noalias() = S.block((k+1)*Ns, 0, (N-k-1)*Ns, Ns) * B[k];
431 const std::size_t preview_horizon_len,
432 const Eigen::MatrixXd &A,
433 const Eigen::MatrixXd &B)
436 Eigen::MatrixXd M = A;
437 int num_rows_A = A.rows();
438 int num_cols_A = A.cols();
439 S.resize(num_rows_A*preview_horizon_len, num_cols_A);
440 S.block(0, 0 , num_rows_A, num_cols_A) = M;
442 for(std::size_t i=1; i<preview_horizon_len; ++i)
445 S.block(i*num_rows_A, 0 , num_rows_A, num_cols_A) = M;
449 int num_rows_B = B.rows();
450 int num_cols_B = B.cols();
451 Eigen::MatrixXd Ucol(num_rows_B*preview_horizon_len, num_cols_B);
453 S.block(0, 0 , num_rows_B*(preview_horizon_len-1), num_cols_A) * B;
454 U.resize(num_rows_B*preview_horizon_len, num_cols_B*preview_horizon_len);
456 for(std::size_t i=0; i<preview_horizon_len; ++i)
458 U.block(num_rows_B*i, num_cols_B*i, num_rows_B*(preview_horizon_len-i), num_cols_B) = Ucol.block(0, 0, num_rows_B*(preview_horizon_len-i), num_cols_B);
Abstract base class (for control problems)
Status of control problem.
static void condenseOutput(etools::GenericBlockMatrix< t_num_outputs, t_num_vars > &Ox, etools::LeftLowerTriangularBlockMatrix< t_num_outputs, t_num_controls > &Ou, const std::vector< t_DMatrix > &D, const std::vector< t_EMatrix > &E, const etools::GenericBlockMatrix< t_num_vars, t_num_vars > &Ux, const etools::LeftLowerTriangularBlockMatrix< t_num_vars, t_num_controls > &Uu)
Condense output of the system.
#define HUMOTO_ASSERT(condition, message)
~MPC()
Protected destructor: prevent destruction of the child classes through a base pointer.
Analog of 'sol_structure' struct in Octave code. [determine_solution_structure.m].
Container of the solution.
Represents log entry name.
static void condense(etools::GenericBlockMatrix< t_num_vars, t_num_vars > &S, etools::BlockMatrix< t_num_vars, t_num_controls, t_bmatrix_sparsity_type > &U, const std::vector< t_AMatrix > &A, const std::vector< t_BMatrix > &B)
Create the condensed matrices (S,U) of a Model Predictive Control problem such that X = S*x0 + U*u...
bool isNonEmpty() const
Checks if the structure is empty or not.
virtual void guessSolution(Solution &solution_guess, const Solution &old_solution) const
Guess solution.
void initSolutionStructure(humoto::Solution &solution) const
Initialize structure of the given solution based on the internally stored solution structure...
~ControlProblem()
Protected destructor: prevent destruction of the child classes through a base pointer.
static void condense(Eigen::MatrixXd &S, Eigen::MatrixXd &U, const std::vector< t_AMatrix > &A, const std::vector< t_BMatrix > &B)
Create the condensed matrices (S,U) of a Model Predictive Control problem such that X = S*x0 + U*u...
Threaded logger: any data sent to this logger is wrapped in a message and pushed to a queue...
void initialize(const SolutionStructure &sol_structure)
Initialize the solution vector.
SolutionStructure sol_structure_
static void condenseOutput(Eigen::MatrixXd &Ox, Eigen::MatrixXd &Ou, const t_DMatrix &D, const t_EMatrix &E, const Eigen::MatrixXd &Ux, const Eigen::MatrixXd &Uu)
Condense output of the system.
The root namespace of HuMoTo.
static void condenseOutput(etools::GenericBlockMatrix< t_num_outputs, t_num_vars > &Ox, std::vector< etools::LeftLowerTriangularBlockMatrix< t_num_outputs, etools::MatrixBlockSizeType::DYNAMIC > > &Ou, const std::vector< t_DMatrix > &D, const std::vector< t_EMatrix > &E, const etools::GenericBlockMatrix< t_num_vars, t_num_vars > &Ux, const std::vector< etools::LeftLowerTriangularBlockMatrix< t_num_vars, etools::MatrixBlockSizeType::DYNAMIC > > &Uu)
Condense output of the system.
static void condenseTimeInvariant(Eigen::MatrixXd &S, Eigen::MatrixXd &U, const std::size_t preview_horizon_len, const Eigen::MatrixXd &A, const Eigen::MatrixXd &B)
Create the condensed matrices (S,U) of a Time Invariant (constant A,B) Model Predictive Control probl...
Abstract base class for Model Predictive Control problems.