00001
00002
00003
00004
00005
00006
00007
00008
00016 #ifndef __LCP_H__
00017 #define __LCP_H__
00018
00019 #include <fMatrix.h>
00020 #include <vector>
00021 #include <assert.h>
00022
00023
00024
00025 #define ACTIVATE_SAME_STATE // activate same state check during planning
00026
00032 class LCP
00033 {
00034 public:
00036
00041 LCP(const fMat& _NN, const fVec& _r): N(_NN), r(_r) {
00042 assert(N.row() == N.col());
00043 assert(N.row() == r.size());
00044 n_vars = N.col();
00045 }
00046 ~LCP() {
00047 }
00048
00050
00055 int Solve(fVec& g, fVec& a);
00056
00058
00068 int SolveEx(fVec& g, fVec& a, const fVec& g_init, double _max_error = 1e-8, int _max_iteration = 100, double _speed = 0.5, int* n_iteration = 0);
00069
00071
00080 int SolvePivot(fVec& g, fVec& a, double _max_error, int _max_iteration, int* n_iteration, std::vector<int>& _g2w);
00081
00083
00092 int SolvePivot2(fVec& g, fVec& a, double _max_error, int _max_iteration, int* n_iteration, std::vector<int>& _g2w);
00093
00094 static void Pivot(int idx1, int idx2,
00095 const fMat& M, const fVec& q,
00096 fMat& M_new, fVec& q_new);
00097 static void Pivot(std::vector<int>& idx1, std::vector<int>& idx2,
00098 const fMat& M, const fVec& q,
00099 fMat& M_new, fVec& q_new);
00100 static void Pivot(std::vector<int>& w2a, std::vector<int>& w2g,
00101 std::vector<int>& z2a, std::vector<int>& z2g,
00102 const fMat& M, const fVec& q,
00103 fMat& M_new, fVec& q_new);
00104 static void Pivot(const fMat& M, const fVec& q,
00105 std::vector<int>& w2a, std::vector<int>& w2g,
00106 std::vector<int>& z2a, std::vector<int>& z2g,
00107 int new_jr,
00108 fMat& m_jr, fVec& q_new);
00109 static void Pivot(const fMat& M, const fVec& q,
00110 const fMat& oldMinv,
00111 std::vector<int>& old_w2a, std::vector<int>& old_w2g,
00112 std::vector<int>& old_z2a, std::vector<int>& old_z2g,
00113 int ys2a, int ys2g, int yr2a, int yr2g,
00114 std::vector<int>& w2a, std::vector<int>& w2g,
00115 std::vector<int>& z2a, std::vector<int>& z2g,
00116 int jr,
00117 fMat& newMinv, fMat& m_jr, fVec& q_new);
00118
00119 double CheckPivotResult(const fVec& q_new, std::vector<int>& w2a, std::vector<int>& w2g);
00120
00121 const fMat& Mref() {
00122 return M;
00123 }
00124 const fVec& Qref() {
00125 return q;
00126 }
00127
00128 int NumLoops();
00129 int NumErrors();
00130
00131 protected:
00132 static void pivot_body(const fMat& M12, const fMat& M1, const fMat& M2, const fMat& M12bar, const fVec& q1, const fVec& q1bar, fMat& Md12, fMat& Md1, fMat& Md2, fMat& Md12bar, fVec& qd1, fVec& qd1bar);
00133
00134 int check_q(const fVec& q, double max_error) {
00135 for(int i=0; i<n_vars; i++)
00136 {
00137 if(q(i) < -max_error)
00138 {
00139 return false;
00140 }
00141 }
00142 return true;
00143 }
00144
00145 fMat N;
00146 fVec r;
00147 int n_vars;
00148
00149 fMat M;
00150 fVec q;
00151 };
00152
00153 #endif