Bullet Collision Detection & Physics Library
btDantzigSolver.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2013 Erwin Coumans http://bulletphysics.org
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 1. 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. 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 
25 {
26 protected:
27 
29 
31 
39 public:
40 
43  {
44  }
45 
46  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)
47  {
48  bool result = true;
49  int n = b.rows();
50  if (n)
51  {
52  int nub = 0;
54  ww.resize(n);
55 
56 
57  const btScalar* Aptr = A.getBufferPointer();
58  m_A.resize(n*n);
59  for (int i=0;i<n*n;i++)
60  {
61  m_A[i] = Aptr[i];
62 
63  }
64 
65  m_b.resize(n);
66  m_x.resize(n);
67  m_lo.resize(n);
68  m_hi.resize(n);
70  for (int i=0;i<n;i++)
71  {
72  m_lo[i] = lo[i];
73  m_hi[i] = hi[i];
74  m_b[i] = b[i];
75  m_x[i] = x[i];
76  m_dependencies[i] = limitDependency[i];
77  }
78 
79 
80  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);
81  if (!result)
82  return result;
83 
84 // printf("numAllocas = %d\n",numAllocas);
85  for (int i=0;i<n;i++)
86  {
87  volatile btScalar xx = m_x[i];
88  if (xx != m_x[i])
89  return false;
91  {
92  return false;
93  }
94 
95  if (x[i] <= -m_acceptableUpperLimitSolution)
96  {
97  return false;
98  }
99  }
100 
101  for (int i=0;i<n;i++)
102  {
103  x[i] = m_x[i];
104  }
105 
106  }
107 
108  return result;
109  }
110 };
111 
112 #endif //BT_DANTZIG_SOLVER_H
btAlignedObjectArray< int > m_dependencies
original version written by Erwin Coumans, October 2013
btAlignedObjectArray< btScalar > m_b
#define btMatrixXu
Definition: btMatrixX.h:499
btAlignedObjectArray< btScalar > m_hi
btAlignedObjectArray< btScalar > m_lo
btAlignedObjectArray< char > m_tempBuffer
original version written by Erwin Coumans, October 2013
#define btVectorXu
Definition: btMatrixX.h:498
btAlignedObjectArray< btScalar > m_x
btDantzigScratchMemory m_scratchMemory
btAlignedObjectArray< btScalar > m_A
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)
bool btSolveDantzigLCP(int n, btScalar *A, btScalar *x, btScalar *b, btScalar *outer_w, int nub, btScalar *lo, btScalar *hi, int *findex, btDantzigScratchMemory &scratchMem)
void resize(int newsize, const T &fillData=T())
btScalar m_acceptableUpperLimitSolution
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:266