Converts a constraint to a cost by weighing the quadratic violations. More...
#include <soft_constraint.h>
Public Types | |
using | ConstraintPtr = Component::Ptr |
Public Types inherited from ifopt::Component | |
typedef Eigen::SparseMatrix< double, Eigen::RowMajor > | Jacobian |
typedef std::shared_ptr< Component > | Ptr |
typedef std::vector< Bounds > | VecBound |
typedef Eigen::VectorXd | VectorXd |
Public Member Functions | |
SoftConstraint (const ConstraintPtr &constraint) | |
Creates a soft constraint (=cost) from a hard constraint. More... | |
virtual | ~SoftConstraint ()=default |
Public Member Functions inherited from ifopt::Component | |
Component (int num_rows, const std::string &name) | |
std::string | GetName () const |
int | GetRows () const |
virtual void | Print (double tolerance, int &index_start) const |
void | SetRows (int num_rows) |
virtual | ~Component ()=default |
Private Member Functions | |
VecBound | GetBounds () const final |
Jacobian | GetJacobian () const override |
The row-vector of derivatives of the cost term. More... | |
VectorXd | GetValues () const override |
average value of each upper and lower bound. More... | |
void | SetVariables (const VectorXd &x) final |
Private Attributes | |
VectorXd | b_ |
ConstraintPtr | constraint_ |
VectorXd | W_ |
weights how each constraint violation contributes to the cost. More... | |
Additional Inherited Members | |
Static Public Attributes inherited from ifopt::Component | |
static const int | kSpecifyLater |
Converts a constraint to a cost by weighing the quadratic violations.
Let constraint g(x) R^m with upper bound b_u and lower bound b_l. Let
g'(x) = g(x) - 0.5(b_u+b_l) = g(x) - b
And it's derivative
dg'(x)/dx = J(x).
Define a cost as
c(x) = 0.5 * g'^T * W * g', where W = diag(w1,...,wm).
Then the gradient of the cost is defined as:
dc(x)/dx = (g'(x)^T * W * J)^T = J^T * W * (g(x)-b).
Definition at line 59 of file soft_constraint.h.
using towr::SoftConstraint::ConstraintPtr = Component::Ptr |
Definition at line 61 of file soft_constraint.h.
towr::SoftConstraint::SoftConstraint | ( | const ConstraintPtr & | constraint | ) |
Creates a soft constraint (=cost) from a hard constraint.
constraint | The fully initialized constraint. |
Weights are set to identity, so each constraint violation contributes equally to the cost.
Definition at line 34 of file soft_constraint.cc.
|
virtualdefault |
|
inlinefinalprivatevirtual |
Implements ifopt::Component.
Definition at line 93 of file soft_constraint.h.
|
overrideprivatevirtual |
The row-vector of derivatives of the cost term.
dc(x)/dx = J^T * W * (g-b)
Implements ifopt::Component.
Definition at line 61 of file soft_constraint.cc.
|
overrideprivatevirtual |
average value of each upper and lower bound.
The quadratic constraint violation transformed to a cost.
c(x) = 0.5 * (g-b)^T * W * (g-b)
Implements ifopt::Component.
Definition at line 53 of file soft_constraint.cc.
|
inlinefinalprivatevirtual |
Implements ifopt::Component.
Definition at line 94 of file soft_constraint.h.
|
private |
Definition at line 76 of file soft_constraint.h.
|
private |
Definition at line 74 of file soft_constraint.h.
|
private |
weights how each constraint violation contributes to the cost.
Definition at line 75 of file soft_constraint.h.