【问题标题】:drake gurobi cannot handle quadratic constraintdrake gurobi 无法处理二次约束
【发布时间】:2021-03-02 16:59:24
【问题描述】:

我目前正在对优化问题实施简单的二次约束。 Gurobi's website 表示可以实现二次约束。 drake 没有使用 Gurobi 的这个约束的接口吗?

代码如下。

#include <Eigen/Dense>
#include <math.h>
#include <iostream>

#include "drake/solvers/mathematical_program.h"
#include "drake/solvers/solve.h"
#include "drake/solvers/gurobi_solver.h"
#include "drake/solvers/scs_solver.h"

using namespace std;
using namespace Eigen;
using namespace drake;

int main(){
    solvers::MathematicalProgram prog; 

    // Instantiate the decision variables
    solvers::VectorXDecisionVariable x = prog.NewContinuousVariables(2, "x");

    // Define constraints 
    for(int i = 0; i < 2; i++){
      prog.AddConstraint(x[i]*x[i] <= 2); //Replacing this with a linear constraint 
                                          //such as prog.AddLinearConstraint(-5 <= x[i] && x[i] <= 5); 
                                          //will work
    }

    // Define the cost
    MatrixXd Q(2,2);
    Q << 2, 1,
         1, 4;
    VectorXd b(2);
    b << 0, 3;
    double c = 1.0;
    prog.AddQuadraticCost(Q, b, c, x);

    solvers::GurobiSolver solver;
    cout << "Gurobi available? " << solver.is_enabled() << endl;

    auto result = solver.Solve(prog);
    cout << "Is optimization successful?" << result.is_success() << endl;
    cout << "Optimal x: " << result.GetSolution().transpose() << endl;
    cout << "solver is: " << result.get_solver_id().name() << endl;
    cout << "computation time is: " << result.get_solver_details<solvers::GurobiSolver>().optimizer_time;

    return 0;
}

【问题讨论】:

    标签: drake


    【解决方案1】:

    Drake 当前(有意)不支持二次约束。为了获得更好的求解器性能,我建议重新制定没有二次约束但具有二阶锥约束的优化问题。

    首先是二次约束

    xᵀx <= a²
    

    这可视为洛伦兹锥约束

    (y, x) is in the Lorentz cone
    y = a
    

    在 Drake 中,您可以将此约束添加为

    prog.AddLorentzConeConstraint((drake::VectorX<drake::symbolic::Expression>(x.rows() + 1) << a, x).finished());
    

    对于二次成本

    min 0.5xᵀQx + bᵀx + c
    

    您也可以将其重新表述为带有旋转洛伦兹锥约束的线性成本

    min z
    z >= 0.5xᵀQx + bᵀx + c
    

    在 Drake 中,代码是

    z = prog.NewContinuousVariables<1>()(0);
    prog.AddLinearCost(z);
    prog.AddRotatedLorentzConeConstraint(symbolic::Expression(z), symbolic::Expression(1), 0.5 * x.dot(Q * x) + b.dot(x) + c);
    

    我们更喜欢洛伦兹锥约束而不是二次约束二次规划 (QCQP) 的原因是,使用洛伦兹锥约束,您最终会遇到二阶锥优化问题 (SOCP),这就其对偶形式而言,优化问题有很多很好的特征。您可以阅读论文 Alizadeh 的 paper 了解更多详细信息。 Mosek 还推荐 SOCP 而不是 QCQP https://docs.mosek.com/9.2/rmosek/prob-def-quadratic.html#a-recommendation

    【讨论】:

    • 感谢您的回复和解释。我也会确保阅读您建议的论文。
    【解决方案2】:

    https://github.com/RobotLocomotion/drake/issues/6341 上的(尚未实现的)功能请求可能是您正在寻找的?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-31
      • 2020-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多