From 293d0597d98ff23c3d00a421863b3b2a41346a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernd=20G=C3=A4rtner?= Date: Thu, 2 Mar 2006 17:12:04 +0000 Subject: [PATCH] - added examples dir and fixed example from doc --- .gitattributes | 1 + QP_solver/examples/small_example.C | 57 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 QP_solver/examples/small_example.C diff --git a/.gitattributes b/.gitattributes index 6b8592fb650..fb02869df99 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1263,6 +1263,7 @@ Principal_component_analysis/demo/Principal_component_analysis/windows/3d/res/id Principal_component_analysis/demo/Principal_component_analysis/windows/3d/res/idb7.bmp -text svneol=unset#unset Principal_component_analysis/demo/Principal_component_analysis/windows/3d/res/idb8.bmp -text svneol=unset#unset Principal_component_analysis/test/Principal_component_analysis/fitting_3.C -text +QP_solver/examples/small_example.C -text QP_solver/include/CGAL/QP_solver/Bounds.C -text QP_solver/test/QP_solver/README -text QP_solver/test/QP_solver/create_test_solver_cin -text diff --git a/QP_solver/examples/small_example.C b/QP_solver/examples/small_example.C new file mode 100644 index 00000000000..5c2824799ed --- /dev/null +++ b/QP_solver/examples/small_example.C @@ -0,0 +1,57 @@ + +#include +#include +#include +#include + +struct Traits { + enum Row_type {LESS_EQUAL, EQUAL, GREATER_EQUAL}; + typedef CGAL::Double ET; + + typedef double **A_iterator; + typedef double *B_iterator; + typedef double *C_iterator; + typedef double **D_iterator; + typedef bool *FL_iterator; + typedef bool *FU_iterator; + typedef double *L_iterator; + typedef double *U_iterator; + typedef Row_type *Row_type_iterator; + + typedef CGAL::Tag_false Is_linear; + typedef CGAL::Tag_true Is_symmetric; + typedef CGAL::Tag_true Has_equalities_only_and_full_rank; + typedef CGAL::Tag_false Is_in_standard_form; +}; + +typedef CGAL::QP_solver Solver; + + +int main() { + double c[] = {0, 3}; + double D_row_0[] = {1, 0}; + double D_row_1[] = {0, 0}; + double A_col_0[] = {1}; + double A_col_1[] = {2}; + double b[] = {1}; + + Traits::Row_type rt[] = {Traits::EQUAL}; + bool fl[] = {true, true}; + bool fu[] = {false, true}; + double l[] = {0, 0}; + double u[] = {0, 1}; + + double *rows_of_D[] = {D_row_0, D_row_1}; + double *cols_of_A[] = {A_col_0, A_col_1}; + + Solver solver(2, 1, cols_of_A, b, c, rows_of_D, rt, fl, l, fu, u); + + if (solver.status() != Solver::INFEASIBLE) { + std::cout << "Optimal feasible solution x: "; + for (Solver::Variable_value_iterator it = solver.variables_value_begin(); it != solver.variables_value_end(); ++it) + std::cout << *it << " "; + std::cout << "f(x): " << solver.solution() << std::endl; + } + + return 0; +}