mbsim 4.0.0 MBSim Kernel

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/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
38 class LinearComplementarityProblem : public virtual fmatvec::Atom {
39 public:
40 enum LCPSolvingStrategy {
41 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)
42 ReformulatedStandard, //trying to use the iterative schemes at first (as fallback use Lemke)
43 ReformulatedNewtonOnly,
44 ReformulatedFixpointOnly,
45 LemkeOnly
46 //only use LemkeAgorithm
47 };
48
49 enum JacobianType {
50 Numerical, //use only a numerical Jacobian Matrix
51 LCPSpecial
52 //use a analytical Jacobian Matrix almost everywhere and choose a derivation at the kink (=LinearComplementarityJacobianFunction) //TODO: find a better name
53 };
54
55 enum CriteriaType {
56 Global,
57 Local
58 };
59
67 LinearComplementarityProblem(const fmatvec::SymMat & M_, const fmatvec::Vec & q_, const LCPSolvingStrategy & strategy_ = Standard, const JacobianType & jacobianType_ = LCPSpecial);
68
69 virtual ~LinearComplementarityProblem();
70
71 /*GETTER / SETTER*/
72 void setSystem(const fmatvec::SymMat & M_, const fmatvec::Vec & q_);
73 void setStrategy(const LCPSolvingStrategy & strategy_) {
74 strategy = strategy_;
75 oldStrategy = strategy_;
76 }
77 void setJacobianType(const JacobianType & jacobianType_) {
78 jacobianType = jacobianType_;
79 }
80 void setNewtonCriteriaFunction(CriteriaFunction * criteriaFunction_) {
81 newtonSolver->setCriteriaFunction(criteriaFunction_);
82 }
83 void setFixpointCriteriaFunction(CriteriaFunction * criteriaFunction_) {
84 fixpointSolver->setCriteriaFunction(criteriaFunction_);
85 }
86 /****************/
87
88 fmatvec::Vec solve(const fmatvec::Vec & initialSolution = fmatvec::Vec(0, fmatvec::NONINIT));
89
93 static double computeMediumEigVal(const fmatvec::SqrMat & M);
94
98 static fmatvec::Vec createInitialSolution(const fmatvec::SymMat & M, const fmatvec::Vec & q, double mediumEigVal = 0);
99
103 static fmatvec::Vec createInitialSolution(const fmatvec::SqrMat & M, const fmatvec::Vec & q, double mediumEigVal = 0);
104
105 protected:
109 void useNewton(fmatvec::Vec & solution, bool & solved);
110
114 void useFixpoint(fmatvec::Vec & solution, bool & solved);
115
119 fmatvec::SqrMat M;
120
124 fmatvec::Vec q;
125
129 LCPSolvingStrategy strategy;
130
134 LCPSolvingStrategy oldStrategy;
135
139 double mediumEigenValue;
140
144 JacobianType jacobianType;
145
149 LemkeAlgorithm lemkeSolver;
150
154 MBSim::MultiDimensionalNewtonMethod * newtonSolver;
155
159 LCPNewtonReformulationFunction * newtonFunction;
160
164 NewtonJacobianFunction * jacobianFunction;
165
169 CriteriaFunction * criteriaNewton;
170
174 MultiDimensionalFixpointSolver * fixpointSolver;
175
179 LCPFixpointReformulationFunction * fixpointFunction;
180
184 CriteriaFunction * criteriaFixedpoint;
185 };
186
187 std::ostream& operator <<(std::ostream & o, const LinearComplementarityProblem::LCPSolvingStrategy &strategy);
188
189 std::ostream& operator <<(std::ostream & o, const LinearComplementarityProblem::JacobianType &jacobianType);
190
191 }
192
193 #endif /*__LINEAR_COMPLEMENTARITY_PROBLEM_H_*/
MBSim::LinearComplementarityProblem::strategy
LCPSolvingStrategy strategy
algorithm strategy to solve the LCP
Definition: linear_complementarity_problem.h:129
MBSim::LinearComplementarityProblem::fixpointFunction
LCPFixpointReformulationFunction * fixpointFunction
reformulated LCP suited for a FixpointSolver
Definition: linear_complementarity_problem.h:179
MBSim::MultiDimensionalNewtonMethod
Newton method for multidimensional root finding.
Definition: multi_dimensional_newton_method.h:41
MBSim::LCPFixpointReformulationFunction
Definition: lcp_reformulation_functions.h:129
MBSim::LinearComplementarityProblem::createInitialSolution
static fmatvec::Vec createInitialSolution(const fmatvec::SymMat &M, const fmatvec::Vec &q, double mediumEigVal=0)
creates an initial solution for the iterative schemes that use a reformulated system
MBSim::LinearComplementarityProblem::lemkeSolver
LemkeAlgorithm lemkeSolver
LemkeSolver for the direct solution of the LCP.
Definition: linear_complementarity_problem.h:149
MBSim::LinearComplementarityProblem
class to solve a linear complementarity problem
Definition: linear_complementarity_problem.h:38
MBSim::LinearComplementarityProblem::oldStrategy
LCPSolvingStrategy oldStrategy
save old Strategy for switching...
Definition: linear_complementarity_problem.h:134
MBSim::LinearComplementarityProblem::mediumEigenValue
double mediumEigenValue
parameter for finding the start solution for the reformulated system
Definition: linear_complementarity_problem.h:139
MBSim::LinearComplementarityProblem::fixpointSolver
MultiDimensionalFixpointSolver * fixpointSolver
FixpointSolver for reformulated system.
Definition: linear_complementarity_problem.h:174
MBSim::LemkeAlgorithm
Definition: lemke_algorithm.h:28
MBSim::NewtonJacobianFunction
base class for square Jacobians used for the newton method
Definition: newton_method_jacobian_functions.h:31
MBSim::LinearComplementarityProblem::q
fmatvec::Vec q
constant vector of the LCP
Definition: linear_complementarity_problem.h:124
MBSim::LinearComplementarityProblem::useFixpoint
void useFixpoint(fmatvec::Vec &solution, bool &solved)
change the incoming solution vector using the fixpoint scheme
Definition: linear_complementarity_problem.cc:383
MBSim::LinearComplementarityProblem::jacobianFunction
NewtonJacobianFunction * jacobianFunction
Jacobian Function for the reformulated LCP.
Definition: linear_complementarity_problem.h:164
MBSim::LCPNewtonReformulationFunction
Definition: lcp_reformulation_functions.h:99
MBSim::LinearComplementarityProblem::newtonSolver
MBSim::MultiDimensionalNewtonMethod * newtonSolver
NewtonSolver for reformulated system.
Definition: linear_complementarity_problem.h:154
MBSim::CriteriaFunction
Mother class for different criterias that are fulfilled or not.
Definition: criteria_functions.h:33
MBSim::LinearComplementarityProblem::computeMediumEigVal
static double computeMediumEigVal(const fmatvec::SqrMat &M)
compute the medium eigenvalue of a matrix (for guessing a initial solution for iterative schemes)
Definition: linear_complementarity_problem.cc:296
MBSim::LinearComplementarityProblem::newtonFunction
LCPNewtonReformulationFunction * newtonFunction
reformulated LCP suited for a Newton Solver
Definition: linear_complementarity_problem.h:159
MBSim::LinearComplementarityProblem::useNewton
void useNewton(fmatvec::Vec &solution, bool &solved)
change the incoming solution vector using the fixpoint scheme
Definition: linear_complementarity_problem.cc:333
MBSim::LinearComplementarityProblem::jacobianType
JacobianType jacobianType
jacobian function for the solving with thew newton algorithm in the reformulated case
Definition: linear_complementarity_problem.h:144
MBSim::MultiDimensionalFixpointSolver
Fixpoint-Solver for multi-dimensional fixpoint-finding.
Definition: multi_dimensional_fixpoint_solver.h:34
MBSim::LinearComplementarityProblem::criteriaNewton
CriteriaFunction * criteriaNewton
criteria function for Newton solver
Definition: linear_complementarity_problem.h:169
MBSim::LinearComplementarityProblem::criteriaFixedpoint
CriteriaFunction * criteriaFixedpoint
criteria function for Fixedpoint solver
Definition: linear_complementarity_problem.h:184
MBSim::LinearComplementarityProblem::M
fmatvec::SqrMat M
linear coupling matrix of the LCP
Definition: linear_complementarity_problem.h:119
MBSim
namespace MBSim
Definition: bilateral_constraint.cc:30
MBSim::LinearComplementarityProblem::LinearComplementarityProblem
LinearComplementarityProblem(const fmatvec::SymMat &M_, const fmatvec::Vec &q_, const LCPSolvingStrategy &strategy_=Standard, const JacobianType &jacobianType_=LCPSpecial)
solves a linear complementarity problem (w = M z + q)
Definition: linear_complementarity_problem.cc:76