40 if (Q.isDiagonal(1e-10))
return setWeightQ(Q.diagonal().asDiagonal());
74 if (R.isDiagonal(1e-10))
return setWeightR(R.diagonal().asDiagonal());
112 cost.noalias() = x_k.transpose() *
_Q_sqrt * x_k;
128 cost.noalias() = x_k.transpose() *
_Q_diag * x_k;
130 cost.noalias() = x_k.transpose() *
_Q * x_k;
136 cost.noalias() = xd.transpose() *
_Q_diag * xd;
138 cost.noalias() = xd.transpose() *
_Q * xd;
155 cost.noalias() =
_R_sqrt * u_k;
163 cost.noalias() = ud.transpose() *
_R_sqrt * ud;
171 cost.noalias() = u_k.transpose() *
_R_diag * u_k;
173 cost.noalias() = u_k.transpose() *
_R * u_k;
179 cost.noalias() = ud.transpose() *
_R_diag * ud;
181 cost.noalias() = ud.transpose() *
_R * ud;
190 assert(cost.size() == 1);
197 cost[0] += x_k.transpose() *
_Q_diag * x_k;
199 cost[0] += x_k.transpose() *
_Q * x_k;
205 cost[0] += xd.transpose() *
_Q_diag * xd;
207 cost[0] += xd.transpose() *
_Q * xd;
212 cost[0] += u_k.transpose() *
_R_diag * u_k;
214 cost[0] += u_k.transpose() *
_R * u_k;
220 cost[0] += ud.transpose() *
_R_diag * ud;
222 cost[0] += ud.transpose() *
_R * ud;
235 *issues <<
"QuadraticFormCost: Diagonal matrix dimension of Q (" <<
_Q_diag.
diagonal().size()
236 <<
") does not match state vector dimension (" << state_dim <<
"); Please specify diagonal elements only." << std::endl;
242 if (
_Q.rows() != state_dim ||
_Q.cols() != state_dim)
245 *issues <<
"QuadraticFormCost: Matrix dimension of Q (" <<
_Q.rows() <<
"x" <<
_Q.cols()
246 <<
") does not match state vector dimension (" << state_dim <<
"); Please specify " << (state_dim * state_dim)
247 <<
" elements (Row-Major)." << std::endl;
257 *issues <<
"QuadraticFormCost: diagonal matrix dimension of R (" <<
_R_diag.
diagonal().size()
258 <<
") does not match control input vector dimension (" << control_dim <<
"); Please specify diagonal elements only." 265 if (
_R.rows() != control_dim ||
_R.cols() != control_dim)
268 *issues <<
"QuadraticFormCost: Matrix dimension of R (" <<
_R.rows() <<
"x" <<
_R.cols()
269 <<
") does not match control input vector dimension (" << control_dim <<
"); Please specify " << (control_dim * control_dim)
270 <<
" elements (Row-Major)." << std::endl;
294 #ifdef MESSAGE_SUPPORT 295 bool QuadraticFormCost::fromMessage(
const messages::QuadraticFormCost& message, std::stringstream* issues)
297 const messages::QuadraticFormCost& msg = message;
307 *issues <<
"QuadraticStateCost: cannot set diagonal weight matrix Q.\n";
315 if (p * p != msg.q_size())
317 *issues <<
"QuadraticStateCost: weight matrix Q is not square.\n";
326 *issues <<
"QuadraticStateCost: weight matrix Q is not positive definite.\n";
339 *issues <<
"QuadraticFormCost: cannot set diagonal weight matrix R.\n";
347 if (q * q != msg.r_size())
349 *issues <<
"QuadraticFormCost: weight matrix R is not square.\n";
358 *issues <<
"QuadraticFormCost: weight matrix R is not positive definite.\n";
373 void QuadraticFormCost::toMessage(messages::QuadraticFormCost& message)
const 375 messages::QuadraticFormCost* msg = &message;
381 msg->mutable_q()->Resize(Qdiag.size(), 0);
384 msg->set_q_diagonal_only(
true);
388 Eigen::MatrixXd Q =
_Q;
389 msg->mutable_q()->Resize(Q.rows() * Q.cols(), 0);
392 msg->set_q_diagonal_only(
false);
399 msg->mutable_r()->Resize(Rdiag.size(), 0);
402 msg->set_r_diagonal_only(
true);
406 Eigen::MatrixXd R =
_R;
407 msg->mutable_r()->Resize(R.rows() * R.cols(), 0);
410 msg->set_r_diagonal_only(
false);
EIGEN_DEVICE_FUNC const DiagonalVectorType & diagonal() const
A matrix or vector expression mapping an existing array of data.
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
bool is_square(const Eigen::MatrixBase< Derived > &matrix)
Determine if a given matrix is square.
virtual const OutputVector & getReferenceCached(int k) const =0
Standard Cholesky decomposition (LL^T) of a matrix and associated features.
EIGEN_DEVICE_FUNC const Scalar & q
ComputationInfo info() const
Reports whether previous computation was successful.
A matrix or vector expression mapping an existing expression.
Traits::MatrixU matrixU() const
EIGEN_DEVICE_FUNC DenseMatrixType toDenseMatrix() const
The matrix class, also used for vectors and row-vectors.