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
00025 namespace MBSim {
00026
00027 class LemkeAlgorithm {
00028 public:
00029 LemkeAlgorithm(const bool & DEBUGLEVEL_ = 0) :
00030 M(), q(), steps(0), DEBUGLEVEL(DEBUGLEVEL_), info(-1) {
00031 }
00032
00033 LemkeAlgorithm(const fmatvec::SqrMat & M_, const fmatvec::Vec & q_, const bool & DEBUGLEVEL_ = 0) :
00034 M(M_), q(q_), steps(0), DEBUGLEVEL(DEBUGLEVEL_), info(-1) {
00035 assert(M_.rows() == q.size());
00036 assert(M_.cols() == q.size());
00037 }
00038
00039 LemkeAlgorithm(const fmatvec::SymMat & M_, const fmatvec::Vec & q_, const bool & DEBUGLEVEL_ = 0) :
00040 DEBUGLEVEL(DEBUGLEVEL_) {
00041 setSystem(M_, q_);
00042 }
00043
00044
00048 int getInfo() {
00049 return info;
00050 }
00051
00055 int getSteps(void) {
00056 return steps;
00057 }
00058
00062 void setSystem(const fmatvec::SqrMat & M_, const fmatvec::Vec & q_) {
00063 assert(M_.rows() == q_.size());
00064 assert(M_.cols() == q_.size());
00065 M.resize() = M_;
00066 q.resize() = q_;
00067 }
00068
00072 void setSystem(const fmatvec::SymMat & M_, const fmatvec::Vec & q_) {
00073 M = fmatvec::SqrMat(M_.size(), fmatvec::NONINIT);
00074 for (int i = 0; i < M.size(); i++)
00075 for (int j = 0; j < M.size(); j++)
00076 M(i, j) = M_(i, j);
00077 q = q_;
00078 }
00079
00080
00084 fmatvec::Vec solve(unsigned int maxloops = 0);
00085
00086 virtual ~LemkeAlgorithm() {
00087 }
00088
00089 protected:
00090 int findLexicographicMinimum(const fmatvec::Mat &A, const int & pivotColIndex);
00091 bool LexicographicPositive(const fmatvec::Vec & v);
00092 void GaussJordanEliminationStep(fmatvec::Mat &A, int pivotRowIndex, int pivotColumnIndex, const std::vector<size_t> & basis);
00093 bool greaterZero(const fmatvec::Vec & vector);
00094 bool validBasis(const std::vector<size_t> & basis);
00095
00096 fmatvec::SqrMat M;
00097 fmatvec::Vec q;
00098
00102 unsigned int steps;
00103
00107 bool DEBUGLEVEL;
00108
00115 int info;
00116 };
00117
00118 }
00119 #endif