Change the solve() method

git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@315 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
chappuis.daniel 2010-05-17 21:30:49 +00:00
parent eddd501bae
commit ad63586b52

View File

@ -23,6 +23,8 @@
// Libraries
#include "../Vector.h"
#include "../Matrix.h"
#include "../../body/Body.h"
#include "../../typeDefinitions.h"
// ReactPhysics3D namespace
namespace reactphysics3d {
@ -30,30 +32,50 @@ namespace reactphysics3d {
/* -------------------------------------------------------------------
Class LCPSolver :
This abstract class represents an algorithm to solve a Linear
Complementary Problem (LCP). Given a matrix "A", a vector "b",
Complementary Problem (LCP). Given a matrix "A=J*B", a vector "b",
a vector "lowLimit" of lower limits and a vector "highLimits" of
upper limits. The goal is to find a vector "x" such that:
upper limits. The goal is to find a vector "lambda" such that:
w = Ax - b
lowLimits <= x <= highLimits
lowLimits <= lambda <= highLimits
and one of the thre following conditions holds :
x_i = lowLimits_i, w_i >= 0
x_i = highLimits_i, w_i >= 0
lowLimits_i < x_i < highLimits_i, w_i = 0
lambda_i = lowLimits_i, w_i >= 0
lambda_i = highLimits_i, w_i >= 0
lowLimits_i < lambda_i < highLimits_i, w_i = 0
Note that the matrix A is givent by the two matrices J and B with A=J*B.
But only their sparse representations "J_sp" and "B_sp" are passed in
arguments to solve() to be more efficient.
-------------------------------------------------------------------
*/
class LCPSolver {
protected:
uint maxIterations; // Maximum number of iterations
Vector lambdaInit; // Initial value for lambda at the beginning of the algorithm
public:
LCPSolver(); // Constructor
virtual ~LCPSolver(); // Destructor
virtual void solve(const Matrix& A, const Vector& b, const Vector& lowLimits, const Vector& highLimits, Vector& x)=0; // Solve a LCP problem
LCPSolver(uint maxIterations); // Constructor
virtual ~LCPSolver(); // Destructor
virtual void solve(const Matrix& J_sp, const Matrix& B_sp, Body*** bodyMapping,
std::map<Body*, uint> bodyNumberMapping const Vector& b, const Vector& lowLimits,
const Vector& highLimits, Vector& lambda) const=0; // Solve a LCP problem
void setLambdaInit(const Vector& lambdaInit); // Set the initial lambda vector
void setMaxIterations(uint maxIterations); // Set the maximum number of iterations
};
// Set the initial lambda vector
inline void LCPSolver::setLambdaInit(const Vector& lambdaInit) {
this->lambdaInit = lambdaInit;
}
// Set the maximum number of iterations
void LCPSolver::setMaxIterations(uint maxIterations) {
assert(maxIterations > 0);
this->maxIterations = maxIterations;
}
} // End of the ReactPhysics3D namespace
#endif