int btLemkeAlgorithm::findLexicographicMinimum(const btMatrixXu& A, const int & pivotColIndex) { int RowIndex = 0; int dim = A.rows(); btAlignedObjectArray<btVectorXu> Rows; for (int row = 0; row < dim; row++) { btVectorXu vec(dim + 1); vec.setZero();//, INIT, 0.) Rows.push_back(vec); btScalar a = A(row, pivotColIndex); if (a > 0) { Rows[row][0] = A(row, 2 * dim + 1) / a; Rows[row][1] = A(row, 2 * dim) / a; for (int j = 2; j < dim + 1; j++) Rows[row][j] = A(row, j - 1) / a; #ifdef BT_DEBUG_OSTREAM // if (DEBUGLEVEL) { // cout << "Rows(" << row << ") = " << Rows[row] << endl; // } #endif } } for (int i = 0; i < Rows.size(); i++) { if (Rows[i].nrm2() > 0.) { int j = 0; for (; j < Rows.size(); j++) { if(i != j) { if(Rows[j].nrm2() > 0.) { btVectorXu test(dim + 1); for (int ii=0;ii<dim+1;ii++) { test[ii] = Rows[j][ii] - Rows[i][ii]; } //=Rows[j] - Rows[i] if (! LexicographicPositive(test)) break; } } } if (j == Rows.size()) { RowIndex += i; break; } } } return RowIndex; }
void btLemkeAlgorithm::GaussJordanEliminationStep(btMatrixXu& A, int pivotRowIndex, int pivotColumnIndex, const btAlignedObjectArray<int>& basis) { btScalar a = -1 / A(pivotRowIndex, pivotColumnIndex); #ifdef BT_DEBUG_OSTREAM cout << A << std::endl; #endif for (int i = 0; i < A.rows(); i++) { if (i != pivotRowIndex) { for (int j = 0; j < A.cols(); j++) { if (j != pivotColumnIndex) { btScalar v = A(i, j); v += A(pivotRowIndex, j) * A(i, pivotColumnIndex) * a; A.setElem(i, j, v); } } } } #ifdef BT_DEBUG_OSTREAM cout << A << std::endl; #endif //BT_DEBUG_OSTREAM for (int i = 0; i < A.cols(); i++) { A.mulElem(pivotRowIndex, i,-a); } #ifdef BT_DEBUG_OSTREAM cout << A << std::endl; #endif //#ifdef BT_DEBUG_OSTREAM for (int i = 0; i < A.rows(); i++) { if (i != pivotRowIndex) { A.setElem(i, pivotColumnIndex,0); } } #ifdef BT_DEBUG_OSTREAM cout << A << std::endl; #endif //#ifdef BT_DEBUG_OSTREAM }