如何访问使用 Drake Toolbox 制定的优化解决方案

How to access the Optimization Solution formulated using Drake Toolbox

这里是c++新手! 终端输出中的详细说明问题已成功解决,但我无法访问解决方案。最后一行有什么问题?

drake::solvers::MathematicalProgram prog;
auto x = prog.NewContinuousVariables(n_x);

// Cost and Constraints

drake::solvers::MathematicalProgramResult result;
drake::solvers::OsqpSolver osqp_solver;
if (osqp_solver.available()) {
    // Setting solver options.
    for (int print_to_console : {0, 0}) {           //{0,1} for verbose, {0,0} for no terminal output
        drake::solvers::SolverOptions options;
        options.SetOption(drake::solvers::OsqpSolver::id(), "verbose", print_to_console);
        osqp_solver.Solve(prog, {}, options);
    }
}
const auto u = result.GetSolution(x);

另一个问题是,如果我不想选择 OSQP 并让 Drake 决定为 QP 使用哪个求解器,我该怎么做?

您需要更改线路

osqp_solver.Solve(prog, {}, options);

result = osqp_solver.Solve(prog, {}, options);

目前 result 未设置。

Another question is that what if I don't wanna choose OSQP and let Drake decide which solver to use for the QP, how can I do this?

你可以做到

const drake::solvers::MathematicalProgramResult result = drake::solvers::Solve(prog, {}, options);

Drake 会自动选择解算器。更多信息请参考https://github.com/RobotLocomotion/drake/blob/master/tutorials/mathematical_program.ipynb中的教程。它讨论了自动选择求解器还是手动选择求解器。