btDantzigLCP.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*************************************************************************
  2. * *
  3. * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
  4. * All rights reserved. Email: russ@q12.org Web: www.q12.org *
  5. * *
  6. * This library is free software; you can redistribute it and/or *
  7. * modify it under the terms of *
  8. * The BSD-style license that is included with this library in *
  9. * the file LICENSE-BSD.TXT. *
  10. * *
  11. * This library is distributed in the hope that it will be useful, *
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
  14. * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
  15. * *
  16. *************************************************************************/
  17. /*
  18. given (A,b,lo,hi), solve the LCP problem: A*x = b+w, where each x(i),w(i)
  19. satisfies one of
  20. (1) x = lo, w >= 0
  21. (2) x = hi, w <= 0
  22. (3) lo < x < hi, w = 0
  23. A is a matrix of dimension n*n, everything else is a vector of size n*1.
  24. lo and hi can be +/- dInfinity as needed. the first `nub' variables are
  25. unbounded, i.e. hi and lo are assumed to be +/- dInfinity.
  26. we restrict lo(i) <= 0 and hi(i) >= 0.
  27. the original data (A,b) may be modified by this function.
  28. if the `findex' (friction index) parameter is nonzero, it points to an array
  29. of index values. in this case constraints that have findex[i] >= 0 are
  30. special. all non-special constraints are solved for, then the lo and hi values
  31. for the special constraints are set:
  32. hi[i] = abs( hi[i] * x[findex[i]] )
  33. lo[i] = -hi[i]
  34. and the solution continues. this mechanism allows a friction approximation
  35. to be implemented. the first `nub' variables are assumed to have findex < 0.
  36. */
  37. #ifndef _BT_LCP_H_
  38. #define _BT_LCP_H_
  39. #include <stdlib.h>
  40. #include <stdio.h>
  41. #include <assert.h>
  42. #include "LinearMath/btScalar.h"
  43. #include "LinearMath/btAlignedObjectArray.h"
  44. struct btDantzigScratchMemory
  45. {
  46. btAlignedObjectArray<btScalar> m_scratch;
  47. btAlignedObjectArray<btScalar> L;
  48. btAlignedObjectArray<btScalar> d;
  49. btAlignedObjectArray<btScalar> delta_w;
  50. btAlignedObjectArray<btScalar> delta_x;
  51. btAlignedObjectArray<btScalar> Dell;
  52. btAlignedObjectArray<btScalar> ell;
  53. btAlignedObjectArray<btScalar *> Arows;
  54. btAlignedObjectArray<int> p;
  55. btAlignedObjectArray<int> C;
  56. btAlignedObjectArray<bool> state;
  57. };
  58. //return false if solving failed
  59. bool btSolveDantzigLCP(int n, btScalar *A, btScalar *x, btScalar *b, btScalar *w,
  60. int nub, btScalar *lo, btScalar *hi, int *findex, btDantzigScratchMemory &scratch);
  61. #endif //_BT_LCP_H_