MBSim

Project Page
linear_complementarity_problem.h
1 /* Copyright (C) 2004-2012 MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: martin.o.foerg@googlemail.com
18  */
19 
20 #ifndef NUMERICS_LINEAR_COMPLEMENTARITY_PROBLEM_H_
21 #define NUMERICS_LINEAR_COMPLEMENTARITY_PROBLEM_H_
22 
23 #include <fmatvec.h>
24 
25 #include <mbsim/numerics/nonlinear_algebra/multi_dimensional_newton_method.h>
26 #include <mbsim/numerics/nonlinear_algebra/multi_dimensional_fixpoint_solver.h>
27 #include <mbsim/numerics/linear_complementarity_problem/lemke_algorithm.h>
28 
29 #include <mbsim/numerics/functions/lcp_reformulation_functions.h>
30 
31 namespace MBSim {
32 
33  enum LCPSolvingStrategy {
34  Standard, //trying to solve the LCP in a standard way (first some steps of Lemke algorithm, then trying iterative schemes in reformulated system, then trying Lemke again as fallback with all steps)
35  ReformulatedStandard, //trying to use the iterative schemes at first (as fallback use Lemke)
36  ReformulatedNewtonOnly,
37  ReformulatedFixpointOnly,
38  LemkeOnly
39  //only use LemkeAgorithm
40  };
41 
42  enum JacobianType {
43  Numerical, //use only a numerical Jacobian Matrix
44  LCPSpecial
45  //use a analytical Jacobian Matrix almost everywhere and choose a derivation at the kink (=LinearComplementarityJacobianFunction) //TODO: find a better name
46  };
47 
48  enum CriteriaType {
49  Global,
50  Local
51  };
52  std::ostream& operator <<(std::ostream & o, const LCPSolvingStrategy &strategy);
53 
54  std::ostream& operator <<(std::ostream & o, const JacobianType &jacobianType);
55 
56 
63  public:
72  LinearComplementarityProblem(const fmatvec::SymMat & M_, const fmatvec::Vec & q_, const LCPSolvingStrategy & strategy_ = Standard, const JacobianType & jacobianType_ = LCPSpecial, const unsigned int & DEBUGLEVEL = 0);
73 
75 
76  /*GETTER / SETTER*/
77  void setSystem(const fmatvec::SymMat & M_, const fmatvec::Vec & q_);
78  void setStrategy(const LCPSolvingStrategy & strategy_) {
79  strategy = strategy_;
80  }
81  void setJacobianType(const JacobianType & jacobianType_) {
82  jacobianType = jacobianType_;
83  }
84  void setNewtonCriteriaFunction(CriteriaFunction * criteriaFunction_) {
85  newtonSolver->setCriteriaFunction(criteriaFunction_);
86  }
87  void setFixpointCriteriaFunction(CriteriaFunction * criteriaFunction_) {
88  fixpointSolver->setCriteriaFunction(criteriaFunction_);
89  }
90  void setDebugLevel(const unsigned int & DEBUGLEVEL_) {
91  DEBUGLEVEL = DEBUGLEVEL_;
92  }
93  /****************/
94 
95  fmatvec::Vec solve(const fmatvec::Vec & initialSolution = fmatvec::Vec(0, fmatvec::NONINIT));
96 
100  static double computeMediumEigVal(const fmatvec::SqrMat & M);
101 
105  static fmatvec::Vec createInitialSolution(const fmatvec::SymMat & M, const fmatvec::Vec & q, double mediumEigVal = 0);
106 
110  static fmatvec::Vec createInitialSolution(const fmatvec::SqrMat & M, const fmatvec::Vec & q, double mediumEigVal = 0);
111 
112  protected:
116  void useNewton(fmatvec::Vec & solution, bool & solved);
117 
121  void useFixpoint(fmatvec::Vec & solution, bool & solved);
122 
126  fmatvec::SqrMat M;
127 
131  fmatvec::Vec q;
132 
136  LCPSolvingStrategy strategy;
137 
142 
146  JacobianType jacobianType;
147 
152 
157 
162 
167 
172 
177 
182 
187 
191  unsigned int DEBUGLEVEL;
192  };
193 }
194 
195 #endif /*__LINEAR_COMPLEMENTARITY_PROBLEM_H_*/