forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mathematical program additional bindings (RobotLocomotion#21754)
Adds some missing python bindings to mathematical program.
- Loading branch information
1 parent
bb415eb
commit b9de456
Showing
9 changed files
with
284 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "drake/bindings/pydrake/common/eigen_pybind.h" | ||
#include "drake/bindings/pydrake/documentation_pybind.h" | ||
#include "drake/bindings/pydrake/pydrake_pybind.h" | ||
#include "drake/bindings/pydrake/solvers/solvers_py.h" | ||
#include "drake/solvers/mathematical_program.h" | ||
|
||
namespace drake { | ||
namespace pydrake { | ||
namespace internal { | ||
void DefineProgramAttribute(py::module m) { | ||
// NOLINTNEXTLINE(build/namespaces): Emulate placement in namespace. | ||
using namespace drake::solvers; | ||
constexpr auto& doc = pydrake_doc.drake.solvers; | ||
py::enum_<ProgramAttribute>(m, "ProgramAttribute", doc.ProgramAttribute.doc) | ||
.value("kGenericCost", ProgramAttribute::kGenericCost, | ||
doc.ProgramAttribute.kGenericCost.doc) | ||
.value("kGenericConstraint", ProgramAttribute::kGenericConstraint, | ||
doc.ProgramAttribute.kGenericConstraint.doc) | ||
.value("kQuadraticCost", ProgramAttribute::kQuadraticCost, | ||
doc.ProgramAttribute.kQuadraticCost.doc) | ||
.value("kQuadraticConstraint", ProgramAttribute::kQuadraticConstraint, | ||
doc.ProgramAttribute.kQuadraticConstraint.doc) | ||
.value("kLinearCost", ProgramAttribute::kLinearCost, | ||
doc.ProgramAttribute.kLinearCost.doc) | ||
.value("kLinearConstraint", ProgramAttribute::kLinearConstraint, | ||
doc.ProgramAttribute.kLinearConstraint.doc) | ||
.value("kLinearEqualityConstraint", | ||
ProgramAttribute::kLinearEqualityConstraint, | ||
doc.ProgramAttribute.kLinearEqualityConstraint.doc) | ||
.value("kLinearComplementarityConstraint", | ||
ProgramAttribute::kLinearComplementarityConstraint, | ||
doc.ProgramAttribute.kLinearComplementarityConstraint.doc) | ||
.value("kLorentzConeConstraint", ProgramAttribute::kLorentzConeConstraint, | ||
doc.ProgramAttribute.kLorentzConeConstraint.doc) | ||
.value("kRotatedLorentzConeConstraint", | ||
ProgramAttribute::kRotatedLorentzConeConstraint, | ||
doc.ProgramAttribute.kRotatedLorentzConeConstraint.doc) | ||
.value("kPositiveSemidefiniteConstraint", | ||
ProgramAttribute::kPositiveSemidefiniteConstraint, | ||
doc.ProgramAttribute.kPositiveSemidefiniteConstraint.doc) | ||
.value("kExponentialConeConstraint", | ||
ProgramAttribute::kExponentialConeConstraint, | ||
doc.ProgramAttribute.kExponentialConeConstraint.doc) | ||
.value("kL2NormCost", ProgramAttribute::kL2NormCost, | ||
doc.ProgramAttribute.kL2NormCost.doc) | ||
.value("kBinaryVariable", ProgramAttribute::kBinaryVariable, | ||
doc.ProgramAttribute.kBinaryVariable.doc) | ||
.value("kCallback", ProgramAttribute::kCallback, | ||
doc.ProgramAttribute.kCallback.doc); | ||
|
||
py::enum_<ProgramType>(m, "ProgramType", doc.ProgramType.doc) | ||
.value("kLP", ProgramType::kLP, doc.ProgramType.kLP.doc) | ||
.value("kQP", ProgramType::kQP, doc.ProgramType.kQP.doc) | ||
.value("kSOCP", ProgramType::kSOCP, doc.ProgramType.kSOCP.doc) | ||
.value("kSDP", ProgramType::kSDP, doc.ProgramType.kSDP.doc) | ||
.value("kGP", ProgramType::kGP, doc.ProgramType.kGP.doc) | ||
.value("kCGP", ProgramType::kCGP, doc.ProgramType.kCGP.doc) | ||
.value("kMILP", ProgramType::kMILP, doc.ProgramType.kMILP.doc) | ||
.value("kMIQP", ProgramType::kMIQP, doc.ProgramType.kMIQP.doc) | ||
.value("kMISOCP", ProgramType::kMISOCP, doc.ProgramType.kMISOCP.doc) | ||
.value("kMISDP", ProgramType::kMISDP, doc.ProgramType.kMISDP.doc) | ||
.value("kQuadraticCostConicConstraint", | ||
ProgramType::kQuadraticCostConicConstraint, | ||
doc.ProgramType.kQuadraticCostConicConstraint.doc) | ||
.value("kNLP", ProgramType::kNLP, doc.ProgramType.kNLP.doc) | ||
.value("kLCP", ProgramType::kLCP, doc.ProgramType.kLCP.doc) | ||
.value("kUnknown", ProgramType::kUnknown, doc.ProgramType.kUnknown.doc); | ||
} | ||
} // namespace internal | ||
} // namespace pydrake | ||
} // namespace drake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import unittest | ||
from pydrake.solvers import ( | ||
ProgramAttribute, | ||
ProgramType | ||
) | ||
|
||
|
||
class TestProgramAttribute(unittest.TestCase): | ||
def test_program_attribute_enum(self): | ||
# This list checks that all the enums exist to ensure that none are | ||
# deleted by accident. | ||
enum_expected = [ProgramAttribute.kGenericCost, | ||
ProgramAttribute.kGenericConstraint, | ||
ProgramAttribute.kQuadraticCost, | ||
ProgramAttribute.kQuadraticConstraint, | ||
ProgramAttribute.kLinearCost, | ||
ProgramAttribute.kLinearConstraint, | ||
ProgramAttribute.kLinearEqualityConstraint, | ||
ProgramAttribute.kLinearComplementarityConstraint, | ||
ProgramAttribute.kLorentzConeConstraint, | ||
ProgramAttribute.kRotatedLorentzConeConstraint, | ||
ProgramAttribute.kPositiveSemidefiniteConstraint, | ||
ProgramAttribute.kExponentialConeConstraint, | ||
ProgramAttribute.kL2NormCost, | ||
ProgramAttribute.kBinaryVariable, | ||
ProgramAttribute.kCallback, | ||
] | ||
|
||
|
||
class TestProgramType(unittest.TestCase): | ||
def test_program_attribute_enum(self): | ||
# This list checks that all the enums exist to ensure that none are | ||
# deleted by accident. | ||
enum_expected = [ProgramType.kLP, | ||
ProgramType.kQP, | ||
ProgramType.kSOCP, | ||
ProgramType.kSDP, | ||
ProgramType.kGP, | ||
ProgramType.kCGP, | ||
ProgramType.kMILP, | ||
ProgramType.kMIQP, | ||
ProgramType.kMISOCP, | ||
ProgramType.kMISDP, | ||
ProgramType.kQuadraticCostConicConstraint, | ||
ProgramType.kNLP, | ||
ProgramType.kLCP, | ||
ProgramType.kUnknown | ||
] |