aligator  0.9.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
expose-problem.cpp
Go to the documentation of this file.
1
7#include <eigenpy/deprecation-policy.hpp>
8
9namespace aligator {
10namespace python {
12 using context::ConstVectorRef;
15 using context::Scalar;
21
22 using PolyUnaryFunction = xyz::polymorphic<UnaryFunction>;
23 using PolyFunction = xyz::polymorphic<context::StageFunction>;
24 using PolyStage = xyz::polymorphic<StageModel>;
25 using PolyCost = xyz::polymorphic<CostAbstract>;
26 using PolyManifold = xyz::polymorphic<Manifold>;
27 using PolySet = xyz::polymorphic<context::ConstraintSet>;
28
29 bp::class_<TrajOptProblem>("TrajOptProblem", "Define a shooting problem.",
30 bp::no_init)
31 .def(
32 bp::init<PolyUnaryFunction, const std::vector<PolyStage> &, PolyCost>(
33 "Constructor adding the initial constraint explicitly.",
34 ("self"_a, "init_constraint", "stages", "term_cost")))
35 .def(bp::init<ConstVectorRef, const std::vector<PolyStage> &, PolyCost>(
36 "Constructor for an initial value problem.",
37 ("self"_a, "x0", "stages", "term_cost")))
38 .def(bp::init<PolyUnaryFunction, PolyCost>(
39 "Constructor adding the initial constraint explicitly (without "
40 "stages).",
41 ("self"_a, "init_constraint", "term_cost")))
42 .def(bp::init<ConstVectorRef, const int, PolyManifold, PolyCost>(
43 "Constructor for an initial value problem (without pre-allocated "
44 "stages).",
45 ("self"_a, "x0", "nu", "space", "term_cost")))
46 .def<void (TrajOptProblem::*)(const PolyStage &)>(
47 "addStage", &TrajOptProblem::addStage, ("self"_a, "new_stage"),
48 "Add a stage to the problem.")
49 .def_readonly("stages", &TrajOptProblem::stages_,
50 "Stages of the shooting problem.")
51 .def_readwrite("term_cost", &TrajOptProblem::term_cost_,
52 "Problem terminal cost.")
53 .def_readwrite("term_constraints", &TrajOptProblem::term_cstrs_,
54 "Set of terminal constraints.")
55 .add_property("num_steps", &TrajOptProblem::numSteps,
56 "Number of stages in the problem.CostPtr")
57 .add_property("x0_init", &TrajOptProblem::getInitState,
58 &TrajOptProblem::setInitState, "Initial state.")
59 .add_property("init_constraint", &TrajOptProblem::init_constraint_,
60 "Get initial state constraint.")
61 .def<void (TrajOptProblem::*)(const context::StageConstraint &)>(
62 "addTerminalConstraint", &TrajOptProblem::addTerminalConstraint,
63 eigenpy::deprecated_member<>("This method is deprecated (because "
64 "StageConstraint has been deprecated)."),
65 ("self"_a, "constraint"), "Add a terminal constraint.")
66 .def<void (TrajOptProblem::*)(const PolyFunction &, const PolySet &)>(
67 "addTerminalConstraint", &TrajOptProblem::addTerminalConstraint,
68 ("self"_a, "func", "set"), "Add a terminal constraint.")
69 .def("removeTerminalConstraint",
70 &TrajOptProblem::removeTerminalConstraints,
71 eigenpy::deprecated_member<>(
72 "This method is deprecated (due to a typo which was fixed). Use "
73 "removeTerminalConstraints instead."),
74 ("self"_a), "Remove all terminal constraints.")
75 .def("removeTerminalConstraints",
76 &TrajOptProblem::removeTerminalConstraints, "self"_a,
77 "Remove all terminal constraints.")
78 .def("evaluate", &TrajOptProblem::evaluate,
79 ("self"_a, "xs", "us", "prob_data", "num_threads"_a = 1),
80 "Evaluate the problem costs, dynamics, and constraints.")
81 .def("computeDerivatives", &TrajOptProblem::computeDerivatives,
82 ("self"_a, "xs", "us", "prob_data", "num_threads"_a = 1,
83 "compute_second_order"_a = true),
84 "Evaluate the problem derivatives. Call `evaluate()` first.")
85 .def("replaceStageCircular", &TrajOptProblem::replaceStageCircular,
86 ("self"_a, "model"),
87 "Circularly replace the last stage in the problem, dropping the "
88 "first stage.")
89 .def("checkIntegrity", &TrajOptProblem::checkIntegrity, ("self"_a));
90
91 bp::def("computeTrajectoryCost", computeTrajectoryCost<Scalar>,
92 ("problem_data"_a),
93 "Compute trajectory cost (call evaluate() first!)");
94
95 bp::class_<TrajOptData>(
96 "TrajOptData", "Data struct for shooting problems.",
97 bp::init<const TrajOptProblem &>(("self"_a, "problem")))
98 .def_readwrite("init_data", &TrajOptData::init_data,
99 "Initial stage contraint data.")
100 .def_readwrite("cost", &TrajOptData::cost_,
101 "Current cost of the TO problem.")
102 .def_readwrite("term_cost", &TrajOptData::term_cost_data,
103 "Terminal cost data.")
104 .def_readwrite("term_constraint", &TrajOptData::term_cstr_data,
105 "Terminal constraint data.")
106 .def_readonly("stage_data", &TrajOptData::stage_data,
107 "Data for each stage.");
108}
109
110} // namespace python
111} // namespace aligator
ManifoldAbstractTpl< Scalar > Manifold
Definition context.hpp:14
xyz::polymorphic< StageFunction > PolyFunction
xyz::polymorphic< UnaryFunction > PolyUnaryFunction
xyz::polymorphic< CostAbstract > PolyCost
void exposeProblem()
Expose TrajOptProblem.
xyz::polymorphic< context::ConstraintSet > PolySet
xyz::polymorphic< Manifold > PolyManifold
Main package namespace.
Scalar computeTrajectoryCost(const TrajOptDataTpl< Scalar > &problem_data)
Helper for computing the trajectory cost (from pre-computed problem data).
Stage costs for control problems.
Definition fwd.hpp:65
Data struct for stage models StageModelTpl.
Definition fwd.hpp:96
A stage in the control problem.
Definition fwd.hpp:93
Problem data struct.
Definition fwd.hpp:110
Trajectory optimization problem.
Definition fwd.hpp:107
Represents unary functions of the form , with no control (or next-state) arguments.
Definition fwd.hpp:59