00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef NUMERICS_LEMKE_ALGORITHM_H_
00021 #define NUMERICS_LEMKE_ALGORITHM_H_
00022
00023 #include <fmatvec/fmatvec.h>
00024 #include <fmatvec/atom.h>
00025
00026 namespace MBSim {
00027
00028 class LemkeAlgorithm : public fmatvec::Atom {
00029 public:
00030 LemkeAlgorithm(const bool & DEBUGLEVEL_ = 0) :
00031 M(), q(), steps(0), DEBUGLEVEL(DEBUGLEVEL_), info(-1) {
00032 }
00033
00034 LemkeAlgorithm(const fmatvec::SqrMat & M_, const fmatvec::Vec & q_, const bool & DEBUGLEVEL_ = 0) :
00035 M(M_), q(q_), steps(0), DEBUGLEVEL(DEBUGLEVEL_), info(-1) {
00036 assert(M_.rows() == q.size());
00037 assert(M_.cols() == q.size());
00038 }
00039
00040 LemkeAlgorithm(const fmatvec::SymMat & M_, const fmatvec::Vec & q_, const bool & DEBUGLEVEL_ = 0) :
00041 DEBUGLEVEL(DEBUGLEVEL_) {
00042 setSystem(M_, q_);
00043 }
00044
00045
00049 int getInfo() {
00050 return info;
00051 }
00052
00056 int getSteps(void) {
00057 return steps;
00058 }
00059
00063 void setSystem(const fmatvec::SqrMat & M_, const fmatvec::Vec & q_) {
00064 assert(M_.rows() == q_.size());
00065 assert(M_.cols() == q_.size());
00066 M.resize() = M_;
00067 q.resize() = q_;
00068 }
00069
00073 void setSystem(const fmatvec::SymMat & M_, const fmatvec::Vec & q_) {
00074 M = fmatvec::SqrMat(M_.size(), fmatvec::NONINIT);
00075 for (int i = 0; i < M.size(); i++)
00076 for (int j = 0; j < M.size(); j++)
00077 M(i, j) = M_(i, j);
00078 q = q_;
00079 }
00080
00081
00085 fmatvec::Vec solve(unsigned int maxloops = 0);
00086
00087 virtual ~LemkeAlgorithm() {
00088 }
00089
00090 protected:
00091 int findLexicographicMinimum(const fmatvec::Mat &A, const int & pivotColIndex);
00092 bool LexicographicPositive(const fmatvec::Vec & v);
00093 void GaussJordanEliminationStep(fmatvec::Mat &A, int pivotRowIndex, int pivotColumnIndex, const std::vector<size_t> & basis);
00094 bool greaterZero(const fmatvec::Vec & vector);
00095 bool validBasis(const std::vector<size_t> & basis);
00096
00097 fmatvec::SqrMat M;
00098 fmatvec::Vec q;
00099
00103 unsigned int steps;
00104
00108 bool DEBUGLEVEL;
00109
00116 int info;
00117 };
00118
00119 }
00120 #endif