00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef NUMERICS_LINEAR_COMPLEMENTARITY_PROBLEM_H_
00021 #define NUMERICS_LINEAR_COMPLEMENTARITY_PROBLEM_H_
00022
00023 #include <fmatvec/fmatvec.h>
00024
00025 #include <mbsim/numerics/nonlinear_algebra/multi_dimensional_newton_method.h>
00026 #include <mbsim/numerics/nonlinear_algebra/multi_dimensional_fixpoint_solver.h>
00027 #include <mbsim/numerics/linear_complementarity_problem/lemke_algorithm.h>
00028
00029 #include <mbsim/numerics/functions/lcp_reformulation_functions.h>
00030
00031 namespace MBSim {
00032
00033 enum LCPSolvingStrategy {
00034 Standard,
00035 ReformulatedStandard,
00036 ReformulatedNewtonOnly,
00037 ReformulatedFixpointOnly,
00038 LemkeOnly
00039
00040 };
00041
00042 enum JacobianType {
00043 Numerical,
00044 LCPSpecial
00045
00046 };
00047
00048 enum CriteriaType {
00049 Global,
00050 Local
00051 };
00052 std::ostream& operator <<(std::ostream & o, const LCPSolvingStrategy &strategy);
00053
00054 std::ostream& operator <<(std::ostream & o, const JacobianType &jacobianType);
00055
00056
00062 class LinearComplementarityProblem {
00063 public:
00072 LinearComplementarityProblem(const fmatvec::SymMat & M_, const fmatvec::Vec & q_, const LCPSolvingStrategy & strategy_ = Standard, const JacobianType & jacobianType_ = LCPSpecial, const unsigned int & DEBUGLEVEL = 0);
00073
00074 virtual ~LinearComplementarityProblem();
00075
00076
00077 void setSystem(const fmatvec::SymMat & M_, const fmatvec::Vec & q_);
00078 void setStrategy(const LCPSolvingStrategy & strategy_) {
00079 strategy = strategy_;
00080 oldStrategy = strategy_;
00081 }
00082 void setJacobianType(const JacobianType & jacobianType_) {
00083 jacobianType = jacobianType_;
00084 }
00085 void setNewtonCriteriaFunction(CriteriaFunction * criteriaFunction_) {
00086 newtonSolver->setCriteriaFunction(criteriaFunction_);
00087 }
00088 void setFixpointCriteriaFunction(CriteriaFunction * criteriaFunction_) {
00089 fixpointSolver->setCriteriaFunction(criteriaFunction_);
00090 }
00091 void setDebugLevel(const unsigned int & DEBUGLEVEL_) {
00092 DEBUGLEVEL = DEBUGLEVEL_;
00093 }
00094
00095
00096 fmatvec::Vec solve(const fmatvec::Vec & initialSolution = fmatvec::Vec(0, fmatvec::NONINIT));
00097
00101 static double computeMediumEigVal(const fmatvec::SqrMat & M);
00102
00106 static fmatvec::Vec createInitialSolution(const fmatvec::SymMat & M, const fmatvec::Vec & q, double mediumEigVal = 0);
00107
00111 static fmatvec::Vec createInitialSolution(const fmatvec::SqrMat & M, const fmatvec::Vec & q, double mediumEigVal = 0);
00112
00113 protected:
00117 void useNewton(fmatvec::Vec & solution, bool & solved);
00118
00122 void useFixpoint(fmatvec::Vec & solution, bool & solved);
00123
00127 fmatvec::SqrMat M;
00128
00132 fmatvec::Vec q;
00133
00137 LCPSolvingStrategy strategy;
00138
00142 LCPSolvingStrategy oldStrategy;
00143
00147 double mediumEigenValue;
00148
00152 JacobianType jacobianType;
00153
00157 LemkeAlgorithm lemkeSolver;
00158
00162 MultiDimensionalNewtonMethod * newtonSolver;
00163
00167 LCPNewtonReformulationFunction * newtonFunction;
00168
00172 NewtonJacobianFunction * jacobianFunction;
00173
00177 CriteriaFunction * criteriaNewton;
00178
00182 MultiDimensionalFixpointSolver * fixpointSolver;
00183
00187 LCPFixpointReformulationFunction * fixpointFunction;
00188
00192 CriteriaFunction * criteriaFixedpoint;
00193
00197 unsigned int DEBUGLEVEL;
00198 };
00199 }
00200
00201 #endif