KrisLibrary  1.0.0
LCP.h
1 #ifndef OPTIMIZATION_LCP_H
2 #define OPTIMIZATION_LCP_H
3 
4 #include <KrisLibrary/math/matrix.h>
5 #include <vector>
6 #include <string>
7 
8 
9 namespace Optimization {
10 
11  using namespace Math;
12 
27 class LemkeLCP
28 {
29 public:
30  LemkeLCP(const Matrix& M,const Vector& q);
31  bool Solve();
32  void GetW(Vector& w) const;
33  void GetZ(Vector& z) const;
34  void Print(std::ostream& out) const;
35 
36 private:
37  //returns the index of z0 (-1 if it's initially feasible)
38  int InitialPivot();
39  int PickPivot(int enter) const;
40  bool Pivot(int enter,int leave);
41 
42  const static int z0=-2;
43  const static int constant=-1;
44  bool IsVarW(int var) const { return 0 <= var && var < dictionary.m; }
45  bool IsVarZ(int var) const { return var >= dictionary.m; }
46  int WToZ(int var) const { return var+dictionary.m; }
47  int ZToW(int var) const { return var-dictionary.m; }
48  int VarToW(int var) const { return var; }
49  int VarToZ(int var) const { return var-dictionary.m; }
50  int WToVar(int index) const { return index; }
51  int ZToVar(int index) const { return index+dictionary.m; }
52  std::string VarName(int var) const;
53 
54  public:
55  int verbose;
56 
57  private:
58  //column 0 is the constant term
59  Matrix dictionary;
60  std::vector<int> basic,nonbasic;
61 };
62 
63 bool IterativeLCP(const Matrix& M,const Vector& q,Vector& w,Vector& z,int& maxIters,Real tol);
64 
65 } //namespace Optimization
66 
67 #endif
Namespace for classes and functions in the Optimization package.
Definition: CSet.h:7
Solves a linear complementarity problem.
Definition: LCP.h:27
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12