00001 #include "cgal_qp.h"
00002
00003 #include "math/matrix.h"
00004
00005 #include "debug.h"
00006
00007
00008 #include <iostream>
00009 #include <cassert>
00010 #include <CGAL/basic.h>
00011 #include <CGAL/QP_models.h>
00012 #include <CGAL/QP_functions.h>
00013
00014
00015 #ifdef CGAL_USE_GMP
00016 #include <CGAL/Gmpz.h>
00017 typedef CGAL::Gmpz ET;
00018 #else
00019 #include <CGAL/MP_Float.h>
00020 typedef CGAL::MP_Float ET;
00021 #endif
00022
00023
00024 typedef CGAL::Quadratic_program<double> Program;
00025 typedef CGAL::Quadratic_program_solution<ET> Solution;
00026
00034 int cgalNNQPSolverWrapper(const Matrix &Q, const Matrix &Eq, const Matrix &b,
00035 const Matrix &InEq, const Matrix &ib, Matrix &sol)
00036 {
00037 DBGA("CGAL QP Wrapper");
00038
00039 Program qp (CGAL::SMALLER, true, 0, false, 0);
00040
00041
00042 for (int i=0; i<Eq.rows(); i++) {
00043 for(int j=0; j<Eq.cols(); j++) {
00044 qp.set_a(j, i, Eq.elem(i,j));
00045 }
00046 qp.set_b(i, b.elem(i,0));
00047 qp.set_r(i, CGAL::EQUAL);
00048 }
00049
00050 for (int i=0; i<InEq.rows(); i++) {
00051 int eqi = i + Eq.rows();
00052 for (int j=0; j<InEq.cols(); j++) {
00053 qp.set_a(j, eqi, InEq.elem(i,j));
00054 }
00055 qp.set_b(eqi, ib.elem(i,0));
00056
00057 }
00058
00059
00060 for (int i=0; i<Q.rows(); i++) {
00061 for (int j=0; j<=i; j++) {
00062 qp.set_d(i, j, 2.0*Q.elem(i,j));
00063 }
00064 }
00065
00066
00067
00068 Solution s = CGAL::solve_nonnegative_quadratic_program(qp, ET());
00069 assert (s.solves_nonnegative_quadratic_program(qp));
00070
00071
00072 std::cout << s;
00073 return 1;
00074 }