【问题标题】:CGAL Solves a Quadratic ProgrammingCGAL 求解二次规划
【发布时间】:2014-05-11 19:53:35
【问题描述】:

我有一个qp问题:

Minimize: -5x0 - x1 - 4x2 - 5x5 + 1000x0x2 + 1000x1x2 + 1000x0x3 
      + 1000x1x3 + 1000x0x4 +1000x1x4

Subject to: x0>=0 x1>=0 x2>=0 x3>=0 x4>=0 x5>=0
        x0+x1+x5<=5      
        x2+x3+x4<=5

答案应该是 X0=0 X1=0 X2=5 X3=0 X4=0 X5=5 和 obj=-45。

但是 CGAL 给我 X0=5 X1=0 X2=0 X3=0 X4=0 X5=0 和 obj=-25。

代码粘贴如下:

任何建议都将不胜感激。

凯莉

#include <iostream>
#include <climits>
#include <cassert>
#include <CGAL/basic.h>
#include <CGAL/QP_models.h>
#include <CGAL/QP_functions.h>
// choose exact integral type
#ifdef CGAL_USE_GMP
#include <CGAL/Gmpz.h>
typedef CGAL::Gmpz ET;
#else
#include <CGAL/MP_Float.h>
typedef CGAL::MP_Float ET;
#endif

using namespace std;

// program and solution types
typedef CGAL::Quadratic_program<int> Program;
typedef CGAL::Quadratic_program_solution<ET> Solution;

int
main(){
    Program qp (CGAL::SMALLER, true, 0.0, false, 0.0);

    qp.set_c(0, -5);
    qp.set_c(1, -1);
    qp.set_c(2, -4);
    qp.set_c(5, -5);

    int g = 1000;
    qp.set_d(2, 0, g);
    qp.set_d(2, 1, g);
    qp.set_d(3, 0, g);
    qp.set_d(3, 1, g);
    qp.set_d(4, 0, g);
    qp.set_d(4, 1, g);

    int nRow = 0;
    qp.set_a(0, nRow,  1.0);
    qp.set_a(1, nRow,  1.0);
    qp.set_a(5, nRow,  1.0);
    qp.set_b(nRow, 5);

    nRow++;
    qp.set_a(2, nRow,  1.0);
    qp.set_a(3, nRow,  1.0);
    qp.set_a(4, nRow,  1.0);
    qp.set_b(nRow, 5);

    Solution s = CGAL::solve_quadratic_program(qp, ET());
    assert (s.solves_quadratic_program(qp));
    CGAL::print_nonnegative_quadratic_program(std::cout, qp, "first_qp");

    std::cout << s;
    return 0;
}          

【问题讨论】:

  • 嗨。到目前为止,您的问题尚未得到解答。我建议您在 CGAL 讨论邮件列表中发布指向它的链接,以尝试吸引更多观众。我自己是一名 CGAL 开发人员,但我对 QP 求解器一无所知。

标签: cgal


【解决方案1】:

由于您的矩阵 D(二次目标函数)不是半正定的,因此您的结果并不令人惊讶。 CGAL 不保证收敛到全局最小值,而是收敛到局部最小值。您获得的是尊重您施加的约束的局部最小值。

如果您通过编写qp.set_l(2,true,1); qp.set_l(5,true,1);x2x5 的最小界限设置为1,您将看到您收敛到您计算的解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-03
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多