26 typedef ADMMContactSolverTpl<context::Scalar>
Solver;
35 #ifdef PINOCCHIO_PYTHON_PLAIN_SCALAR_TYPE
37 template<
typename DelassusDerived>
38 static bool solve_wrapper(
40 DelassusDerived & delassus,
42 const context::CoulombFrictionConeVector & cones,
44 const boost::optional<ConstRefVectorXs> primal_solution = boost::none,
45 const boost::optional<ConstRefVectorXs> dual_solution = boost::none,
46 bool compute_largest_eigen_values =
true,
47 bool stat_record =
false)
50 delassus, g, cones,
R, primal_solution, dual_solution, compute_largest_eigen_values,
54 template<
typename DelassusDerived>
55 static bool solve_wrapper2(
57 DelassusDerived & delassus,
59 const context::CoulombFrictionConeVector & cones,
60 Eigen::Ref<context::VectorXs> x)
62 return solver.solve(delassus, g, cones, x);
66 #ifndef PINOCCHIO_PYTHON_SKIP_CASADI_UNSUPPORTED
69 const context::CoulombFrictionConeVector & cones,
const context::VectorXs & forces)
77 const context::CoulombFrictionConeVector & cones,
const context::VectorXs & velocities)
85 const context::CoulombFrictionConeVector & cones,
const context::VectorXs & forces)
91 const context::CoulombFrictionConeVector & cones,
99 const context::CoulombFrictionConeVector & cones,
const context::VectorXs & velocities)
105 #endif // PINOCCHIO_PYTHON_SKIP_CASADI_UNSUPPORTED
109 #ifdef PINOCCHIO_PYTHON_PLAIN_SCALAR_TYPE
110 bp::class_<Solver>
cl(
112 "Alternating Direction Method of Multi-pliers solver for contact dynamics.",
113 bp::init<int, Scalar, Scalar, Scalar, Scalar, Scalar, int>(
114 (bp::arg(
"self"), bp::arg(
"problem_dim"), bp::arg(
"mu_prox") =
Scalar(1e-6),
115 bp::arg(
"tau") =
Scalar(0.5), bp::arg(
"rho_power") =
Scalar(0.2),
116 bp::arg(
"rho_power_factor") =
Scalar(0.05), bp::arg(
"ratio_primal_dual") =
Scalar(10),
117 bp::arg(
"max_it_largest_eigen_value_solver") = 20),
118 "Default constructor."));
122 "solve", solve_wrapper<ContactCholeskyDecomposition::DelassusCholeskyExpression>,
123 (bp::args(
"self",
"delassus",
"g",
"cones",
"R"),
124 bp::arg(
"primal_solution") = boost::none, bp::arg(
"dual_solution") = boost::none,
125 bp::arg(
"compute_largest_eigen_values") =
true, bp::arg(
"stat_record") =
false),
126 "Solve the constrained conic problem, starting from the optional initial guess.")
128 "solve", solve_wrapper<context::DelassusOperatorDense>,
129 (bp::args(
"self",
"delassus",
"g",
"cones",
"R"),
130 bp::arg(
"primal_solution") = boost::none, bp::arg(
"dual_solution") = boost::none,
131 bp::arg(
"compute_largest_eigen_values") =
true, bp::arg(
"stat_record") =
false),
132 "Solve the constrained conic problem, starting from the optional initial guess.")
134 "solve", solve_wrapper<context::DelassusOperatorSparse>,
135 (bp::args(
"self",
"delassus",
"g",
"cones",
"R"),
136 bp::arg(
"primal_solution") = boost::none, bp::arg(
"dual_solution") = boost::none,
137 bp::arg(
"compute_largest_eigen_values") =
true, bp::arg(
"stat_record") =
false),
138 "Solve the constrained conic problem, starting from the optional initial guess.")
140 .def(
"setRho", &Solver::setRho, bp::args(
"self",
"rho"),
"Set the ADMM penalty value.")
141 .def(
"getRho", &Solver::getRho, bp::arg(
"self"),
"Get the ADMM penalty value.")
144 "setRhoPower", &Solver::setRhoPower, bp::args(
"self",
"rho_power"),
145 "Set the power associated to the problem conditionning.")
147 "getRhoPower", &Solver::getRhoPower, bp::arg(
"self"),
148 "Get the power associated to the problem conditionning.")
151 "setRhoPowerFactor", &Solver::setRhoPowerFactor, bp::args(
"self",
"rho_power_factor"),
152 "Set the power factor associated to the problem conditionning.")
154 "getRhoPowerFactor", &Solver::getRhoPowerFactor, bp::arg(
"self"),
155 "Get the power factor associated to the problem conditionning.")
158 "setTau", &Solver::setTau, bp::args(
"self",
"tau"),
"Set the tau linear scaling factor.")
159 .def(
"getTau", &Solver::getTau, bp::arg(
"self"),
"Get the tau linear scaling factor.")
162 "setProximalValue", &Solver::setProximalValue, bp::args(
"self",
"mu"),
163 "Set the proximal value.")
165 "getProximalValue", &Solver::getProximalValue, bp::arg(
"self"),
"Get the proximal value.")
168 "setRatioPrimalDual", &Solver::setRatioPrimalDual, bp::args(
"self",
"ratio_primal_dual"),
169 "Set the primal/dual ratio.")
171 "getRatioPrimalDual", &Solver::getRatioPrimalDual, bp::arg(
"self"),
172 "Get the primal/dual ratio.")
175 "getPrimalSolution", &Solver::getPrimalSolution, bp::arg(
"self"),
176 "Returns the primal solution of the problem.", bp::return_internal_reference<>())
179 "getDualSolution", &Solver::getDualSolution, bp::arg(
"self"),
180 "Returns the dual solution of the problem.", bp::return_internal_reference<>())
183 "getCholeskyUpdateCount", &Solver::getCholeskyUpdateCount, bp::arg(
"self"),
184 "Returns the number of updates of the Cholesky factorization due to rho updates.")
187 "computeRho", &Solver::computeRho, bp::args(
"L",
"m",
"rho_power"),
188 "Compute the penalty ADMM value from the current largest and lowest eigenvalues and "
189 "the scaling spectral factor.")
190 .staticmethod(
"computeRho")
192 "computeRhoPower", &Solver::computeRhoPower, bp::args(
"L",
"m",
"rho"),
193 "Compute the scaling spectral factor of the ADMM penalty term from the current "
194 "largest and lowest eigenvalues and the ADMM penalty term.")
195 .staticmethod(
"computeRhoPower")
198 "getPowerIterationAlgo", &Solver::getPowerIterationAlgo, bp::arg(
"self"),
199 bp::return_internal_reference<>())
201 .def(
"getStats", &Solver::getStats, bp::arg(
"self"), bp::return_internal_reference<>());
203 #ifdef PINOCCHIO_WITH_ACCELERATE_SUPPORT
205 typedef Eigen::AccelerateLLT<context::SparseMatrix> AccelerateLLT;
207 DelassusOperatorSparseAccelerate;
209 "solve", solve_wrapper<DelassusOperatorSparseAccelerate>,
210 (bp::args(
"self",
"delassus",
"g",
"cones",
"R"),
211 bp::arg(
"primal_solution") = boost::none, bp::arg(
"dual_solution") = boost::none,
212 bp::arg(
"compute_largest_eigen_values") =
true, bp::arg(
"stat_record") =
false),
213 "Solve the constrained conic problem, starting from the optional initial guess.");
219 "Project a vector on the cartesian product of cones.");
223 bp::args(
"cones",
"velocities"),
224 "Project a vector on the cartesian product of dual cones.");
228 "Compute the primal feasibility.");
232 bp::args(
"cones",
"forces",
"velocities"),
"Compute the reprojection error.");
236 bp::args(
"cones",
"velocities"),
237 "Compute the complementarity shift associated to the De Saxé function.");
240 bp::class_<SolverStats>(
242 bp::init<int>((bp::arg(
"self"), bp::arg(
"max_it")),
"Default constructor"))
243 .def(
"reset", &SolverStats::reset, bp::arg(
"self"),
"Reset the stasts.")
246 "Size of the vectors stored in the structure.")
248 .PINOCCHIO_ADD_PROPERTY_READONLY(
SolverStats, primal_feasibility,
"")
249 .PINOCCHIO_ADD_PROPERTY_READONLY(
SolverStats, dual_feasibility,
"")
250 .PINOCCHIO_ADD_PROPERTY_READONLY(
SolverStats, dual_feasibility_ncp,
"")
251 .PINOCCHIO_ADD_PROPERTY_READONLY(
SolverStats, complementarity,
"")
253 .PINOCCHIO_ADD_PROPERTY_READONLY(
254 SolverStats,
it,
"Number of iterations performed by the algorithm.")
255 .PINOCCHIO_ADD_PROPERTY_READONLY(
257 "Number of Cholesky updates performed by the algorithm.");
262 bp::class_<PowerIterationAlgo>(
263 "PowerIterationAlgo",
"",
264 bp::init<Eigen::DenseIndex, int, Scalar>(
265 (bp::arg(
"self"), bp::arg(
"size"), bp::arg(
"max_it") = 10, bp::arg(
"rel_tol") = 1e-8),
266 "Default constructor"))
267 .def(
"run", &PowerIterationAlgo::run<context::MatrixXs>, bp::arg(
"self"),
"")
269 "lowest", &PowerIterationAlgo::lowest<context::MatrixXs>,
270 (bp::arg(
"self"), bp::arg(
"compute_largest") =
true),
"")
271 .def(
"reset", &PowerIterationAlgo::reset, bp::arg(
"self"))