26 #include <agxSabre/agxSabre.h>
29 #pragma warning( push )
30 #pragma warning( disable : 4275 )
36 class StabilityReport;
63 void clear(
size_t numEquations);
84 std::vector<int> m_timesAdded;
90 std::vector<int> m_timesRemoved;
92 UInt m_numNlMixedCpIterations = 0;
94 std::vector<UInt> m_numMurtyIterations;
95 std::vector<UInt> m_numKellerMakeFeasibleIterations;
96 std::vector<UInt> m_numKellerSearchIterations;
98 std::vector<UInt> m_numFreeEquationsAtEnd;
100 bool m_gatherStatistics =
false;
188 Args& operator = (
const Args& ) =
delete;
494 class MixedLCPRep * m_rep;
498 #if defined(_MSC_VER)
499 #pragma warning( pop )
#define AGXPHYSICS_EXPORT
Class that stores rows and columns of the matrix.
Storage location for solver statistics.
const std::vector< UInt > & numMurtyIterations() const
const std::vector< UInt > & numKellerSearchIterations() const
void reportKellerSearchIterations(UInt numIterations)
const std::vector< int > & timesAdded() const
void setNumEquations(size_t numEquations)
void clear(size_t numEquations)
bool getEnableGatherStatistics() const
void reportKellerMakeFeasibleIterations(UInt numIterations)
void addStats(const McpAlgorithmStats &other)
void reportNumNlMixedCpIterations(UInt numIterations)
void reportNumFreeEquationsAtEnd(const agx::IndexSet &indexSet)
const std::vector< UInt > & numFreeEquationsAtEnd() const
void setEnableGatherStatistics(bool enable)
const std::vector< UInt > & numKellerMakeFeasibleIterations() const
const std::vector< int > & timesRemoved() const
void reportMurtyIterations(UInt numIterations)
UInt numNlMixedCpIterations() const
void reportAddedAndRemovedEquations(const agxSabre::UInt32Vector &add, const agxSabre::UInt32Vector &del)
Definition of a mixed LCP problem.
const RealValarray & q() const
void solve(bool warm=false)
Solve the problem .
int getIterations() const
Returns the number of iterations.
const SparseRangeReal & bounds() const
SparseRangeReal & bounds()
bool isSuccess() const
Returns true if the solver computed a correct answer, false * otherwise.
MixedLCPOld(SparseMatrix &M, RealValarray &q, SparseRangeReal &bounds, RealValarray &z, const RealValarray &signs, int max_iterations=-1)
Construction copies references to the internal objects.
const RealValarray & z() const
Real getLastResidual() const
std::ostream & diag(std::ostream &os, const agx::String &msg="") const
agx::Real getResidual() const
agx::Bool isSuccessful() const
agx::UInt getNumIterations() const
SolveReport(agx::UInt numIterations, agx::Real residual, agx::Bool successful)
Construct given solve result.
Interface class for algorithm to solve general mixed complementarity problem.
void debugCheckSolution(const RealValarray &z, const SparseRangeReal &) const
Asserts if z has invalid values.
void resizeStats(size_t numEquations)
Ensure that the solver statistics can report data for the given number of equations.
McpAlgorithm(agx::Real globalTolerance, agx::UInt maxNumIterations, bool gatherStatistics)
Construct given minimum tolerance and maximum number of iterations.
McpAlgorithmStats m_stats
void clearStats(size_t numEquations)
Ensure that the solver statistics can report data for the given number of equations.
const McpAlgorithmStats & getStats() const
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.
agx::Real m_globalTolerance
void linearSolve(agx::SparseMatrix &m, agx::RealValarray &z, const agx::RealValarray &q, const agx::RealValarray &signs) const
Solves: M z = -q for z.
agx::UInt getMaxNumIterations() const
void setGlobalTolerance(agx::Real globalTolerance)
Assign the tolerance (accuracy) of the solution.
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.
agx::UInt m_maxNumIterations
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.
static agx::Bool isFeasible(const SparseRangeReal &bounds, const RealValarray &z, const Real threshold)
Checks if the solution z is feasible, i.e., within bounds.
void setMaxNumIterations(agx::UInt maxNumIterations)
Assign the maximum number of iterations this algorithm may perform to reach the given tolerance of th...
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 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.
void solveInitial(agx::NlMixedCp::McpAlgorithm::Args &args) const
Performs linear solve and stores the solution into args.z0 AND args.z.
virtual agx::NlMixedCp::McpAlgorithm::SolveReport solve(agx::NlMixedCp::McpAlgorithm::Args &args)=0
Solve given current state of the index set, matrix, q, bounds etc.
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 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.
agx::Real getGlobalTolerance() const
McpAlgorithmStats & getStats()
Class that implements a method to solve linear- or nonlinear complementary problems.
agx::RealValarray & getQ()
agx::SparseMatrix m_matrix
agx::NlMixedCp::McpAlgorithmRef m_mcp
virtual agx::UInt solve(agx::Bool warm=false, agx::StabilityReport *stabilityReport=nullptr, agx::INlSolveDataH5 *nlSolveDataH5=nullptr)
Solves the system, returns the total number of iterations made in the inner (mcp) loop.
agx::SparseRangeReal m_sparseBounds
agx::SparseMatrix & getMatrix()
const agx::RealValarray & getQ() const
const agx::RealValarray & getSigns() const
NlMixedCp(agx::NlMixedCp::McpAlgorithm *mcpAlgorithm)
const agx::SparseRangeReal & getSparseBounds() const
const agx::RealValarray & getSolution() const
agx::ref_ptr< McpAlgorithm > McpAlgorithmRef
const agx::SparseMatrix & getMatrix() const
Solver::NlMcpConfig m_config
const agx::NlMixedCp::McpAlgorithm * getAlgorithm() const
agx::UInt m_maxNumOuterIterations
agx::RealValarray & getSolution()
agx::RealValarray m_signs
agx::Real m_outerGlobalTolerance
virtual void setSize(agx::UInt numEquations)
Set the size of the system.
agx::SparseRangeReal & getSparseBounds()
agx::RealValarray & getSigns()
static NlMixedCpRef create(agx::Solver::NlMcpConfig config, bool gatherStatistics)
Creates default solver assuming symmetric-, sparse- and lower triangle matrix.
Base class providing referencing counted objects.
agx::SparseMatrix holds a matrix representation which contains the data.
Essentially a sparse array of bounds.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
agx::ref_ptr< class NlMixedCp > NlMixedCpRef
std::valarray< agx::Real > RealValarray
For this module, vectors are defined using valarray.
VectorPOD< UInt32 > UInt32Vector
Structure for all the arguments passed around.
const agx::RealValarray & signs
agx::ColumnStorage * columnStorage
const agx::SparseRangeReal & bounds
Args(agx::SparseMatrix &m, agx::RealValarray &q, agx::RealValarray &z, agx::RealValarray &z0, const agx::SparseRangeReal &bounds, agx::IndexSet &indexSet, const agx::RealValarray &signs, agx::SparseInverse &sInv, agx::Bool warm=false, agx::StabilityReport *stabilityReport=nullptr)
agx::StabilityReport * stabilityReport