MBSim

Project Page
linear_complementarity_problem.h
00001 /* Copyright (C) 2004-2012 MBSim Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU Lesser General Public
00005  * License as published by the Free Software Foundation; either
00006  * version 2.1 of the License, or (at your option) any later version.
00007  *
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Lesser General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Lesser General Public
00014  * License along with this library; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact: martin.o.foerg@googlemail.com
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 
00038   class LinearComplementarityProblem {
00039     public:
00040       enum LCPSolvingStrategy {
00041         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)
00042         ReformulatedStandard,  //trying to use the iterative schemes at first (as fallback use Lemke)
00043         ReformulatedNewtonOnly,
00044         ReformulatedFixpointOnly,
00045         LemkeOnly
00046           //only use LemkeAgorithm
00047       };
00048 
00049       enum JacobianType {
00050         Numerical,  //use only a numerical Jacobian Matrix
00051         LCPSpecial
00052           //use a analytical Jacobian Matrix almost everywhere and choose a derivation at the kink (=LinearComplementarityJacobianFunction) //TODO: find a better name
00053       };
00054 
00055       enum CriteriaType {
00056         Global,
00057         Local
00058       };
00059 
00068       LinearComplementarityProblem(const fmatvec::SymMat & M_, const fmatvec::Vec & q_, const LCPSolvingStrategy & strategy_ = Standard, const JacobianType & jacobianType_ = LCPSpecial, const unsigned int & DEBUGLEVEL = 0);
00069 
00070       virtual ~LinearComplementarityProblem();
00071 
00072       /*GETTER / SETTER*/
00073       void setSystem(const fmatvec::SymMat & M_, const fmatvec::Vec & q_);
00074       void setStrategy(const LCPSolvingStrategy & strategy_) {
00075         strategy = strategy_;
00076         oldStrategy = strategy_;
00077       }
00078       void setJacobianType(const JacobianType & jacobianType_) {
00079         jacobianType = jacobianType_;
00080       }
00081       void setNewtonCriteriaFunction(CriteriaFunction * criteriaFunction_) {
00082         newtonSolver->setCriteriaFunction(criteriaFunction_);
00083       }
00084       void setFixpointCriteriaFunction(CriteriaFunction * criteriaFunction_) {
00085         fixpointSolver->setCriteriaFunction(criteriaFunction_);
00086       }
00087       void setDebugLevel(const unsigned int & DEBUGLEVEL_) {
00088         DEBUGLEVEL = DEBUGLEVEL_;
00089       }
00090       /****************/
00091 
00092       fmatvec::Vec solve(const fmatvec::Vec & initialSolution = fmatvec::Vec(0, fmatvec::NONINIT));
00093 
00097       static double computeMediumEigVal(const fmatvec::SqrMat & M);
00098 
00102       static fmatvec::Vec createInitialSolution(const fmatvec::SymMat & M, const fmatvec::Vec & q, double mediumEigVal = 0);
00103 
00107       static fmatvec::Vec createInitialSolution(const fmatvec::SqrMat & M, const fmatvec::Vec & q, double mediumEigVal = 0);
00108 
00109     protected:
00113       void useNewton(fmatvec::Vec & solution, bool & solved);
00114 
00118       void useFixpoint(fmatvec::Vec & solution, bool & solved);
00119 
00123       fmatvec::SqrMat M;
00124 
00128       fmatvec::Vec q;
00129 
00133       LCPSolvingStrategy strategy;
00134 
00138       LCPSolvingStrategy oldStrategy;
00139 
00143       double mediumEigenValue;
00144 
00148       JacobianType jacobianType;
00149 
00153       LemkeAlgorithm lemkeSolver;
00154 
00158       MultiDimensionalNewtonMethod * newtonSolver;
00159 
00163       LCPNewtonReformulationFunction * newtonFunction;
00164 
00168       NewtonJacobianFunction * jacobianFunction;
00169 
00173       CriteriaFunction * criteriaNewton;
00174 
00178       MultiDimensionalFixpointSolver * fixpointSolver;
00179 
00183       LCPFixpointReformulationFunction * fixpointFunction;
00184 
00188       CriteriaFunction * criteriaFixedpoint;
00189 
00193       unsigned int DEBUGLEVEL;
00194   };
00195 
00196   std::ostream& operator <<(std::ostream & o, const LinearComplementarityProblem::LCPSolvingStrategy &strategy);
00197 
00198   std::ostream& operator <<(std::ostream & o, const LinearComplementarityProblem::JacobianType &jacobianType);
00199 
00200 }
00201 
00202 #endif /*__LINEAR_COMPLEMENTARITY_PROBLEM_H_*/