C++ CGAL二次规划包发现错误的解决方案

C++ CGAL二次规划包发现错误的解决方案,c++,cgal,quadratic-programming,mps-format,C++,Cgal,Quadratic Programming,Mps Format,我使用CGAL QP包解决以下二次问题: 我正在使用以下MPS文件来定义问题(Firstqp.MPS): 注意,我使用QUADOBJ来定义D矩阵。对于QUADOBJ,只需指定对角线上或对角线下的2D条目,对角线上的条目由对称性推导而来。然后,我将此文件馈送到解算器(首先是来自\u mps.cpp的\u qp\u): //示例:从文件中读取MPS格式的二次程序 //下面的QP是用户手册中的第一个二次程序示例 #包括 #包括 #包括 #包括 #包括 //选择精确积分类型 #ifdef CGAL_使

我使用CGAL QP包解决以下二次问题:

我正在使用以下MPS文件来定义问题(Firstqp.MPS):

注意,我使用QUADOBJ来定义D矩阵。对于QUADOBJ,只需指定对角线上或对角线下的2D条目,对角线上的条目由对称性推导而来。然后,我将此文件馈送到解算器(首先是来自\u mps.cpp的\u qp\u):

//示例:从文件中读取MPS格式的二次程序
//下面的QP是用户手册中的第一个二次程序示例
#包括
#包括
#包括
#包括
#包括
//选择精确积分类型
#ifdef CGAL_使用GMP
#包括
typedef-CGAL::Gmpz等;
#否则
#包括
typedef CGAL::MP_Float ET;
#恩迪夫
//程序和解决方案类型
typedef CGAL::来自_mps程序的二次_程序_;
typedef CGAL::二次规划解;
int main(){
std::ifstream in(“第一个流程管理程序”);
程序qp(in);//从文件中读取程序
assert(qp.is_valid());//我们应该有一个有效的mps文件
//使用ET作为精确类型求解程序
解s=CGAL::解二次规划(qp,ET());
//输出溶液

std::cout您确实应该在程序类型中使用而不是。但除此之外,ET的类型应该定义为CGAL::Gmpzf(精确浮点类型),而不是CGAL::Gmpz(精确整数类型).

对不起,帖子被弄乱了。你确实应该在程序typedef中使用double而不是int。谢谢你,Bernd。你的建议已经奏效了。为什么CGAL手册列出MP_浮动为与输入类型double对应的确切类型,但在我的情况下它不能正常工作?我指的是
NAME first_qp
ROWS
E c0
COLUMNS
x0  c0  1
x1  c0  1
x2  c0  1
x3  c0  1
x4  c0  1
x5  c0  1
x6  c0  1
x7  c0  1
x8  c0  1
RHS
rhs c0  1
BOUNDS
UP  BND  x0  0.2
UP  BND  x1  0.2
UP  BND  x2  0.2
UP  BND  x3  0.2
UP  BND  x4  0.2
UP  BND  x5  0.2
UP  BND  x6  0.2
UP  BND  x7  0.2
UP  BND  x8  0.2
QUADOBJ
x0  x0  39.07
x1  x0  25.54
x2  x0  27.29
x3  x0  28.56
x4  x0  24.38
x5  x0  10.23
x6  x0  11.12
x7  x0  15.26
x8  x0  25.17
x1  x1  38.82
x2  x1  18.11
x3  x1  20.67
x4  x1  17.20
x5  x1  8.10
x6  x1  12.41
x7  x1  9.82
x8  x1  14.69
x2  x2  39.97
x3  x2  26.82
x4  x2  22.55
x5  x2  12.81
x6  x2  10.90
x7  x2  16.17
x8  x2  26.42
x3  x3  29.00
x4  x3  24.61
x5  x3  10.37
x6  x3  10.65
x7  x3  14.93
x8  x3  23.61
x4  x4  49.71
x5  x4  7.04
x6  x4  6.20
x7  x4  17.41
x8  x4  25.87
x5  x5  12.47
x6  x5  8.21
x7  x5  7.53
x8  x5  9.73
x6  x6  19.02
x7  x6  7.47
x8  x6  7.87
x7  x7  16.04
x8  x7  14.95
x8  x8  28.90
ENDATA
// example: read quadratic program in MPS format from file
// the QP below is the first quadratic program example in the user manual
#include <iostream>
#include <fstream>
#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

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

int main() {
  std::ifstream in ("first_qp.mps");
  Program qp(in);         // read program from file
  assert (qp.is_valid()); // we should have a valid mps file

  // solve the program, using ET as the exact type
  Solution s = CGAL::solve_quadratic_program(qp, ET());

  // output solution
  std::cout << s;
  return 0;
}
typedef CGAL::Quadratic_program_from_mps<int> Program;