AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
agx::NlMixedCp::McpAlgorithm Class Referenceabstract

Interface class for algorithm to solve general mixed complementarity problem. More...

#include <MixedLCP.h>

+ Inheritance diagram for agx::NlMixedCp::McpAlgorithm:

Classes

struct  Args
 Structure for all the arguments passed around. More...
 
class  Exception
 
class  SolveReport
 

Public Member Functions

 McpAlgorithm (agx::Real globalTolerance, agx::UInt maxNumIterations, bool gatherStatistics)
 Construct given minimum tolerance and maximum number of iterations.
 
void clearStats (size_t numEquations)
 Ensure that the solver statistics can report data for the given number of equations.
 
agx::Real getGlobalTolerance () const
 
agx::UInt getMaxNumIterations () const
 
McpAlgorithmStats & getStats ()
 
const McpAlgorithmStats & getStats () const
 
void resizeStats (size_t numEquations)
 Ensure that the solver statistics can report data for the given number of equations.
 
void setGlobalTolerance (agx::Real globalTolerance)
 Assign the tolerance (accuracy) of the solution.
 
void setMaxNumIterations (agx::UInt maxNumIterations)
 Assign the maximum number of iterations this algorithm may perform to reach the given tolerance of the solution.
 
virtual agx::NlMixedCp::McpAlgorithm::SolveReport solve (agx::NlMixedCp::McpAlgorithm::Args &args)=0
 Solve given current state of the index set, matrix, q, bounds etc.
 
- Public Member Functions inherited from agx::Referenced
 Referenced ()
 Default constructor.
 
 Referenced (const Referenced &)
 
template<typename T >
T * as ()
 Subclass casting.
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match.
 
template<typename T >
const T * asSafe () const
 
int getReferenceCount () const
 
template<typename T >
bool is () const
 Subclass test.
 
Referenced & operator= (const Referenced &)
 Assignment operator. Will increment the number of references to the referenced object.
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it.
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it.
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it.
 

Static Public Member Functions

static agx::Real getComplementarityError (const agx::IndexSet &indexSet, const agx::SparseRangeReal &bounds, const agx::RealValarray &z, const agx::RealValarray &w)
 Computes the complementarity error of a current solution.
 
static agx::Bool isFeasible (const SparseRangeReal &bounds, const RealValarray &z, const Real threshold)
 Checks if the solution z is feasible, i.e., within bounds.
 
static agx::Bool saveAsHdf5 (const agx::String &filename, const SparseMatrix &m, RealValarray &z, RealValarray &q, RealValarray &signs, const agx::SparseRangeReal &bounds)
 Save matrix, solution, right hand side, sign convention and bounds to a unique problem in filename.
 
- Static Public Member Functions inherited from agx::Referenced
template<typename T >
static bool ValidateCast (const Referenced *object)
 

Protected Member Functions

void debugCheckSolution (const RealValarray &z, const SparseRangeReal &) const
 Asserts if z has invalid values.
 
void forceToBound (RealValarray &v, const agx::SparseRangeReal &bounds, const agx::IndexSet &indexSet) const
 Write the elements v[i] for which i is at a bound.
 
void getSlack (agx::SparseMatrix &m, agx::RealValarray &z, const agx::RealValarray &q, const agx::RealValarray &signs, agx::RealValarray &slack) const
 Computes slack w = M z + q.
 
void linearSolve (agx::SparseMatrix &m, agx::RealValarray &z, const agx::RealValarray &q, const agx::RealValarray &signs) const
 Solves: M z = -q for z.
 
void solveInitial (agx::NlMixedCp::McpAlgorithm::Args &args) const
 Performs linear solve and stores the solution into args.z0 AND args.z.
 
void solvePp (agx::SparseMatrix &m, agx::SparseInverse &sparseInverse, const RealValarray &z0, const agx::SparseRangeReal &bounds, const IndexSet &indexSet, const RealValarray &signs, RealValarray &z) const
 Solve principle problem given sparse matrix, initial solution, bounds and current index set.
 
void solvePp (agx::SparseMatrix &m, const agx::SparseRangeReal &bounds, const IndexSet &indexSet, const RealValarray &signs, const RealValarray &q, RealValarray &z, RealValarray &workspace)
 Solve principle problem given sparse matrix, initial solution, bounds and current index set.
 
virtual agx::UInt switchIndices (const agx::RealValarray &z, const agx::RealValarray &w, const agx::SparseRangeReal &bounds, agx::IndexSet &indexSet, agx::Real tolerance=agx::Real(1E-8)) const
 Switch indices in the index set given current solution and slack.
 
- Protected Member Functions inherited from agx::Referenced
virtual ~Referenced ()
 Destructor.
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 

Protected Attributes

agx::Real m_globalTolerance
 
agx::UInt m_maxNumIterations
 
McpAlgorithmStats m_stats
 
- Protected Attributes inherited from agx::Referenced
Mutex m_mutex
 
ObserverContainer m_observers
 
AtomicValue m_refCount
 

Additional Inherited Members

- Static Protected Member Functions inherited from agx::Referenced
static DeleteHandler * getDeleteHandler ()
 
static void setDeleteHandler (DeleteHandler *handler)
 Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to.
 

Detailed Description

Interface class for algorithm to solve general mixed complementarity problem.

After call to solve the solution is stored in the z array.

Definition at line 114 of file MixedLCP.h.

Constructor & Destructor Documentation

◆ McpAlgorithm()

agx::NlMixedCp::McpAlgorithm::McpAlgorithm ( agx::Real  globalTolerance,
agx::UInt  maxNumIterations,
bool  gatherStatistics 
)

Construct given minimum tolerance and maximum number of iterations.

Member Function Documentation

◆ clearStats()

void agx::NlMixedCp::McpAlgorithm::clearStats ( size_t  numEquations)

Ensure that the solver statistics can report data for the given number of equations.

All previously reported statistics are set to zero.

Parameters
numEquationsThe number of equations to gather statistics for.

◆ debugCheckSolution()

void agx::NlMixedCp::McpAlgorithm::debugCheckSolution ( const RealValarray &  z,
const SparseRangeReal &   
) const
protected

Asserts if z has invalid values.

◆ forceToBound()

void agx::NlMixedCp::McpAlgorithm::forceToBound ( RealValarray &  v,
const agx::SparseRangeReal &  bounds,
const agx::IndexSet &  indexSet 
) const
protected

Write the elements v[i] for which i is at a bound.

◆ getComplementarityError()

static agx::Real agx::NlMixedCp::McpAlgorithm::getComplementarityError ( const agx::IndexSet &  indexSet,
const agx::SparseRangeReal &  bounds,
const agx::RealValarray &  z,
const agx::RealValarray &  w 
)
static

Computes the complementarity error of a current solution.

Parameters
indexSet- index set
bounds- bounded variables
z- current solution
w- current slack
Returns
normalized error

◆ getGlobalTolerance()

agx::Real agx::NlMixedCp::McpAlgorithm::getGlobalTolerance ( ) const
Returns
the tolerance (accuracy) of the solution

◆ getMaxNumIterations()

agx::UInt agx::NlMixedCp::McpAlgorithm::getMaxNumIterations ( ) const
Returns
the maximum number of iterations this algorithm may perform to reach the given tolerance of the solution

◆ getSlack()

void agx::NlMixedCp::McpAlgorithm::getSlack ( agx::SparseMatrix &  m,
agx::RealValarray &  z,
const agx::RealValarray &  q,
const agx::RealValarray &  signs,
agx::RealValarray &  slack 
) const
protected

Computes slack w = M z + q.

Parameters
m- sparse matrix
z- current solution (NOTE: multiplied with signs before matrix multiply, but and later restored, hence not const)
q- right hand side
signs- sign convention (-1 for constraints 1 for bodies)
[out]slack- output slack

◆ getStats() [1/2]

McpAlgorithmStats & agx::NlMixedCp::McpAlgorithm::getStats ( )
Returns
The solver statistics for the current solve algorithm.

◆ getStats() [2/2]

const McpAlgorithmStats & agx::NlMixedCp::McpAlgorithm::getStats ( ) const
Returns
The solver statistics for the current solve algorithm.

◆ isFeasible()

static agx::Bool agx::NlMixedCp::McpAlgorithm::isFeasible ( const SparseRangeReal &  bounds,
const RealValarray &  z,
const Real  threshold 
)
static

Checks if the solution z is feasible, i.e., within bounds.

Parameters
bounds- bounded equations in z
z- current solution
threshold- feasible threshold
Returns
true if z is feasible, otherwise false

◆ linearSolve()

void agx::NlMixedCp::McpAlgorithm::linearSolve ( agx::SparseMatrix &  m,
agx::RealValarray &  z,
const agx::RealValarray &  q,
const agx::RealValarray &  signs 
) const
protected

Solves: M z = -q for z.

Parameters
m- sparse matrix
[out]z- solution
q- right hand side
signs- sign convention (-1 for constraints 1 for bodies)

◆ resizeStats()

void agx::NlMixedCp::McpAlgorithm::resizeStats ( size_t  numEquations)

Ensure that the solver statistics can report data for the given number of equations.

Any new allocations will be initialized to zero.

Parameters
numEquationsThe number of equations to gather statistics for.

◆ saveAsHdf5()

static agx::Bool agx::NlMixedCp::McpAlgorithm::saveAsHdf5 ( const agx::String &  filename,
const SparseMatrix &  m,
RealValarray &  z,
RealValarray &  q,
RealValarray &  signs,
const agx::SparseRangeReal &  bounds 
)
static

Save matrix, solution, right hand side, sign convention and bounds to a unique problem in filename.

Parameters
filename- name of file to save the problem to
m- matrix
z- solution
q- rhs
signs- sign convention (-1 of constraints 1 for bodies)
bounds- bounds
Returns
true if successful, otherwise false

◆ setGlobalTolerance()

void agx::NlMixedCp::McpAlgorithm::setGlobalTolerance ( agx::Real  globalTolerance)

Assign the tolerance (accuracy) of the solution.

◆ setMaxNumIterations()

void agx::NlMixedCp::McpAlgorithm::setMaxNumIterations ( agx::UInt  maxNumIterations)

Assign the maximum number of iterations this algorithm may perform to reach the given tolerance of the solution.

◆ solve()

virtual agx::NlMixedCp::McpAlgorithm::SolveReport agx::NlMixedCp::McpAlgorithm::solve ( agx::NlMixedCp::McpAlgorithm::Args &  args)
pure virtual

Solve given current state of the index set, matrix, q, bounds etc.

Returns
the solve report

Implemented in agx::BoxedHybridPivotAlgorithm, agx::BoxedKellerAlgorithm, and agx::BoxedMurtyAlgorithm.

◆ solveInitial()

void agx::NlMixedCp::McpAlgorithm::solveInitial ( agx::NlMixedCp::McpAlgorithm::Args &  args) const
protected

Performs linear solve and stores the solution into args.z0 AND args.z.

◆ solvePp() [1/2]

void agx::NlMixedCp::McpAlgorithm::solvePp ( agx::SparseMatrix &  m,
agx::SparseInverse &  sparseInverse,
const RealValarray &  z0,
const agx::SparseRangeReal &  bounds,
const IndexSet &  indexSet,
const RealValarray &  signs,
RealValarray &  z 
) const
protected

Solve principle problem given sparse matrix, initial solution, bounds and current index set.

Parameters
m- sparse matrix (support solve and for unit solve)
sparseInverse- sparse inverse with storage of columns of the inverse
z0- initial, linear solution
bounds- bounded variables
indexSet- current state of the index set
signs- sign convention (-1 for constraints 1 for bodies)
[out]z- solution

◆ solvePp() [2/2]

void agx::NlMixedCp::McpAlgorithm::solvePp ( agx::SparseMatrix &  m,
const agx::SparseRangeReal &  bounds,
const IndexSet &  indexSet,
const RealValarray &  signs,
const RealValarray &  q,
RealValarray &  z,
RealValarray &  workspace 
)
protected

Solve principle problem given sparse matrix, initial solution, bounds and current index set.

Parameters
m- sparse matrix (support solve and for unit solve)
bounds- bounded variables
indexSet- current state of the index set
signs- sign convention (-1 for constraints 1 for bodies)
q- right hand side
[out]z- solution
workspaceTemporary vector used for storage and to avoid reallocations

◆ switchIndices()

virtual agx::UInt agx::NlMixedCp::McpAlgorithm::switchIndices ( const agx::RealValarray &  z,
const agx::RealValarray &  w,
const agx::SparseRangeReal &  bounds,
agx::IndexSet &  indexSet,
agx::Real  tolerance = agx::Real(1E-8) 
) const
protectedvirtual

Switch indices in the index set given current solution and slack.

Parameters
z- solution
w- slack
bounds- bounded equations
indexSet- Output variable: with index set
tolerance- tolerance of switch condition
Returns
number of switched indices

Reimplemented in agx::BoxedKellerAlgorithm.

Member Data Documentation

◆ m_globalTolerance

agx::Real agx::NlMixedCp::McpAlgorithm::m_globalTolerance
protected

Definition at line 354 of file MixedLCP.h.

◆ m_maxNumIterations

agx::UInt agx::NlMixedCp::McpAlgorithm::m_maxNumIterations
protected

Definition at line 355 of file MixedLCP.h.

◆ m_stats

McpAlgorithmStats agx::NlMixedCp::McpAlgorithm::m_stats
protected

Definition at line 357 of file MixedLCP.h.


The documentation for this class was generated from the following file: