Skip to content
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

Add Convenience Constructor for Vector of Formulas #22634

Open
AlexandreAmice opened this issue Feb 14, 2025 · 1 comment
Open

Add Convenience Constructor for Vector of Formulas #22634

AlexandreAmice opened this issue Feb 14, 2025 · 1 comment
Labels
good first issue Thinking of contributing? These issues might be a good place to start. type: feature request

Comments

@AlexandreAmice
Copy link
Contributor

It would be nice to be able to call the following code blobs.

prog = MathematicalProgram()
x = prog.NewContinuousVariables(4, "x")
prog.AddLinearConstraint(x <= np.ones(4))
prog.AddLinearConstraint(x <= 1)
prog.AddLinearConstraint(x == np.ones(4))
prog.AddLinearConstraint(x == 1)

Currently, all four options fail because we don't support vectorized construction of Formula objects (i.e. one gets an error with just x <= np.ones(4)).

Once we have sugar for constructing vectors of Formula, one would also like to add

Binding<LinearConstraint> AddLinearEqualityConstraint(
      const Eigen::Ref<const MatrixX<symbolic::Expression>>& v,
      const Eigen::Ref<const Eigen::MatrixXd>& lb,
      const Eigen::Ref<const Eigen::MatrixXd>& ub)

to MathematicalProgram.

This makes reading code involving MathematicalPrograms easier to read. For example:

prog.AddLinearConstraint(x <= np.ones(4))
prog.AddLinearConstraint(x, -np.inf*np.ones(4), np.ones(4))

The first is nice and easy to read. The second requires me remembering which arguments should be variables vs bound, and noticing that I said AddLinearConstraint (so I have inequalities) vs AddLinearEqualityConstraint.

@AlexandreAmice AlexandreAmice added good first issue Thinking of contributing? These issues might be a good place to start. type: feature request labels Feb 14, 2025
@jdetweiler1
Copy link

Hi! I'd like to work on this issue. I’ll start implementing it today. Let me know if you have any guidance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Thinking of contributing? These issues might be a good place to start. type: feature request
Projects
None yet
Development

No branches or pull requests

2 participants