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.
Avoid auto-diff for linear IPOPT constraints (RobotLocomotion#18603)
- Loading branch information
1 parent
24dc995
commit db690b3
Showing
3 changed files
with
128 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "drake/solvers/ipopt_solver.h" | ||
#include "drake/solvers/mathematical_program.h" | ||
#include "drake/tools/performance/fixture_common.h" | ||
|
||
namespace drake { | ||
namespace solvers { | ||
namespace { | ||
|
||
static void BenchmarkIpoptSolver(benchmark::State& state) { // NOLINT | ||
// Number of decision variables. | ||
const int nx = 1000; | ||
// Create the mathematical program and the solver. | ||
MathematicalProgram prog; | ||
IpoptSolver solver; | ||
// Create decision variables. | ||
auto x = prog.NewContinuousVariables<nx>(); | ||
// Add bounding box constraints. | ||
auto lbx = -1e0 * Eigen::VectorXd::Ones(nx); | ||
auto ubx = +1e0 * Eigen::VectorXd::Ones(nx); | ||
prog.AddBoundingBoxConstraint(lbx, ubx, x); | ||
// Add random linear constraints. | ||
auto A = Eigen::MatrixXd::Random(nx, nx); | ||
auto lb = Eigen::VectorXd::Zero(nx); | ||
auto ub = 1e20 * Eigen::VectorXd::Ones(nx); | ||
prog.AddLinearConstraint(A, lb, ub, x); | ||
// Add linear equality constraints. | ||
auto Aeq = Eigen::MatrixXd::Identity(nx, nx); | ||
auto beq = Eigen::VectorXd::Zero(nx); | ||
prog.AddLinearEqualityConstraint(Aeq, beq, x); | ||
// Add a nonlinear constraint: closed unit disk. | ||
prog.AddConstraint(x.transpose() * x <= 1e0); | ||
// Add a quadratic cost. | ||
prog.AddQuadraticCost(Eigen::MatrixXd::Identity(nx, nx), | ||
Eigen::VectorXd::Zero(nx), x); | ||
|
||
// Run the solver and measure the performance. | ||
MathematicalProgramResult result; | ||
for (auto _ : state) { | ||
result = solver.Solve(prog); | ||
} | ||
// Verify the success of the solver. | ||
DRAKE_DEMAND(result.is_success()); | ||
} | ||
|
||
BENCHMARK(BenchmarkIpoptSolver); | ||
} // namespace | ||
} // namespace solvers | ||
} // 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