Drake
MobyLCPSolver< T > Class Template Referencefinal

## Detailed Description

### template<class T> class drake::solvers::MobyLCPSolver< T >

A class for solving Linear Complementarity Problems (LCPs).

Solving a LCP requires finding a solution to the problem:

Mz + q = w
z ≥ 0
w ≥ 0
zᵀw = 0


(where M ∈ ℝⁿˣⁿ and q ∈ ℝⁿ are problem inputs and z ∈ ℝⁿ and w ∈ ℝⁿ are unknown vectors) or correctly reporting that such a solution does not exist. In spite of their linear structure, solving LCPs is NP-Hard [Cottle 1992]. However, some LCPs are significantly easier to solve. For instance, it can be seen that the LCP is solvable in worst-case polynomial time for the case of symmetric positive-semi-definite M by formulating it as the following convex quadratic program:

minimize:   f(z) = zᵀw = zᵀ(Mz + q)
subject to: z ≥ 0
Mz + q ≥ 0


Note that this quadratic program's (QP) objective function at the minimum z cannot be less than zero, and the LCP is only solved if the objective function at the minimum is equal to zero. Since the seminal result of Karmarkar, it has been known that convex QPs are solvable in polynomial time [Karmarkar 1984].

The difficulty of solving an LCP is characterized by the properties of its particular matrix, namely the class of matrices it belongs to. Classes include, for example, Q, Q₀, P, P₀, copositive, and Z matrices. [Cottle 1992] and Murty 1998 describe relevant matrix classes in more detail.

• [Cottle 1992] R. Cottle, J.-S. Pang, and R. Stone. The Linear Complementarity Problem. Academic Press, 1992.
• [Karmarkar 1984] N. Karmarkar. A New Polynomial-Time Algorithm for Linear Programming. Combinatorica, 4(4), pp. 373-395.
• [Murty 1988] K. Murty. Linear Complementarity, Linear and Nonlinear Programming. Heldermann Verlag, 1988.

#include <drake/solvers/moby_lcp_solver.h>

## Public Member Functions

MobyLCPSolver ()

~MobyLCPSolver () final

void SetLoggingEnabled (bool enabled)

bool SolveLcpFast (const MatrixX< T > &M, const VectorX< T > &q, VectorX< T > *z, const T &zero_tol=T(-1)) const
Fast pivoting algorithm for LCPs of the form M = PAPᵀ, q = Pb, where b ∈ ℝᵐ, P ∈ ℝⁿˣᵐ, and A ∈ ℝᵐˣᵐ (where A is positive definite). More...

bool SolveLcpFastRegularized (const MatrixX< T > &M, const VectorX< T > &q, VectorX< T > *z, int min_exp=-20, unsigned step_exp=4, int max_exp=20, const T &zero_tol=T(-1)) const
Regularized version of the fast pivoting algorithm for LCPs of the form M = PAPᵀ, q = Pb, where b ∈ ℝᵐ, P ∈ ℝⁿˣᵐ, and A ∈ ℝᵐˣᵐ (where A is positive definite). More...

bool SolveLcpLemke (const MatrixX< T > &M, const VectorX< T > &q, VectorX< T > *z, const T &piv_tol=T(-1), const T &zero_tol=T(-1)) const
Lemke's Algorithm for solving LCPs in the matrix class E, which contains all strictly semimonotone matrices, all P-matrices, and all strictly copositive matrices. More...

bool SolveLcpLemkeRegularized (const MatrixX< T > &M, const VectorX< T > &q, VectorX< T > *z, int min_exp=-20, unsigned step_exp=1, int max_exp=1, const T &piv_tol=T(-1), const T &zero_tol=T(-1)) const
Lemke's Algorithm for solving LCPs in the matrix class E, which contains all strictly semimonotone matrices, all P-matrices, and all strictly copositive matrices. More...

int get_num_pivots () const
Returns the number of pivoting operations made by the last LCP solve. More...

void reset_num_pivots ()
Resets the number of pivoting operations made by the last LCP solver to zero. More...

MathematicalProgramResult Solve (const MathematicalProgram &prog, const std::optional< Eigen::VectorXd > &initial_guess=std::nullopt, const std::optional< SolverOptions > &solver_options=std::nullopt) const
Like SolverInterface::Solve(), but the result is a return value instead of an output argument. More...

void Solve (const MathematicalProgram &, const std::optional< Eigen::VectorXd > &, const std::optional< SolverOptions > &, MathematicalProgramResult *) const override

Does not allow copy, move, or assignment
MobyLCPSolver (const MobyLCPSolver &)=delete

MobyLCPSolveroperator= (const MobyLCPSolver &)=delete

MobyLCPSolver (MobyLCPSolver &&)=delete

MobyLCPSolveroperator= (MobyLCPSolver &&)=delete

Public Member Functions inherited from SolverBase
~SolverBase () override

MathematicalProgramResult Solve (const MathematicalProgram &prog, const std::optional< Eigen::VectorXd > &initial_guess=std::nullopt, const std::optional< SolverOptions > &solver_options=std::nullopt) const
Like SolverInterface::Solve(), but the result is a return value instead of an output argument. More...

void Solve (const MathematicalProgram &, const std::optional< Eigen::VectorXd > &, const std::optional< SolverOptions > &, MathematicalProgramResult *) const override
Solves an optimization program with optional initial guess and solver options. More...

bool available () const override
Returns true iff support for this solver has been compiled into Drake. More...

bool enabled () const override
Returns true iff this solver is properly configured for use at runtime. More...

SolverId solver_id () const override
Returns the identifier of this solver. More...

bool AreProgramAttributesSatisfied (const MathematicalProgram &) const override
Returns true iff the program's attributes are compatible with this solver's capabilities. More...

std::string ExplainUnsatisfiedProgramAttributes (const MathematicalProgram &) const override
Describes the reasons (if any) why the program is incompatible with this solver's capabilities. More...

SolverBase (const SolverBase &)=delete

SolverBaseoperator= (const SolverBase &)=delete

SolverBase (SolverBase &&)=delete

SolverBaseoperator= (SolverBase &&)=delete

Public Member Functions inherited from SolverInterface
virtual ~SolverInterface ()

SolverInterface (const SolverInterface &)=delete

SolverInterfaceoperator= (const SolverInterface &)=delete

SolverInterface (SolverInterface &&)=delete

SolverInterfaceoperator= (SolverInterface &&)=delete

## Static Public Member Functions

template<class U >
static U ComputeZeroTolerance (const MatrixX< U > &M)
Calculates the zero tolerance that the solver would compute if the user does not specify a tolerance. More...

Static versions of the instance methods with similar names.
static SolverId id ()

static bool is_available ()

static bool is_enabled ()

static bool ProgramAttributesSatisfied (const MathematicalProgram &)

Protected Member Functions inherited from SolverBase
SolverBase (std::function< SolverId()> id, std::function< bool()> available, std::function< bool()> enabled, std::function< bool(const MathematicalProgram &)> are_satisfied, std::function< std::string(const MathematicalProgram &)> explain_unsatisfied=nullptr)
Constructs a SolverBase with the given default implementations of the solver_id(), available(), enabled(), AreProgramAttributesSatisfied(), and ExplainUnsatisfiedProgramAttributes() methods. More...

Protected Member Functions inherited from SolverInterface
SolverInterface ()

## ◆ MobyLCPSolver() [1/3]

 MobyLCPSolver ( const MobyLCPSolver< T > & )
delete

## ◆ MobyLCPSolver() [2/3]

 MobyLCPSolver ( MobyLCPSolver< T > && )
delete

## ◆ MobyLCPSolver() [3/3]

 MobyLCPSolver ( )

## ◆ ~MobyLCPSolver()

 ~MobyLCPSolver ( )
final

## ◆ ComputeZeroTolerance()

 static U ComputeZeroTolerance ( const MatrixX< U > & M )
static

Calculates the zero tolerance that the solver would compute if the user does not specify a tolerance.

## ◆ get_num_pivots()

 int get_num_pivots ( ) const

Returns the number of pivoting operations made by the last LCP solve.

## ◆ id()

 static SolverId id ( )
static

## ◆ is_available()

 static bool is_available ( )
static

## ◆ is_enabled()

 static bool is_enabled ( )
static

## ◆ operator=() [1/2]

 MobyLCPSolver& operator= ( const MobyLCPSolver< T > & )
delete

## ◆ operator=() [2/2]

 MobyLCPSolver& operator= ( MobyLCPSolver< T > && )
delete

## ◆ ProgramAttributesSatisfied()

 static bool ProgramAttributesSatisfied ( const MathematicalProgram & )
static

## ◆ reset_num_pivots()

 void reset_num_pivots ( )

Resets the number of pivoting operations made by the last LCP solver to zero.

## ◆ SetLoggingEnabled()

 void SetLoggingEnabled ( bool enabled )

## ◆ Solve() [1/2]

Like SolverInterface::Solve(), but the result is a return value instead of an output argument.

## ◆ Solve() [2/2]

 void Solve
override

## ◆ SolveLcpFast()

 bool SolveLcpFast ( const MatrixX< T > & M, const VectorX< T > & q, VectorX< T > * z, const T & zero_tol = T(-1) ) const

Fast pivoting algorithm for LCPs of the form M = PAPᵀ, q = Pb, where b ∈ ℝᵐ, P ∈ ℝⁿˣᵐ, and A ∈ ℝᵐˣᵐ (where A is positive definite).

Therefore, q is in the range of P and M is positive semi-definite. An LCP of this form is also guaranteed to have a solution [Cottle 1992].

This particular implementation focuses on the case where the solution requires few nonzero nonbasic variables, meaning that few z variables need be nonzero to find a solution to Mz + q = w. This algorithm, which is based off of Dantzig's Principle Pivoting Method I [Cottle 1992] is described in [Drumwright 2015]. This algorithm is able to use "warm" starting- a solution to a "nearby" LCP can be used to find the solution to a given LCP more quickly.

Although this solver is theoretically guaranteed to give a solution to the LCPs described above, accumulated floating point error from pivoting operations could cause the solver to fail. Additionally, the solver can be applied with some success to problems outside of its guaranteed matrix class. For these reasons, the solver returns a flag indicating success/failure.

Parameters
 [in] M the LCP matrix. [in] q the LCP vector. [in,out] z the solution to the LCP on return (if the solver succeeds). If the length of z is equal to the length of q, the solver will attempt to use z's value as a starting solution. If the solver fails (returns false), z will be set to the zero vector. [in] zero_tol The tolerance for testing against zero. If the tolerance is negative (default) the solver will determine a generally reasonable tolerance.
Exceptions
 std::exception if M is non-square or M's dimensions do not equal q's dimension.
Returns
true if the solver succeeded and false otherwise.
• [Cottle 1992] R. Cottle, J.-S. Pang, and R. Stone. The Linear Complementarity Problem. Academic Press, 1992.
• [Drumwright 2015] E. Drumwright. Rapidly computable viscous friction and no-slip rigid contact models. arXiv: 1504.00719v1. 2015.

## ◆ SolveLcpFastRegularized()

 bool SolveLcpFastRegularized ( const MatrixX< T > & M, const VectorX< T > & q, VectorX< T > * z, int min_exp = -20, unsigned step_exp = 4, int max_exp = 20, const T & zero_tol = T(-1) ) const

Regularized version of the fast pivoting algorithm for LCPs of the form M = PAPᵀ, q = Pb, where b ∈ ℝᵐ, P ∈ ℝⁿˣᵐ, and A ∈ ℝᵐˣᵐ (where A is positive definite).

Therefore, q is in the range of P and M is positive semi-definite. Please see SolveLcpFast() for more documentation about the particular algorithm.

This implementation wraps that algorithm with a Tikhonov-type regularization approach. Specifically, this implementation repeatedly attempts to solve the LCP:

(M + Iα)z + q = w
z ≥ 0
w ≥ 0
zᵀw = 0


where I is the identity matrix and α ≪ 1, using geometrically increasing values of α, until the LCP is solved. Cottle et al. describe how, for sufficiently large α, the LCP will always be solvable [Cottle 1992], p. 493.

Although this solver is theoretically guaranteed to give a solution to the LCPs described above, accumulated floating point error from pivoting operations could cause the solver to fail. Additionally, the solver can be applied with some success to problems outside of its guaranteed matrix class. For these reasons, the solver returns a flag indicating success/failure.

Parameters
 [in] M the LCP matrix. [in] q the LCP vector. [in,out] z the solution to the LCP on return (if the solver succeeds). If the length of z is equal to the length of q, the solver will attempt to use z's value as a starting solution. [in] min_exp The minimum exponent for computing α over [10ᵝ, 10ᵞ] in steps of 10ᵟ, where β is the minimum exponent, γ is the maximum exponent, and δ is the stepping exponent. [in] step_exp The stepping exponent for computing α over [10ᵝ, 10ᵞ] in steps of 10ᵟ, where β is the minimum exponent, γ is the maximum exponent, and δ is the stepping exponent. [in] max_exp The maximum exponent for computing α over [10ᵝ, 10ᵞ] in steps of 10ᵟ, where β is the minimum exponent, γ is the maximum exponent, and δ is the stepping exponent. [in] zero_tol The tolerance for testing against zero. If the tolerance is negative (default) the solver will determine a generally reasonable tolerance.
Exceptions
 std::exception if M is non-square or M's dimensions do not equal q's dimension.
Returns
true if the solver succeeded and false if the solver did not find a solution for α = 10ᵞ.
SolveLcpFast()
• [Cottle, 1992] R. Cottle, J.-S. Pang, and R. Stone. The Linear Complementarity Problem. Academic Press, 1992.

## ◆ SolveLcpLemke()

 bool SolveLcpLemke ( const MatrixX< T > & M, const VectorX< T > & q, VectorX< T > * z, const T & piv_tol = T(-1), const T & zero_tol = T(-1) ) const

Lemke's Algorithm for solving LCPs in the matrix class E, which contains all strictly semimonotone matrices, all P-matrices, and all strictly copositive matrices.

Lemke's Algorithm is described in [Cottle 1992], Section 4.4. This implementation was adapted from the LEMKE Library [LEMKE] for Matlab; this particular implementation fixes a bug in LEMKE that could occur when multiple indices passed the minimum ratio test.

Although this solver is theoretically guaranteed to give a solution to the LCPs described above, accumulated floating point error from pivoting operations could cause the solver to fail. Additionally, the solver can be applied with some success to problems outside of its guaranteed matrix classes. For these reasons, the solver returns a flag indicating success/failure.

Parameters
 [in] M the LCP matrix. [in] q the LCP vector. [in,out] z the solution to the LCP on return (if the solver succeeds). If the length of z is equal to the length of q, the solver will attempt to use z's value as a starting solution. This warmstarting is generally not recommended: it has a predisposition to lead to a failing pivoting sequence. If the solver fails (returns false), z will be set to the zero vector. [in] zero_tol The tolerance for testing against zero. If the tolerance is negative (default) the solver will determine a generally reasonable tolerance. [in] piv_tol The tolerance for testing against zero, specifically used for the purpose of finding variables for pivoting. If the tolerance is negative (default) the solver will determine a generally reasonable tolerance.
Returns
true if the solver believes it has computed a solution (which it determines by the ability to "pivot out" the "artificial" variable (see [Cottle 1992]) and false otherwise.
Warning
The caller should verify that the algorithm has solved the LCP to the desired tolerances on returns indicating success.
Exceptions
 std::exception if M is not square or the dimensions of M do not match the length of q.

## ◆ SolveLcpLemkeRegularized()

 bool SolveLcpLemkeRegularized ( const MatrixX< T > & M, const VectorX< T > & q, VectorX< T > * z, int min_exp = -20, unsigned step_exp = 1, int max_exp = 1, const T & piv_tol = T(-1), const T & zero_tol = T(-1) ) const

Lemke's Algorithm for solving LCPs in the matrix class E, which contains all strictly semimonotone matrices, all P-matrices, and all strictly copositive matrices.

Lemke's Algorithm is described in [Cottle 1992], Section 4.4.

This implementation wraps that algorithm with a Tikhonov-type regularization approach. Specifically, this implementation repeatedly attempts to solve the LCP:

(M + Iα)z + q = w
z ≥ 0
w ≥ 0
zᵀw = 0


where I is the identity matrix and α ≪ 1, using geometrically increasing values of α, until the LCP is solved. See SolveLcpFastRegularized() for description of the regularization process and the function parameters, which are identical. See SolveLcpLemke() for a description of Lemke's Algorithm. See SolveLcpFastRegularized() for a description of all calling parameters other than z, which apply equally well to this function.

Parameters
 [in,out] z the solution to the LCP on return (if the solver succeeds). If the length of z is equal to the length of q, the solver will attempt to use z's value as a starting solution. This warmstarting is generally not recommended: it has a predisposition to lead to a failing pivoting sequence.