Skip to content

Commit

Permalink
Merge pull request #1171 from cmastalli/topic/constraints-api
Browse files Browse the repository at this point in the history
  • Loading branch information
cmastalli authored Oct 16, 2023
2 parents e3cdd07 + 8175cb3 commit 62d0eac
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 23 deletions.
10 changes: 6 additions & 4 deletions bindings/python/crocoddyl/core/action-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,13 @@ void exposeActionAbstract() {
.add_property("g_lb",
bp::make_function(&ActionModelAbstract_wrap::get_g_lb,
bp::return_internal_reference<>()),
&ActionModelAbstract_wrap::set_g_lb,
"lower bound of the inequality constraints")
.add_property("g_ub",
bp::make_function(&ActionModelAbstract_wrap::get_g_ub,
bp::return_internal_reference<>()),
&ActionModelAbstract_wrap::set_g_ub,
"upper bound of the inequality constraints")
.add_property(
"has_control_limits",
bp::make_function(&ActionModelAbstract_wrap::get_has_control_limits),
"indicates whether problem has finite control limits")
.add_property("u_lb",
bp::make_function(&ActionModelAbstract_wrap::get_u_lb,
bp::return_internal_reference<>()),
Expand All @@ -149,6 +147,10 @@ void exposeActionAbstract() {
bp::make_function(&ActionModelAbstract_wrap::get_u_ub,
bp::return_internal_reference<>()),
&ActionModelAbstract_wrap::set_u_ub, "upper control limits")
.add_property(
"has_control_limits",
bp::make_function(&ActionModelAbstract_wrap::get_has_control_limits),
"indicates whether problem has finite control limits")
.def(PrintableVisitor<ActionModelAbstract>());

bp::register_ptr_to_python<boost::shared_ptr<ActionDataAbstract> >();
Expand Down
16 changes: 9 additions & 7 deletions bindings/python/crocoddyl/core/diff-action-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,29 +148,31 @@ void exposeDifferentialActionAbstract() {
"g_lb",
bp::make_function(&DifferentialActionModelAbstract_wrap::get_g_lb,
bp::return_internal_reference<>()),
&DifferentialActionModelAbstract_wrap::set_g_lb,
"lower bound of the inequality constraints")
.add_property(
"g_ub",
bp::make_function(&DifferentialActionModelAbstract_wrap::get_g_ub,
bp::return_internal_reference<>()),
&DifferentialActionModelAbstract_wrap::set_g_ub,
"upper bound of the inequality constraints")
.add_property(
"has_control_limits",
bp::make_function(
&DifferentialActionModelAbstract_wrap::get_has_control_limits),
"indicates whether problem has finite control limits")
.add_property(
"u_lb",
bp::make_function(&DifferentialActionModelAbstract_wrap::get_u_lb,
bp::return_value_policy<bp::return_by_value>()),
bp::return_internal_reference<>()),
&DifferentialActionModelAbstract_wrap::set_u_lb,
"lower control limits")
.add_property(
"u_ub",
bp::make_function(&DifferentialActionModelAbstract_wrap::get_u_ub,
bp::return_value_policy<bp::return_by_value>()),
bp::return_internal_reference<>()),
&DifferentialActionModelAbstract_wrap::set_u_ub,
"upper control limits")
.add_property(
"has_control_limits",
bp::make_function(
&DifferentialActionModelAbstract_wrap::get_has_control_limits),
"indicates whether problem has finite control limits")
.def(PrintableVisitor<DifferentialActionModelAbstract>());

bp::register_ptr_to_python<
Expand Down
16 changes: 13 additions & 3 deletions include/crocoddyl/core/action-base.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh,
// Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh,
// University of Oxford, Heriot-Watt University
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
Expand Down Expand Up @@ -245,12 +245,12 @@ class ActionModelAbstractTpl {
/**
* @brief Return the lower bound of the inequality constraints
*/
virtual const VectorXs& get_g_lb() const;
const VectorXs& get_g_lb() const;

/**
* @brief Return the upper bound of the inequality constraints
*/
virtual const VectorXs& get_g_ub() const;
const VectorXs& get_g_ub() const;

/**
* @brief Return the control lower bound
Expand All @@ -267,6 +267,16 @@ class ActionModelAbstractTpl {
*/
bool get_has_control_limits() const;

/**
* @brief Modify the lower bound of the inequality constraints
*/
void set_g_lb(const VectorXs& g_lb);

/**
* @brief Modify the upper bound of the inequality constraints
*/
void set_g_ub(const VectorXs& g_ub);

/**
* @brief Modify the control lower bounds
*/
Expand Down
28 changes: 25 additions & 3 deletions include/crocoddyl/core/action-base.hxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh,
// Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh,
// University of Oxford, Heriot-Watt University
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
Expand Down Expand Up @@ -170,11 +170,33 @@ bool ActionModelAbstractTpl<Scalar>::get_has_control_limits() const {
return has_control_limits_;
}

template <typename Scalar>
void ActionModelAbstractTpl<Scalar>::set_g_lb(const VectorXs& g_lb) {
if (static_cast<std::size_t>(g_lb.size()) != ng_) {
throw_pretty(
"Invalid argument: "
<< "inequality lower bound has wrong dimension (it should be " +
std::to_string(ng_) + ")");
}
g_lb_ = g_lb;
}

template <typename Scalar>
void ActionModelAbstractTpl<Scalar>::set_g_ub(const VectorXs& g_ub) {
if (static_cast<std::size_t>(g_ub.size()) != ng_) {
throw_pretty(
"Invalid argument: "
<< "inequality upper bound has wrong dimension (it should be " +
std::to_string(ng_) + ")");
}
g_ub_ = g_ub;
}

template <typename Scalar>
void ActionModelAbstractTpl<Scalar>::set_u_lb(const VectorXs& u_lb) {
if (static_cast<std::size_t>(u_lb.size()) != nu_) {
throw_pretty("Invalid argument: "
<< "lower bound has wrong dimension (it should be " +
<< "control lower bound has wrong dimension (it should be " +
std::to_string(nu_) + ")");
}
u_lb_ = u_lb;
Expand All @@ -185,7 +207,7 @@ template <typename Scalar>
void ActionModelAbstractTpl<Scalar>::set_u_ub(const VectorXs& u_ub) {
if (static_cast<std::size_t>(u_ub.size()) != nu_) {
throw_pretty("Invalid argument: "
<< "upper bound has wrong dimension (it should be " +
<< "control upper bound has wrong dimension (it should be " +
std::to_string(nu_) + ")");
}
u_ub_ = u_ub;
Expand Down
16 changes: 13 additions & 3 deletions include/crocoddyl/core/diff-action-base.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh,
// Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh,
// University of Oxford, Heriot-Watt University
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
Expand Down Expand Up @@ -278,12 +278,12 @@ class DifferentialActionModelAbstractTpl {
/**
* @brief Return the lower bound of the inequality constraints
*/
virtual const VectorXs& get_g_lb() const;
const VectorXs& get_g_lb() const;

/**
* @brief Return the upper bound of the inequality constraints
*/
virtual const VectorXs& get_g_ub() const;
const VectorXs& get_g_ub() const;

/**
* @brief Return the control lower bound
Expand All @@ -300,6 +300,16 @@ class DifferentialActionModelAbstractTpl {
*/
bool get_has_control_limits() const;

/**
* @brief Modify the lower bound of the inequality constraints
*/
void set_g_lb(const VectorXs& g_lb);

/**
* @brief Modify the upper bound of the inequality constraints
*/
void set_g_ub(const VectorXs& g_ub);

/**
* @brief Modify the control lower bounds
*/
Expand Down
28 changes: 25 additions & 3 deletions include/crocoddyl/core/diff-action-base.hxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2022, LAAS-CNRS, University of Edinburgh,
// Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh,
// University of Oxford, Heriot-Watt University
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
Expand Down Expand Up @@ -68,8 +68,6 @@ void DifferentialActionModelAbstractTpl<Scalar>::quasiStatic(
assert_pretty(x.tail(state_->get_nv()).isZero(),
"The velocity input should be zero for quasi-static to work.");

const std::size_t ndx = state_->get_ndx();
VectorXs dx = VectorXs::Zero(ndx);
if (nu_ != 0) {
VectorXs du = VectorXs::Zero(nu_);
for (std::size_t i = 0; i < maxiter; ++i) {
Expand Down Expand Up @@ -169,6 +167,30 @@ bool DifferentialActionModelAbstractTpl<Scalar>::get_has_control_limits()
return has_control_limits_;
}

template <typename Scalar>
void DifferentialActionModelAbstractTpl<Scalar>::set_g_lb(
const VectorXs& g_lb) {
if (static_cast<std::size_t>(g_lb.size()) != ng_) {
throw_pretty(
"Invalid argument: "
<< "inequality lower bound has wrong dimension (it should be " +
std::to_string(ng_) + ")");
}
g_lb_ = g_lb;
}

template <typename Scalar>
void DifferentialActionModelAbstractTpl<Scalar>::set_g_ub(
const VectorXs& g_ub) {
if (static_cast<std::size_t>(g_ub.size()) != ng_) {
throw_pretty(
"Invalid argument: "
<< "inequality upper bound has wrong dimension (it should be " +
std::to_string(ng_) + ")");
}
g_ub_ = g_ub;
}

template <typename Scalar>
void DifferentialActionModelAbstractTpl<Scalar>::set_u_lb(
const VectorXs& u_lb) {
Expand Down

0 comments on commit 62d0eac

Please sign in to comment.