1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh |
5 |
|
|
// Heriot-Watt University |
6 |
|
|
// Copyright note valid unless otherwise stated in individual files. |
7 |
|
|
// All rights reserved. |
8 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
9 |
|
|
|
10 |
|
|
#include "crocoddyl/core/activations/quadratic-barrier.hpp" |
11 |
|
|
|
12 |
|
|
#include "python/crocoddyl/core/activation-base.hpp" |
13 |
|
|
#include "python/crocoddyl/core/core.hpp" |
14 |
|
|
#include "python/crocoddyl/utils/copyable.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
10 |
void exposeActivationQuadraticBarrier() { |
20 |
✓✗ |
10 |
bp::class_<ActivationBounds>( |
21 |
|
|
"ActivationBounds", |
22 |
|
|
"Activation bounds.\n\n" |
23 |
|
|
"The activation bounds describe the lower and upper vector plus it " |
24 |
|
|
"activation range\n" |
25 |
|
|
"(between 0 and 1), its default value is 1. Note that a full activation " |
26 |
|
|
"is defined by\n" |
27 |
|
|
"1 and the activation range is equally distributed between the lower and " |
28 |
|
|
"upper bounds.", |
29 |
✓✗ |
10 |
bp::init<Eigen::VectorXd, Eigen::VectorXd, bp::optional<double> >( |
30 |
|
20 |
bp::args("self", "lb", "ub", "beta"), |
31 |
|
|
"Initialize the activation bounds.\n\n" |
32 |
|
|
":param lb: lower bounds\n" |
33 |
|
|
":param ub: upper bounds\n" |
34 |
|
|
":param beta: range of activation (between 0 to 1, default 1)")) |
35 |
✓✗ |
10 |
.add_property("lb", bp::make_getter(&ActivationBounds::lb), |
36 |
✓✗ |
20 |
bp::make_setter(&ActivationBounds::lb, |
37 |
|
10 |
bp::return_internal_reference<>()), |
38 |
✓✗ |
10 |
"lower bounds") |
39 |
✓✗ |
10 |
.add_property("ub", bp::make_getter(&ActivationBounds::ub), |
40 |
✓✗ |
20 |
bp::make_setter(&ActivationBounds::lb, |
41 |
|
10 |
bp::return_internal_reference<>()), |
42 |
✓✗ |
10 |
"upper bounds") |
43 |
✓✗ |
10 |
.add_property("beta", &ActivationBounds::beta, "beta") |
44 |
✓✗ |
10 |
.def(CopyableVisitor<ActivationBounds>()); |
45 |
|
|
|
46 |
|
|
boost::python::register_ptr_to_python< |
47 |
|
10 |
boost::shared_ptr<ActivationModelQuadraticBarrier> >(); |
48 |
|
|
|
49 |
✓✗ |
10 |
bp::class_<ActivationModelQuadraticBarrier, |
50 |
|
|
bp::bases<ActivationModelAbstract> >( |
51 |
|
|
"ActivationModelQuadraticBarrier", |
52 |
|
|
"Inequality activation model.\n\n" |
53 |
|
|
"The activation is zero when r is between the lower (lb) and upper (ub) " |
54 |
|
|
"bounds, beta\n" |
55 |
|
|
"determines how much of the total range is not activated. This is the " |
56 |
|
|
"activation\n" |
57 |
|
|
"equations:\n" |
58 |
|
|
"a(r) = 0.5 * ||r||^2 for lb > r > ub\n" |
59 |
|
|
"a(r) = 0. for lb <= r <= ub.", |
60 |
✓✗ |
20 |
bp::init<ActivationBounds>(bp::args("self", "bounds"), |
61 |
|
|
"Initialize the activation model.\n\n" |
62 |
|
|
":param bounds: activation bounds")) |
63 |
|
|
.def("calc", &ActivationModelQuadraticBarrier::calc, |
64 |
✓✗ |
20 |
bp::args("self", "data", "r"), |
65 |
|
|
"Compute the inequality activation.\n\n" |
66 |
|
|
":param data: activation data\n" |
67 |
✓✗ |
10 |
":param r: residual vector") |
68 |
|
|
.def("calcDiff", &ActivationModelQuadraticBarrier::calcDiff, |
69 |
✓✗ |
20 |
bp::args("self", "data", "r"), |
70 |
|
|
"Compute the derivatives of inequality activation.\n\n" |
71 |
|
|
":param data: activation data\n" |
72 |
|
|
"Note that the Hessian is constant, so we don't write again this " |
73 |
|
|
"value.\n" |
74 |
|
|
"It assumes that calc has been run first.\n" |
75 |
✓✗ |
10 |
":param r: residual vector \n") |
76 |
|
|
.def("createData", &ActivationModelQuadraticBarrier::createData, |
77 |
✓✗✓✗
|
20 |
bp::args("self"), "Create the weighted quadratic action data.") |
78 |
|
|
.add_property( |
79 |
|
|
"bounds", |
80 |
✓✗ |
10 |
bp::make_function(&ActivationModelQuadraticBarrier::get_bounds, |
81 |
|
|
bp::return_internal_reference<>()), |
82 |
✓✗ |
20 |
bp::make_function(&ActivationModelQuadraticBarrier::set_bounds), |
83 |
✓✗ |
10 |
"bounds (beta, lower and upper bounds)") |
84 |
✓✗ |
10 |
.def(CopyableVisitor<ActivationModelQuadraticBarrier>()); |
85 |
|
10 |
} |
86 |
|
|
|
87 |
|
|
} // namespace python |
88 |
|
|
} // namespace crocoddyl |