From 6ca948e22f385368126f4c10cd036f7a5374c40c Mon Sep 17 00:00:00 2001 From: "erwin.coumans@gmail.com" Date: Wed, 30 Oct 2013 00:02:13 +0000 Subject: [PATCH] make Lemke work with lower/upper bounds, using the BLCP to LCP conversion (using a dog-slow matrix inversion etc) for this conversion, see also https://github.com/erwincoumans/num4lcp/blob/master/matlab/test_lcp_bounds.m and appendix A1 in http://www.cs.duke.edu/~parr/nips10.pdf, thanks to Kenny Erleben and Evan Drumwright for the tips! (friction is not coupled to normal forces yet) --- .../MLCPSolvers/btLemkeAlgorithm.cpp | 5 +- .../MLCPSolvers/btLemkeSolver.h | 170 ++++++++++++++++-- .../MLCPSolvers/btMLCPSolver.cpp | 4 +- 3 files changed, 163 insertions(+), 16 deletions(-) diff --git a/src/BulletDynamics/MLCPSolvers/btLemkeAlgorithm.cpp b/src/BulletDynamics/MLCPSolvers/btLemkeAlgorithm.cpp index d11764346..1f4015c7c 100644 --- a/src/BulletDynamics/MLCPSolvers/btLemkeAlgorithm.cpp +++ b/src/BulletDynamics/MLCPSolvers/btLemkeAlgorithm.cpp @@ -23,7 +23,10 @@ subject to the following restrictions: #include "btLemkeAlgorithm.h" - +#undef BT_DEBUG_OSTREAM +#ifdef BT_DEBUG_OSTREAM +using namespace std; +#endif //BT_DEBUG_OSTREAM btScalar btMachEps() { diff --git a/src/BulletDynamics/MLCPSolvers/btLemkeSolver.h b/src/BulletDynamics/MLCPSolvers/btLemkeSolver.h index e1de4cf48..177559569 100644 --- a/src/BulletDynamics/MLCPSolvers/btLemkeSolver.h +++ b/src/BulletDynamics/MLCPSolvers/btLemkeSolver.h @@ -22,34 +22,178 @@ subject to the following restrictions: #include "btLemkeAlgorithm.h" + +#ifdef BT_DEBUG_OSTREAM +using namespace std; +#endif //BT_DEBUG_OSTREAM + class btLemkeSolver : public btMLCPSolverInterface { public: virtual bool solveMLCP(const btMatrixXu & A, const btVectorXu & b, btVectorXu& x, const btVectorXu & lo,const btVectorXu & hi,const btAlignedObjectArray& limitDependency, int numIterations, bool useSparsity = true) { - int dimension = A.rows(); - if (0==dimension) + int n = A.rows(); + if (0==n) return true; // printf("================ solving using Lemke/Newton/Fixpoint\n"); - btVectorXu q; - q.resize(dimension); - for (int row=0;row