Bullet Collision Detection & Physics Library: btDantzigSolver.h Source File

Bullet Collision Detection & Physics Library

btDantzigSolver.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2013 Erwin Coumans http://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
16
17#ifndef BT_DANTZIG_SOLVER_H
18#define BT_DANTZIG_SOLVER_H
19
20#include "btMLCPSolverInterface.h"
21#include "btDantzigLCP.h"
22
23 class btDantzigSolver : public btMLCPSolverInterface
24{
25protected:
26 btScalar m_acceptableUpperLimitSolution;
27
28 btAlignedObjectArray<char> m_tempBuffer;
29
30 btAlignedObjectArray<btScalar> m_A;
31 btAlignedObjectArray<btScalar> m_b;
32 btAlignedObjectArray<btScalar> m_x;
33 btAlignedObjectArray<btScalar> m_lo;
34 btAlignedObjectArray<btScalar> m_hi;
35 btAlignedObjectArray<int> m_dependencies;
36 btDantzigScratchMemory m_scratchMemory;
37
38public:
39 btDantzigSolver()
40 : m_acceptableUpperLimitSolution(btScalar(1000))
41 {
42 }
43
44 virtual bool solveMLCP(const btMatrixXu& A, const btVectorXu& b, btVectorXu& x, const btVectorXu& lo, const btVectorXu& hi, const btAlignedObjectArray<int>& limitDependency, int numIterations, bool useSparsity = true)
45 {
46 bool result = true;
47 int n = b.rows();
48 if (n)
49 {
50 int nub = 0;
51 btAlignedObjectArray<btScalar> ww;
52 ww.resize(n);
53
54 const btScalar* Aptr = A.getBufferPointer();
55 m_A.resize(n * n);
56 for (int i = 0; i < n * n; i++)
57 {
58 m_A[i] = Aptr[i];
59 }
60
61 m_b.resize(n);
62 m_x.resize(n);
63 m_lo.resize(n);
64 m_hi.resize(n);
65 m_dependencies.resize(n);
66 for (int i = 0; i < n; i++)
67 {
68 m_lo[i] = lo[i];
69 m_hi[i] = hi[i];
70 m_b[i] = b[i];
71 m_x[i] = x[i];
72 m_dependencies[i] = limitDependency[i];
73 }
74
75 result = btSolveDantzigLCP(n, &m_A[0], &m_x[0], &m_b[0], &ww[0], nub, &m_lo[0], &m_hi[0], &m_dependencies[0], m_scratchMemory);
76 if (!result)
77 return result;
78
79 // printf("numAllocas = %d\n",numAllocas);
80 for (int i = 0; i < n; i++)
81 {
82 volatile btScalar xx = m_x[i];
83 if (xx != m_x[i])
84 return false;
85 if (x[i] >= m_acceptableUpperLimitSolution)
86 {
87 return false;
88 }
89
90 if (x[i] <= -m_acceptableUpperLimitSolution)
91 {
92 return false;
93 }
94 }
95
96 for (int i = 0; i < n; i++)
97 {
98 x[i] = m_x[i];
99 }
100 }
101
102 return result;
103 }
104};
105
106#endif //BT_DANTZIG_SOLVER_H
btSolveDantzigLCP
bool btSolveDantzigLCP(int n, btScalar *A, btScalar *x, btScalar *b, btScalar *outer_w, int nub, btScalar *lo, btScalar *hi, int *findex, btDantzigScratchMemory &scratchMem)
Definition btDantzigLCP.cpp:1838
btDantzigLCP.h
btMLCPSolverInterface.h
btMatrixXu
#define btMatrixXu
Definition btMatrixX.h:529
btVectorXu
#define btVectorXu
Definition btMatrixX.h:528
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition btAlignedObjectArray.h:46
btAlignedObjectArray::resize
void resize(int newsize, const T &fillData=T())
Definition btAlignedObjectArray.h:203
btDantzigSolver::m_hi
btAlignedObjectArray< btScalar > m_hi
Definition btDantzigSolver.h:34
btDantzigSolver::m_lo
btAlignedObjectArray< btScalar > m_lo
Definition btDantzigSolver.h:33
btDantzigSolver::m_dependencies
btAlignedObjectArray< int > m_dependencies
Definition btDantzigSolver.h:35
btDantzigSolver::m_x
btAlignedObjectArray< btScalar > m_x
Definition btDantzigSolver.h:32
btDantzigSolver::m_b
btAlignedObjectArray< btScalar > m_b
Definition btDantzigSolver.h:31
btDantzigSolver::m_scratchMemory
btDantzigScratchMemory m_scratchMemory
Definition btDantzigSolver.h:36
btDantzigSolver::btDantzigSolver
btDantzigSolver()
Definition btDantzigSolver.h:39
btDantzigSolver::solveMLCP
virtual bool solveMLCP(const btMatrixXu &A, const btVectorXu &b, btVectorXu &x, const btVectorXu &lo, const btVectorXu &hi, const btAlignedObjectArray< int > &limitDependency, int numIterations, bool useSparsity=true)
Definition btDantzigSolver.h:44
btDantzigSolver::m_A
btAlignedObjectArray< btScalar > m_A
Definition btDantzigSolver.h:30
btDantzigSolver::m_acceptableUpperLimitSolution
btScalar m_acceptableUpperLimitSolution
Definition btDantzigSolver.h:26
btDantzigSolver::m_tempBuffer
btAlignedObjectArray< char > m_tempBuffer
Definition btDantzigSolver.h:28
btMLCPSolverInterface
original version written by Erwin Coumans, October 2013
Definition btMLCPSolverInterface.h:23
btDantzigScratchMemory
Definition btDantzigLCP.h:55