-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[solvers] Support Expression
s in AddBoundingBoxConstraint
#17976
Comments
Currently we can call |
I hope Vector would be supported for |
@hongkai-dai -- i agree we can do it with linear constraints already. yes, the request is to do it as a bounding box. Partly because this can be better for the solver. But also because users can (reasonably) be surprised that calling AddBoundingBoxConstraint in this case does not work. |
@RussTedrake I might have found a fix for constraint 3, see my solution here |
Commenting here to check if there's any update on whether or not vectorized constraint definitions are possible in the future (as @buoyancy99 mentioned above). |
The discussion above is a bit twisty. To be very clear about your request, is that that we bind this existing C++ function into /**
* Adds constraints represented by symbolic expressions to the program. It
* throws if <tt>lb <= v <= ub</tt> includes trivial/unsatisfiable
* constraints.
*
* @overload Binding<Constraint> AddConstraint(const symbolic::Expression& e,
* double lb, double ub)
*
* @exclude_from_pydrake_mkdoc{Not bound in pydrake.}
*/
Binding<Constraint> AddConstraint(
const Eigen::Ref<const MatrixX<symbolic::Expression>>& v,
const Eigen::Ref<const Eigen::MatrixXd>& lb,
const Eigen::Ref<const Eigen::MatrixXd>& ub); For reference, we already have this function bound (which nicely describes the semantics): /**
* Adds one row of constraint lb <= e <= ub where @p e is a symbolic
* expression.
* @throws std::exception if
* 1. <tt>lb <= e <= ub</tt> is a trivial constraint such as 1 <= 2 <= 3.
* 2. <tt>lb <= e <= ub</tt> is unsatisfiable such as 1 <= -5 <= 3
*
* @param e A symbolic expression of the decision variables.
* @param lb A scalar, the lower bound.
* @param ub A scalar, the upper bound.
*
* The resulting constraint may be a BoundingBoxConstraint, LinearConstraint,
* LinearEqualityConstraint, or ExpressionConstraint, depending on the
* arguments. Constraints of the form x == 1 (which could be created as a
* BoundingBoxConstraint or LinearEqualityConstraint) will be
* constructed as a LinearEqualityConstraint.
*/
Binding<Constraint> AddConstraint(const symbolic::Expression& e, double lb,
double ub); |
Reading the original post #17976 (comment) I don't believe |
My apologies for the confusion. Perhaps it would have been better for me to comment on #16025 instead of this issue. Binding the first example Jeremy listed would be helpful, since there are cases where it's helpful to assign different bounds to different components. (I've made use of this feature in cvxpy before.) In general, it's frustrating that we can't write expressions such as |
Per #16025 (comment) we already have
At the time we wrote the code a few years ago, that was true. Since that time, there might be new |
I had an excellent question from a student, reposted below.
Attempt 3 we already track away with #8315 and #16025. But, especially since that code is so inelegant, we definitely could support
AddBoundingBoxConstraint(lb, ub, Expression)
(orVector<Expression>
) for the special case when eachExpression
depends linearly on only oneVariable
. That’s a bit niche, but definitely doable.original question:
I was wondering if you could clear up some confusion I have about implementing different representations of constraints in a MathematicalProgram. For 3.10 I tried implementing the lower and upper bounds for the end effector position in a few ways:
Attempt 1 used a bounding box acting on an array of symbolic representations (Stack Exchange leads me to believe that this is not a valid way of using AddBoundingBoxConstraint at this time, but I wanted to confirm). Attempt 2 implemented a series of bounding box constraints, one for each position coordinate. Attempt 3 used the <= and >= operators within AddConstraint. Attempt 4 used ge() and le() instead. My naive understanding is that all these implementations should be equivalent, but only attempt 4 successfully ran without triggering an error. I have attached a code snippet (question kept private as a result) and the error messages below.
Thanks!
Attempt 1:
Attempt 2:
Attempt 3:
The text was updated successfully, but these errors were encountered: