Skip to content

Commit

Permalink
Add python binding for generic_costs and generic_constraints. (RobotL…
Browse files Browse the repository at this point in the history
  • Loading branch information
hongkai-dai authored Apr 6, 2020
1 parent 92a2bea commit 0bfd3ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bindings/pydrake/solvers/mathematicalprogram_py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@ top-level documentation for :py:mod:`pydrake.math`.
const Eigen::Ref<const VectorXDecisionVariable>&)>(
&MathematicalProgram::AddVisualizationCallback),
doc.MathematicalProgram.AddVisualizationCallback.doc)
.def("generic_constraints", &MathematicalProgram::generic_constraints,
doc.MathematicalProgram.generic_constraints.doc)
.def("linear_constraints", &MathematicalProgram::linear_constraints,
doc.MathematicalProgram.linear_constraints.doc)
.def("linear_equality_constraints",
Expand All @@ -741,6 +743,8 @@ top-level documentation for :py:mod:`pydrake.math`.
.def("bounding_box_constraints",
&MathematicalProgram::bounding_box_constraints,
doc.MathematicalProgram.bounding_box_constraints.doc)
.def("generic_costs", &MathematicalProgram::generic_costs,
doc.MathematicalProgram.generic_costs.doc)
.def("linear_costs", &MathematicalProgram::linear_costs,
doc.MathematicalProgram.linear_costs.doc)
.def("quadratic_costs", &MathematicalProgram::quadratic_costs,
Expand Down
7 changes: 7 additions & 0 deletions bindings/pydrake/solvers/test/mathematicalprogram_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,13 @@ def constraint(x):
# Verify that they can be evaluated.
self.assertAlmostEqual(cost_binding.evaluator().Eval(xstar), 0.)
self.assertAlmostEqual(constraint_binding.evaluator().Eval(xstar), 1.)
self.assertEqual(len(prog.generic_constraints()), 1)
self.assertEqual(
prog.generic_constraints()[0].evaluator(),
constraint_binding.evaluator())
self.assertEqual(len(prog.generic_costs()), 1)
self.assertEqual(
prog.generic_costs()[0].evaluator(), cost_binding.evaluator())

def test_addcost_symbolic(self):
prog = mp.MathematicalProgram()
Expand Down

0 comments on commit 0bfd3ea

Please sign in to comment.