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
31namespace 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
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
140
144 JacobianType jacobianType;
145
150
155
160
165
170
175
180
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_*/
Mother class for different criterias that are fulfilled or not.
Definition: criteria_functions.h:33
Definition: lcp_reformulation_functions.h:129
Definition: lcp_reformulation_functions.h:99
Definition: lemke_algorithm.h:28
class to solve a linear complementarity problem
Definition: linear_complementarity_problem.h:38
LCPFixpointReformulationFunction * fixpointFunction
reformulated LCP suited for a FixpointSolver
Definition: linear_complementarity_problem.h:179
LemkeAlgorithm lemkeSolver
LemkeSolver for the direct solution of the LCP.
Definition: linear_complementarity_problem.h:149
static fmatvec::Vec createInitialSolution(const fmatvec::SqrMat &M, const fmatvec::Vec &q, double mediumEigVal=0)
creates an initial solution for the iterative schemes that use a reformulated system
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
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
CriteriaFunction * criteriaFixedpoint
criteria function for Fixedpoint solver
Definition: linear_complementarity_problem.h:184
fmatvec::SqrMat M
linear coupling matrix of the LCP
Definition: linear_complementarity_problem.h:119
LCPSolvingStrategy strategy
algorithm strategy to solve the LCP
Definition: linear_complementarity_problem.h:129
fmatvec::Vec q
constant vector of the LCP
Definition: linear_complementarity_problem.h:124
void useFixpoint(fmatvec::Vec &solution, bool &solved)
change the incoming solution vector using the fixpoint scheme
Definition: linear_complementarity_problem.cc:383
JacobianType jacobianType
jacobian function for the solving with thew newton algorithm in the reformulated case
Definition: linear_complementarity_problem.h:144
MultiDimensionalFixpointSolver * fixpointSolver
FixpointSolver for reformulated system.
Definition: linear_complementarity_problem.h:174
double mediumEigenValue
parameter for finding the start solution for the reformulated system
Definition: linear_complementarity_problem.h:139
LCPNewtonReformulationFunction * newtonFunction
reformulated LCP suited for a Newton Solver
Definition: linear_complementarity_problem.h:159
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
MBSim::MultiDimensionalNewtonMethod * newtonSolver
NewtonSolver for reformulated system.
Definition: linear_complementarity_problem.h:154
LCPSolvingStrategy oldStrategy
save old Strategy for switching...
Definition: linear_complementarity_problem.h:134
NewtonJacobianFunction * jacobianFunction
Jacobian Function for the reformulated LCP.
Definition: linear_complementarity_problem.h:164
CriteriaFunction * criteriaNewton
criteria function for Newton solver
Definition: linear_complementarity_problem.h:169
void useNewton(fmatvec::Vec &solution, bool &solved)
change the incoming solution vector using the fixpoint scheme
Definition: linear_complementarity_problem.cc:333
Fixpoint-Solver for multi-dimensional fixpoint-finding.
Definition: multi_dimensional_fixpoint_solver.h:34
Newton method for multidimensional root finding.
Definition: multi_dimensional_newton_method.h:41
base class for square Jacobians used for the newton method
Definition: newton_method_jacobian_functions.h:31
namespace MBSim
Definition: bilateral_constraint.cc:30