From ce80f2f8db943f6fb6af7704e400780adadfa284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernd=20G=C3=A4rtner?= Date: Sat, 14 Apr 2007 15:39:55 +0000 Subject: [PATCH] - _from_pointer models removed (they are useless as well) - fixed and added more examples, and referred to them from manual --- .gitattributes | 20 ++- .../QP_solver_ref/LinearProgramInterface.tex | 16 ++- .../Linear_program_from_iterators.tex | 27 +++- .../Linear_program_from_pointers.tex | 48 ------- QP_solver/doc_tex/QP_solver_ref/MPSFormat.tex | 11 +- .../NonnegativeLinearProgramInterface.tex | 16 ++- .../NonnegativeQuadraticProgramInterface.tex | 14 +- ...negative_linear_program_from_iterators.tex | 23 +++- ...nnegative_linear_program_from_pointers.tex | 45 ------- ...ative_quadratic_program_from_iterators.tex | 26 +++- ...gative_quadratic_program_from_pointers.tex | 46 ------- .../QuadraticProgramInterface.tex | 15 ++- .../QP_solver_ref/Quadratic_program.tex | 26 +++- .../Quadratic_program_from_iterators.tex | 29 +++- .../Quadratic_program_from_mps.tex | 13 +- .../Quadratic_program_from_pointers.tex | 51 ------- .../Quadratic_program_solution.tex | 25 +++- QP_solver/doc_tex/QP_solver_ref/intro.tex | 21 +-- QP_solver/doc_tex/QP_solver_ref/main.tex | 4 - .../make_linear_program_from_iterators.tex | 26 ++-- ...negative_linear_program_from_iterators.tex | 15 ++- ...ative_quadratic_program_from_iterators.tex | 19 ++- .../make_quadratic_program_from_iterators.tex | 29 ++-- .../QP_solver_ref/print_linear_program.tex | 8 ++ .../print_nonnegative_linear_program.tex | 9 ++ .../print_nonnegative_quadratic_program.tex | 8 ++ .../QP_solver_ref/print_quadratic_program.tex | 9 ++ .../QP_solver_ref/solve_linear_program.tex | 21 ++- .../solve_nonnegative_linear_program.tex | 22 ++- .../solve_nonnegative_quadratic_program.tex | 21 ++- .../QP_solver_ref/solve_quadratic_program.tex | 21 ++- .../QP_solver/convex_hull_containment.cpp | 2 +- QP_solver/examples/QP_solver/first_lp.cpp | 30 ++--- QP_solver/examples/QP_solver/first_lp.mps | 18 +++ .../QP_solver/first_lp_from_iterators.cpp | 60 +++++++++ .../examples/QP_solver/first_lp_from_mps.cpp | 40 ++++++ .../QP_solver/first_nonnegative_lp.cpp | 23 ++-- .../QP_solver/first_nonnegative_lp.mps | 15 +++ .../first_nonnegative_lp_from_iterators.cpp | 51 +++++++ .../first_nonnegative_lp_from_mps.cpp | 41 ++++++ .../QP_solver/first_nonnegative_qp.cpp | 29 ++-- .../QP_solver/first_nonnegative_qp.mps | 19 +++ .../first_nonnegative_qp_from_iterators.cpp | 56 ++++++++ .../first_nonnegative_qp_from_mps.cpp | 40 ++++++ QP_solver/examples/QP_solver/first_qp.cpp | 34 ++--- QP_solver/examples/QP_solver/first_qp.mps | 21 +++ .../QP_solver/first_qp_from_iterators.cpp | 64 +++++++++ .../examples/QP_solver/first_qp_from_mps.cpp | 39 ++++++ .../QP_solver/important_variables.cpp | 43 +++--- .../examples/QP_solver/print_first_lp.cpp | 24 ++++ .../QP_solver/print_first_nonnegative_lp.cpp | 23 ++++ .../QP_solver/print_first_nonnegative_qp.cpp | 25 ++++ .../examples/QP_solver/print_first_qp.cpp | 26 ++++ QP_solver/include/CGAL/QP_models.h | 127 +----------------- .../test/QP_solver/test_default_bounds.cpp | 33 +++-- QP_solver/test/QP_solver/test_random_qp.cpp | 12 +- 56 files changed, 1039 insertions(+), 540 deletions(-) delete mode 100644 QP_solver/doc_tex/QP_solver_ref/Linear_program_from_pointers.tex delete mode 100644 QP_solver/doc_tex/QP_solver_ref/Nonnegative_linear_program_from_pointers.tex delete mode 100644 QP_solver/doc_tex/QP_solver_ref/Nonnegative_quadratic_program_from_pointers.tex delete mode 100644 QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_pointers.tex create mode 100644 QP_solver/examples/QP_solver/first_lp.mps create mode 100644 QP_solver/examples/QP_solver/first_lp_from_iterators.cpp create mode 100644 QP_solver/examples/QP_solver/first_lp_from_mps.cpp create mode 100644 QP_solver/examples/QP_solver/first_nonnegative_lp.mps create mode 100644 QP_solver/examples/QP_solver/first_nonnegative_lp_from_iterators.cpp create mode 100644 QP_solver/examples/QP_solver/first_nonnegative_lp_from_mps.cpp create mode 100644 QP_solver/examples/QP_solver/first_nonnegative_qp.mps create mode 100644 QP_solver/examples/QP_solver/first_nonnegative_qp_from_iterators.cpp create mode 100644 QP_solver/examples/QP_solver/first_nonnegative_qp_from_mps.cpp create mode 100644 QP_solver/examples/QP_solver/first_qp.mps create mode 100644 QP_solver/examples/QP_solver/first_qp_from_iterators.cpp create mode 100644 QP_solver/examples/QP_solver/first_qp_from_mps.cpp create mode 100644 QP_solver/examples/QP_solver/print_first_lp.cpp create mode 100644 QP_solver/examples/QP_solver/print_first_nonnegative_lp.cpp create mode 100644 QP_solver/examples/QP_solver/print_first_nonnegative_qp.cpp create mode 100644 QP_solver/examples/QP_solver/print_first_qp.cpp diff --git a/.gitattributes b/.gitattributes index 6e2a92b361c..4f099f9d201 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1837,15 +1837,11 @@ QP_solver/doc_tex/QP_solver/first_qp.gif -text svneol=unset#image/gif QP_solver/doc_tex/QP_solver/first_qp.pdf -text svneol=unset#application/pdf QP_solver/doc_tex/QP_solver/qp.png -text QP_solver/doc_tex/QP_solver_ref/Linear_program_from_iterators.tex -text -QP_solver/doc_tex/QP_solver_ref/Linear_program_from_pointers.tex -text QP_solver/doc_tex/QP_solver_ref/MPSFormat.tex -text QP_solver/doc_tex/QP_solver_ref/Nonnegative_linear_program_from_iterators.tex -text -QP_solver/doc_tex/QP_solver_ref/Nonnegative_linear_program_from_pointers.tex -text QP_solver/doc_tex/QP_solver_ref/Nonnegative_quadratic_program_from_iterators.tex -text -QP_solver/doc_tex/QP_solver_ref/Nonnegative_quadratic_program_from_pointers.tex -text QP_solver/doc_tex/QP_solver_ref/Quadratic_program.tex -text QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_mps.tex -text -QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_pointers.tex -text QP_solver/doc_tex/QP_solver_ref/Quadratic_program_solution.tex -text QP_solver/doc_tex/QP_solver_ref/make_linear_program_from_iterators.tex -text QP_solver/doc_tex/QP_solver_ref/make_nonnegative_linear_program_from_iterators.tex -text @@ -1861,10 +1857,26 @@ QP_solver/doc_tex/QP_solver_ref/solve_nonnegative_quadratic_program.tex -text QP_solver/doc_tex/QP_solver_ref/solve_quadratic_program.tex -text QP_solver/examples/QP_solver/double_qp_solver.cin -text QP_solver/examples/QP_solver/double_qp_solver.data -text +QP_solver/examples/QP_solver/first_lp.cpp -text +QP_solver/examples/QP_solver/first_lp.mps -text +QP_solver/examples/QP_solver/first_lp_from_mps.cpp -text +QP_solver/examples/QP_solver/first_nonnegative_lp.cpp -text +QP_solver/examples/QP_solver/first_nonnegative_lp.mps -text +QP_solver/examples/QP_solver/first_nonnegative_lp_from_mps.cpp -text +QP_solver/examples/QP_solver/first_nonnegative_qp.cpp -text +QP_solver/examples/QP_solver/first_nonnegative_qp.mps -text +QP_solver/examples/QP_solver/first_nonnegative_qp_from_mps.cpp -text +QP_solver/examples/QP_solver/first_qp.cpp -text +QP_solver/examples/QP_solver/first_qp.mps -text +QP_solver/examples/QP_solver/first_qp_from_mps.cpp -text QP_solver/examples/QP_solver/infeasibility_certificate.cpp -text QP_solver/examples/QP_solver/integer_qp_solver.cin -text QP_solver/examples/QP_solver/integer_qp_solver.data -text QP_solver/examples/QP_solver/optimality_certificate.cpp -text +QP_solver/examples/QP_solver/print_first_lp.cpp -text +QP_solver/examples/QP_solver/print_first_nonnegative_lp.cpp -text +QP_solver/examples/QP_solver/print_first_nonnegative_qp.cpp -text +QP_solver/examples/QP_solver/print_first_qp.cpp -text QP_solver/examples/QP_solver/rational_qp_solver.cin -text QP_solver/examples/QP_solver/rational_qp_solver.data -text QP_solver/examples/QP_solver/unboundedness_certificate.cpp -text diff --git a/QP_solver/doc_tex/QP_solver_ref/LinearProgramInterface.tex b/QP_solver/doc_tex/QP_solver_ref/LinearProgramInterface.tex index 80370efd83a..b0b1e1cccf0 100644 --- a/QP_solver/doc_tex/QP_solver_ref/LinearProgramInterface.tex +++ b/QP_solver/doc_tex/QP_solver_ref/LinearProgramInterface.tex @@ -30,10 +30,10 @@ iterators over the program data, see below. The program therefore comes in \emph{dense} representation which includes zero entries. \ccHasModels -\ccc{CGAL::Linear_program}\\ -\ccc{CGAL::Linear_program_from_iterators}\\ -\ccc{CGAL::Linear_program_from_pointers}\\ -\ccc{CGAL::Linear_program_from_mps}\\ +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps}\\ +\ccc{Linear_program_from_iterators} + \ccTypes @@ -119,6 +119,14 @@ respectively, for \ccc{A_iterator}) must be convertible to some common \ccc{IntegralDomain} \ccc{ET}. \ccSeeAlso +The models + +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps}\\ +\ccc{Linear_program_from_iterators} + +and the other concepts + \ccc{QuadraticProgramInterface}\\ \ccc{NonnegativeQuadraticProgramInterface}\\ \ccc{NonnegativeLinearProgramInterface} diff --git a/QP_solver/doc_tex/QP_solver_ref/Linear_program_from_iterators.tex b/QP_solver/doc_tex/QP_solver_ref/Linear_program_from_iterators.tex index cd673787b76..1d523191e3f 100644 --- a/QP_solver/doc_tex/QP_solver_ref/Linear_program_from_iterators.tex +++ b/QP_solver/doc_tex/QP_solver_ref/Linear_program_from_iterators.tex @@ -31,6 +31,13 @@ This class is simply a wrapper for existing iterators, and it does not copy the program data (if you need a copy, you may use the class \ccc{Linear_program}). +It frequently happens that all values in one of the vectors from +above are the same, for example if the system $Ax\qprel b$ is +actually a system of equations $Ax=b$. To get an iterator over such a +vector, it is not necessary to store multiple copies of the value in +some container; an instance of the class \ccc{Const_oneset_iterator}, +constructed from the value in question, does the job more efficiently. + \ccIsModel \ccc{LinearProgramInterface} @@ -49,11 +56,23 @@ copy the program data (if you need a copy, you may use the class const U_it& u, const C_it& c, const std::iterator_traitsvalue_type& c0 = 0 - )}{constructs \ccVar\ from given random-access iterators and the constant \ccc{c0}. The passed iterators are merely stored, no copying of the program data takes place. } + )}{constructs \ccVar\ from given random-access iterators and the constant \ccc{c0}. The passed iterators are merely stored, no copying of the program data takes place. How these iterators are supposed to encode the linear program is +described in \ccc{LinearProgramInterface}. } + +\ccExample + +\ccReferToExampleCode{QP_solver/first_lp_from_iterators.cpp} + +The following example for the simpler model +\ccc{Nonnegative_linear_program_from_iterators} +should give you a flavor of the use of this +model in practice. + +\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp.h} \ccSeeAlso -\ccc{Linear_program}\\ -\ccc{Linear_program_from_pointers}\\ -\ccc{Linear_program_from_mps} +\ccc{LinearProgramInterface} +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps} \end{ccRefClass} diff --git a/QP_solver/doc_tex/QP_solver_ref/Linear_program_from_pointers.tex b/QP_solver/doc_tex/QP_solver_ref/Linear_program_from_pointers.tex deleted file mode 100644 index fb9da99f553..00000000000 --- a/QP_solver/doc_tex/QP_solver_ref/Linear_program_from_pointers.tex +++ /dev/null @@ -1,48 +0,0 @@ -\begin{ccRefClass}{Linear_program_from_pointers} - -\ccInclude{CGAL/QP_models.h} - -\ccDefinition -An object of class \ccRefName\ describes a linear program of the form -%% -\begin{eqnarray*} -\mbox{(LP)}& \mbox{minimize} & c^{T}x+c_0 \\ -&\mbox{subject to} & Ax\qprel b, \\ -& & l \leq x \leq u -\end{eqnarray*} -%% -in $n$ real variables $x=(x_0,\ldots,x_{n-1})$. -Here, -\begin{itemize} -\item $A$ is an $m\times n$ matrix (the constraint matrix), -\item $b$ is an $m$-dimensional vector (the right-hand side), -\item $\qprel$ is an $m$-dimensional vector of relations -from $\{\leq, =, \geq\}$, -\item $l$ is an $n$-dimensional vector of lower -bounds for $x$, -\item $u$ is an $n$-dimensional vector of upper bounds for -$x$, -\item $c$ is an $n$-dimensional vector (the linear objective - function), and -\item $c_0$ is a constant. -\end{itemize} - -This class specializes the class -\ccc{Linear_program_from_iterators} for the case where all iterators are of type \ccc{NT**} (for -$A$) and \ccc{NT*} otherwise, for some number type \ccc{NT}. -The class is simply a wrapper for -existing pointers, and it does not copy the program data (if you need -a copy, you may use the class \ccc{Linear_program}). - -\ccIsModel -\ccc{LinearProgramInterface} - -\ccTypes -\ccNestedType{NT}{The number type of the program entries.} - -\ccSeeAlso -\ccc{Linear_program}\\ -\ccc{Linear_program_from_iterators}\\ -\ccc{Linear_program_from_mps} - -\end{ccRefClass} diff --git a/QP_solver/doc_tex/QP_solver_ref/MPSFormat.tex b/QP_solver/doc_tex/QP_solver_ref/MPSFormat.tex index 6a2e41809e8..974fee04749 100644 --- a/QP_solver/doc_tex/QP_solver_ref/MPSFormat.tex +++ b/QP_solver/doc_tex/QP_solver_ref/MPSFormat.tex @@ -1,8 +1,10 @@ \begin{ccRefConcept}{MPSFormat} MPS is a commonly used file format for storing linear and quadratic -programs according to the concepts \ccc{LinearProgramInterface} and -\ccc{QuadraticProgramInterface}. \cgal\ supports a large subset of +programs according to the concepts \ccc{QuadraticProgramInterface}, +\ccc{LinearProgramInterface}, +\ccc{NonnegativeQuadraticProgramInterface}, and +\ccc{NonnegativeLinearProgramInterface}. \cgal\ supports a large subset of this format, but there are MPS files around that we cannot read (for example, files that encode integrality constraints on the variables). Also, there might be some other MPS-based solvers that will not be able @@ -26,7 +28,7 @@ Let's look at an example first. The quadratic program has the following description in MPS format. \begin{verbatim} -NAME MY_MPS +NAME first_qp ROWS N obj L c0 @@ -149,5 +151,8 @@ program is a model of the concept \ccc{LinearProgramInterface}. Our MPS format also supports an (optional) \texttt{RANGES} section, but we don't explain this here. +\ccSeeAlso + +\ccc{Quadratic_program_from_mps} \end{ccRefConcept} diff --git a/QP_solver/doc_tex/QP_solver_ref/NonnegativeLinearProgramInterface.tex b/QP_solver/doc_tex/QP_solver_ref/NonnegativeLinearProgramInterface.tex index 231c808bd35..7604078ba74 100644 --- a/QP_solver/doc_tex/QP_solver_ref/NonnegativeLinearProgramInterface.tex +++ b/QP_solver/doc_tex/QP_solver_ref/NonnegativeLinearProgramInterface.tex @@ -26,10 +26,10 @@ iterators over the program data, see below. The program therefore comes in \emph{dense} representation which includes zero entries. \ccHasModels -\ccc{CGAL::Nonnegative_linear_program}\\ -\ccc{CGAL::Nonnegative_linear_program_from_iterators}\\ -\ccc{CGAL::Nonnegative_linear_program_from_pointers}\\ -\ccc{CGAL::Nonnegative_linear_program_from_mps}\\ +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps}\\ +\ccc{Nonnegative_linear_program_from_iterators} + \ccTypes @@ -83,6 +83,14 @@ respectively, for \ccc{A_iterator}) must be convertible to some common \ccc{IntegralDomain} \ccc{ET}. \ccSeeAlso +The models + +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps}\\ +\ccc{Nonnegative_linear_program_from_iterators} + +and the other concepts + \ccc{QuadraticProgramInterface}\\ \ccc{LinearProgramInterface}\\ \ccc{NonnegativeQuadraticProgramInterface} diff --git a/QP_solver/doc_tex/QP_solver_ref/NonnegativeQuadraticProgramInterface.tex b/QP_solver/doc_tex/QP_solver_ref/NonnegativeQuadraticProgramInterface.tex index 9c751f33015..31b5b27f477 100644 --- a/QP_solver/doc_tex/QP_solver_ref/NonnegativeQuadraticProgramInterface.tex +++ b/QP_solver/doc_tex/QP_solver_ref/NonnegativeQuadraticProgramInterface.tex @@ -28,10 +28,9 @@ iterators over the program data, see below. The program therefore comes in \emph{dense} representation which includes zero entries. \ccHasModels -\ccc{CGAL::Nonnegative_quadratic_program}\\ -\ccc{CGAL::Nonnegative_quadratic_program_from_iterators}\\ -\ccc{CGAL::Nonnegative_quadratic_program_from_pointers}\\ -\ccc{CGAL::Nonnegative_quadratic_program_from_mps}\\ +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps}\\ +\ccc{Nonnegative_quadratic_program_from_iterators}\\ \ccTypes @@ -95,6 +94,13 @@ respectively, for \ccc{A_iterator} and \ccc{D_iterator}) must be convertible to some common \ccc{IntegralDomain} \ccc{ET}. \ccSeeAlso +The models + +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps}\\ +\ccc{Nonnegative_quadratic_program_from_iterators} +and the other concepts + \ccc{QuadraticProgramInterface}\\ \ccc{LinearProgramInterface}\\ \ccc{NonnegativeLinearProgramInterface} diff --git a/QP_solver/doc_tex/QP_solver_ref/Nonnegative_linear_program_from_iterators.tex b/QP_solver/doc_tex/QP_solver_ref/Nonnegative_linear_program_from_iterators.tex index dbd0377320d..26e8f291eba 100644 --- a/QP_solver/doc_tex/QP_solver_ref/Nonnegative_linear_program_from_iterators.tex +++ b/QP_solver/doc_tex/QP_solver_ref/Nonnegative_linear_program_from_iterators.tex @@ -27,6 +27,13 @@ This class is simply a wrapper for existing iterators, and it does not copy the program data (if you need a copy, you may use the class \ccc{Nonnegative_linear_program}). +It frequently happens that all values in one of the vectors from +above are the same, for example if the system $Ax\qprel b$ is +actually a system of equations $Ax=b$. To get an iterator over such a +vector, it is not necessary to store multiple copies of the value in +some container; an instance of the class \ccc{Const_oneset_iterator}, +constructed from the value in question, does the job more efficiently. + \ccIsModel \ccc{NonnegativeLinearProgramInterface} @@ -41,10 +48,18 @@ copy the program data (if you need a copy, you may use the class const R_it& r, const C_it& c, const std::iterator_traitsvalue_type& c0 = 0 - )}{constructs \ccVar\ from given random-access iterators and the constant \ccc{c0}. The passed iterators are merely stored, no copying of the program data takes place. } + )}{constructs \ccVar\ from given random-access iterators and the constant +\ccc{c0}. The passed iterators are merely stored, no copying of the program +data takes place. How these iterators are supposed to encode the nonnegative +linear program is described in \ccc{NonnegativeLinearProgramInterface}.} + +\ccExample + +\ccReferToExampleCode{QP_solver/first_nonnegative_lp_from_iterators.cpp}\\ +\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp.h} \ccSeeAlso -\ccc{Nonnegative_linear_program}\\ -\ccc{Nonnegative_linear_program_from_pointers}\\ -\ccc{Nonnegative_linear_program_from_mps} +\ccc{NonnegativeLinearProgramInterface} +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps} \end{ccRefClass} diff --git a/QP_solver/doc_tex/QP_solver_ref/Nonnegative_linear_program_from_pointers.tex b/QP_solver/doc_tex/QP_solver_ref/Nonnegative_linear_program_from_pointers.tex deleted file mode 100644 index 0d6359325e4..00000000000 --- a/QP_solver/doc_tex/QP_solver_ref/Nonnegative_linear_program_from_pointers.tex +++ /dev/null @@ -1,45 +0,0 @@ -\begin{ccRefClass}{Nonnegative_linear_program_from_pointers} - -\ccInclude{CGAL/QP_models.h} - -\ccDefinition -An object of class \ccRefName\ describes a linear program of the form -%% -\begin{eqnarray*} -\mbox{(LP)}& \mbox{minimize} & c^{T}x+c_0 \\ -&\mbox{subject to} & Ax\qprel b, \\ -& & x \geq 0 -\end{eqnarray*} -%% -in $n$ real variables $x=(x_0,\ldots,x_{n-1})$. -Here, -\begin{itemize} -\item $A$ is an $m\times n$ matrix (the constraint matrix), -\item $b$ is an $m$-dimensional vector (the right-hand side), -\item $\qprel$ is an $m$-dimensional vector of relations -from $\{\leq, =, \geq\}$, -\item $c$ is an $n$-dimensional vector (the linear objective - function), and -\item $c_0$ is a constant. -\end{itemize} - -This class specializes the class -\ccc{Nonnegative_linear_program_from_iterators} -for the case where all iterators are of type \ccc{NT**} (for -$A$) and \ccc{NT*} otherwise, for some number type \ccc{NT}. -The class is simply a wrapper for -existing pointers, and it does not copy the program data (if you need -a copy, you may use the class \ccc{Nonnegative_linear_program}). - -\ccIsModel -\ccc{NonnegativeLinearProgramInterface} - -\ccTypes -\ccNestedType{NT}{The number type of the program entries.} - -\ccSeeAlso -\ccc{Nonnegative_linear_program}\\ -\ccc{Nonnegative_linear_program_from_iterators}\\ -\ccc{Nonnegative_linear_program_from_mps} - -\end{ccRefClass} diff --git a/QP_solver/doc_tex/QP_solver_ref/Nonnegative_quadratic_program_from_iterators.tex b/QP_solver/doc_tex/QP_solver_ref/Nonnegative_quadratic_program_from_iterators.tex index 7f50be85380..3d7a2974599 100644 --- a/QP_solver/doc_tex/QP_solver_ref/Nonnegative_quadratic_program_from_iterators.tex +++ b/QP_solver/doc_tex/QP_solver_ref/Nonnegative_quadratic_program_from_iterators.tex @@ -29,6 +29,13 @@ This class is simply a wrapper for existing iterators, and it does not copy the program data (if you need a copy, you may use the class \ccc{Nonnegative_quadratic_program}). +It frequently happens that all values in one of the vectors from +above are the same, for example if the system $Ax\qprel b$ is +actually a system of equations $Ax=b$. To get an iterator over such a +vector, it is not necessary to store multiple copies of the value in +some container; an instance of the class \ccc{Const_oneset_iterator}, +constructed from the value in question, does the job more efficiently. + \ccIsModel \ccc{NonnegativeQuadraticProgramInterface} @@ -44,10 +51,21 @@ copy the program data (if you need a copy, you may use the class const D_it& d, const C_it& c, const std::iterator_traitsvalue_type& c0 = 0 - )}{constructs \ccVar\ from given random-access iterators and the constant \ccc{c0}. The passed iterators are merely stored, no copying of the program data takes place. } + )}{constructs \ccVar\ from given random-access iterators and the constant \ccc{c0}. The passed iterators are merely stored, no copying of the program data takes place. How these iterators are supposed to encode the nonnegative +quadratic program is described in \ccc{NonnegativeQuadraticProgramInterface}.} +\ccExample + +\ccReferToExampleCode{QP_solver/first_nonnegative_qp_from_iterators.cpp} + +The following example for the simpler model +\ccc{Nonnegative_linear_program_from_iterators} +should give you a flavor of the use of this +model in practice. + +\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp.h} \ccSeeAlso -\ccc{Nonnegative_quadratic_program}\\ -\ccc{Nonnegative_quadratic_program_from_pointers}\\ -\ccc{Nonnegative_quadratic_program_from_mps} +\ccc{NonnegativeQuadraticProgramInterface} +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps} \end{ccRefClass} diff --git a/QP_solver/doc_tex/QP_solver_ref/Nonnegative_quadratic_program_from_pointers.tex b/QP_solver/doc_tex/QP_solver_ref/Nonnegative_quadratic_program_from_pointers.tex deleted file mode 100644 index d9807f005c9..00000000000 --- a/QP_solver/doc_tex/QP_solver_ref/Nonnegative_quadratic_program_from_pointers.tex +++ /dev/null @@ -1,46 +0,0 @@ -\begin{ccRefClass}{Nonnegative_quadratic_program_from_pointers} - -\ccInclude{CGAL/QP_models.h} - -\ccDefinition -An object of class \ccRefName\ describes a convex quadratic program of the form -%% -\begin{eqnarray*} -\mbox{(QP)}& \mbox{minimize} & x^{T}Dx+c^{T}x+c_0 \\ -&\mbox{subject to} & Ax\qprel b, \\ -& & x \geq 0 -\end{eqnarray*} -%% -in $n$ real variables $x=(x_0,\ldots,x_{n-1})$. -Here, -\begin{itemize} -\item $A$ is an $m\times n$ matrix (the constraint matrix), -\item $b$ is an $m$-dimensional vector (the right-hand side), -\item $\qprel$ is an $m$-dimensional vector of relations -from $\{\leq, =, \geq\}$, -\item $D$ is a symmetric positive-semidefinite $n\times n$ matrix (the - quadratic objective function), -\item $c$ is an $n$-dimensional vector (the linear objective - function), and -\item $c_0$ is a constant. -\end{itemize} - -This class specializes the class -\ccc{Nonnegative_quadratic_program_from_iterators} for the case where all iterators are of type \ccc{NT**} (for -$A$ and $D$) and \ccc{NT*} otherwise, for some number type \ccc{NT}. -The class is simply a wrapper for -existing pointers, and it does not copy the program data (if you need -a copy, you may use the class \ccc{Nonnegative_quadratic_program}). - -\ccIsModel -\ccc{NonnegativeQuadraticProgramInterface} - -\ccTypes -\ccNestedType{NT}{The number type of the program entries.} - -\ccSeeAlso -\ccc{Nonnegative_quadratic_program}\\ -\ccc{Nonnegative_quadratic_program_from_iterators}\\ -\ccc{Nonnegative_quadratic_program_from_mps} - -\end{ccRefClass} diff --git a/QP_solver/doc_tex/QP_solver_ref/QuadraticProgramInterface.tex b/QP_solver/doc_tex/QP_solver_ref/QuadraticProgramInterface.tex index be9e72b33dc..90dbc6062ee 100644 --- a/QP_solver/doc_tex/QP_solver_ref/QuadraticProgramInterface.tex +++ b/QP_solver/doc_tex/QP_solver_ref/QuadraticProgramInterface.tex @@ -32,10 +32,9 @@ iterators over the program data, see below. The program therefore comes in \emph{dense} representation which includes zero entries. \ccHasModels -\ccc{CGAL::Quadratic_program}\\ -\ccc{CGAL::Quadratic_program_from_iterators}\\ -\ccc{CGAL::Quadratic_program_from_pointers}\\ -\ccc{CGAL::Quadratic_program_from_mps}\\ +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps}\\ +\ccc{Quadratic_program_from_iterators} \ccTypes @@ -131,6 +130,14 @@ respectively, for \ccc{A_iterator} and \ccc{D_iterator}) must be convertible to some common \ccc{IntegralDomain} \ccc{ET}. \ccSeeAlso +The models + +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps}\\ +\ccc{Quadratic_program_from_iterators} + +and the other conepts + \ccc{NonnegativeQuadraticProgramInterface}\\ \ccc{LinearProgramInterface}\\ \ccc{NonnegativeLinearProgramInterface} diff --git a/QP_solver/doc_tex/QP_solver_ref/Quadratic_program.tex b/QP_solver/doc_tex/QP_solver_ref/Quadratic_program.tex index 292edb529d1..3805d72a5ea 100644 --- a/QP_solver/doc_tex/QP_solver_ref/Quadratic_program.tex +++ b/QP_solver/doc_tex/QP_solver_ref/Quadratic_program.tex @@ -31,11 +31,17 @@ $x$, \end{itemize} This class allows you to build your program entry by entry, using -the set-methods below. If you only need to wrap existing (random-access) -iterators, then you may use the classes -\ccc{Quadratic_program_from_iterators} and \ccc{Quadratic_program_from_pointers}). If you want -to read a quadratic program in \ccc{MPSFormat} from a file, please use -the model \ccc{Quadratic_program_from_mps}. +the set-methods below. + +If you only need to wrap existing (random-access) +iterators over your own data, then you may use any of the four models +\ccc{Quadratic_program_from_iterators}, +\ccc{Linear_program_from_iterators}, +\ccc{Nonnegative_quadratic_program_from_iterators}, and +\ccc{Nonnegative_linear_program_from_iterators}. + +If you want to read a quadratic program in \ccc{MPSFormat} from a stream, +please use the model \ccc{Quadratic_program_from_mps}. \ccIsModel \ccc{QuadraticProgramInterface}\\ @@ -110,10 +116,18 @@ $2D_{ij}$ and $2D_{ji}$ of \ccVar\ to \ccc{val}. Existing entries are overwritten. \ccVar\ is enlarged if necessary to accomodate these entries. \ccPrecond \ccc{j <= i}} +\ccExample + +\ccReferToExampleCode{QP_solver/first_qp.cpp}\\ +\ccReferToExampleCode{QP_solver/first_lp.cpp}\\ +\ccReferToExampleCode{QP_solver/first_nonnegative_qp.cpp}\\ +\ccReferToExampleCode{QP_solver/first_nonnegative_lp.cpp} \ccSeeAlso \ccc{Quadratic_program_from_iterators}\\ -\ccc{Quadratic_program_from_pointers}\\ +\ccc{Linear_program_from_iterators}\\ +\ccc{Nonnegative_quadratic_program_from_iterators}\\ +\ccc{Nonnegative_linear_program_from_iterators}\\ \ccc{Quadratic_program_from_mps} \end{ccRefClass} diff --git a/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_iterators.tex b/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_iterators.tex index 109fa5f7688..8cbfb3810fa 100644 --- a/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_iterators.tex +++ b/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_iterators.tex @@ -29,9 +29,16 @@ $x$, \item $c_0$ is a constant. \end{itemize} -This class is simply a wrapper for existing iterators, and it does not -copy the program data (if you need a copy, you may use the class -\ccc{Quadratic_program}). +This class is simply a wrapper for existing iterators over these program +data, and it does not copy the program data (if you need a copy, you may +use the class \ccc{Quadratic_program}). + +It frequently happens that all values in one of the vectors from +above are the same, for example if the system $Ax\qprel b$ is +actually a system of equations $Ax=b$. To get an iterator over such a +vector, it is not necessary to store multiple copies of the value in +some container; an instance of the class \ccc{Const_oneset_iterator}, +constructed from the value in question, does the job more efficiently. \ccIsModel \ccc{QuadraticProgramInterface} @@ -52,11 +59,23 @@ copy the program data (if you need a copy, you may use the class const D_it& d, const C_it& c, const std::iterator_traitsvalue_type& c0 = 0 - )}{constructs \ccVar\ from given random-access iterators and the constant \ccc{c0}. The passed iterators are merely stored, no copying of the program data takes place. } + )}{constructs \ccVar\ from given random-access iterators and the constant \ccc{c0}. The passed iterators are merely stored, no copying of the program data takes place. How these iterators are supposed to encode the quadratic program is +described in \ccc{QuadraticProgramInterface}.} + +\ccExample + +\ccReferToExampleCode{QP_solver/first_qp_from_iterators.cpp} + +The following example for the simpler model +\ccc{Nonnegative_linear_program_from_iterators} +should give you a flavor of the use of this +model in practice. + +\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp.h} \ccSeeAlso +\ccc{QuadraticProgramInterface} \ccc{Quadratic_program}\\ -\ccc{Quadratic_program_from_pointers}\\ \ccc{Quadratic_program_from_mps} \end{ccRefClass} diff --git a/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_mps.tex b/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_mps.tex index c82b902b1aa..51e0a31820d 100644 --- a/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_mps.tex +++ b/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_mps.tex @@ -102,10 +102,17 @@ $2D_{ij}$ and $2D_{ji}$ of \ccVar\ to \ccc{val}. Existing entries are overwritten. \ccVar\ is enlarged if necessary to accomodate these entries. \ccPrecond \ccc{j <= i}} +\ccExample + +\ccReferToExampleCode{QP_solver/first_qp_from_mps.cpp}\\ +\ccReferToExampleCode{QP_solver/first_lp_from_mps.cpp}\\ +\ccReferToExampleCode{QP_solver/first_nonnegative_qp_from_mps.cpp}\\ +\ccReferToExampleCode{QP_solver/first_nonnegative_lp_from_mps.cpp} + \ccSeeAlso \ccc{Quadratic_program}\\ \ccc{Quadratic_program_from_iterators}\\ -\ccc{Quadratic_program_from_pointers} - - +\ccc{Linear_program_from_iterators}\\ +\ccc{Nonnegative_quadratic_program_from_iterators}\\ +\ccc{Nonnegative_linear_program_from_iterators} \end{ccRefClass} diff --git a/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_pointers.tex b/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_pointers.tex deleted file mode 100644 index 7f71a41d5ec..00000000000 --- a/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_from_pointers.tex +++ /dev/null @@ -1,51 +0,0 @@ -\begin{ccRefClass}{Quadratic_program_from_pointers} - -\ccInclude{CGAL/QP_models.h} - -\ccDefinition -An object of class \ccRefName\ describes a convex quadratic program of the form -%% -\begin{eqnarray*} -\mbox{(QP)}& \mbox{minimize} & x^{T}Dx+c^{T}x+c_0 \\ -&\mbox{subject to} & Ax\qprel b, \\ -& & l \leq x \leq u -\end{eqnarray*} -%% -in $n$ real variables $x=(x_0,\ldots,x_{n-1})$. -Here, -\begin{itemize} -\item $A$ is an $m\times n$ matrix (the constraint matrix), -\item $b$ is an $m$-dimensional vector (the right-hand side), -\item $\qprel$ is an $m$-dimensional vector of relations -from $\{\leq, =, \geq\}$, -\item $l$ is an $n$-dimensional vector of lower -bounds for $x$, -\item $u$ is an $n$-dimensional vector of upper bounds for -$x$, -\item $D$ is a symmetric positive-semidefinite $n\times n$ matrix (the - quadratic objective function), -\item $c$ is an $n$-dimensional vector (the linear objective - function), and -\item $c_0$ is a constant. -\end{itemize} - -This class specializes the class -\ccc{Quadratic_program_from_iterators} for the case where all iterators are of type \ccc{NT**} (for -$A$ and $D$) and \ccc{NT*} otherwise, for some number type \ccc{NT}. -The class is simply a wrapper for -existing pointers, and it does not copy the program data (if you need -a copy, you may use the class \ccc{Quadratic_program}). - -\ccIsModel -\ccc{QuadraticProgramInterface} - -\ccTypes -\ccNestedType{NT}{The number type of the program entries.} - -\ccSeeAlso -\ccc{Quadratic_program}\\ -\ccc{Quadratic_program_from_iterators}\\ -\ccc{Quadratic_program_from_mps} - - -\end{ccRefClass} diff --git a/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_solution.tex b/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_solution.tex index 0995c13825e..3aa81b68455 100644 --- a/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_solution.tex +++ b/QP_solver/doc_tex/QP_solver_ref/Quadratic_program_solution.tex @@ -20,6 +20,9 @@ the four functions \ccc{solve_nonnegative_quadratic_program}, and \ccc{solve_nonnegative_linear_program}. +\ccExample +\ccReferToExampleCode{QP_solver/first_qp.cpp} + \ccHeading{Terminology} If there is no $x$ that satisfies all the (in)equalities, the program is called \emph{infeasible}, otherwise, it is \emph{feasible}, @@ -165,6 +168,9 @@ variables have value $0$.} {returns the number of basic variables, equivalently the length of the range determined by the previous two iterators.} +\ccExample +\ccReferToExampleCode{QP_solver/important_variables.cpp} + \ccMethod{Index_iterator basic_constraint_indices_begin() const;} {returns a random access iterator over the indices of the basic constraints in the system $Ax\qprel b$. The value type is \ccc{int}. @@ -179,6 +185,7 @@ basic.} {returns the number of basic constraint, equivalently the length of the range determined by the previous two iterators.} +\begin{ccAdvanced} \ccHeading{Certificates} A certificate is a vector that admits a simple proof for the @@ -200,7 +207,6 @@ then $\lambda_i\geq 0$ ($\lambda_i\leq 0$, respectively). \end{array}\] \end{enumerate} -\begin{ccAdvanced} {\bf Proof:} Let $x$ be any feasible solution. We need to prove that \[c^Tx + x^TDx \geq c^Tx^* + {x^*}^TDx^*.\] @@ -224,7 +230,7 @@ c^Tx + x^TDx - (x-x^*)^TD(x-x^*) \geq c^Tx^* + {x^*}^TDx^*, \] and since $D$ is positive semidefinite, we have $(x-x^*)^TD(x-x^*)\geq 0$ and the lemma follows. -\end{ccAdvanced} + \ccMethod{Optimality_certificate_iterator optimality_certifcate_begin() const;} @@ -253,6 +259,9 @@ is \ccc{ET}, and the valid iterator range has length $m$.} {returns the common denominator of the certificate values $\lambda$ as referred to by the previous two methods.} +\ccExample +\ccReferToExampleCode{QP_solver/optimality_certificate.cpp} + {\bf Lemma 2 (infeasibility certificate):} The program (QP) is infeasible if an $m$-vector $\lambda$ with the following properties exist. @@ -271,7 +280,6 @@ then $\lambda_i\geq 0$ ($\lambda_i\leq 0$, respectively). \quad+\quad \sum_{j: \lambda^TA_j >0} \lambda^TA_j l_j.\] \end{enumerate} -\begin{ccAdvanced} {\bf Proof:} Let us assume for the purpose of obtaining a contradiction that there is a feasible solution $x$. Then we get \[ @@ -286,7 +294,7 @@ that there is a feasible solution $x$. Then we get \end{array} \] and this is the desired contradiction $0>0$. -\end{ccAdvanced} + \ccMethod{Infeasibility_certificate_iterator infeasibility_certificate_begin() const;} @@ -299,6 +307,9 @@ is \ccc{ET}, and the valid iterator range has length $m$. infeasibility_certificate_end() const;} {returns the corresponding past-the-end iterator.} +\ccExample +\ccReferToExampleCode{QP_solver/infeasibility_certificate.cpp} + {\bf Lemma 3 (unboundedness certificate:)} Let $x^*$ be a feasible solution of (QP). The program (QP) is unbounded if an $n$-vector $w$ with the following properties exist. @@ -318,7 +329,6 @@ w_j &\quad \\ The vector $w$ is called an \emph{unbounded direction}. -\begin{ccAdvanced} {\bf Proof:} For a real number $t$, consider the vector $x(t):=x^*+tw$. By 1. and 2., $x(t)$ is feasible for all $t\geq 0$. The objective function value of $x(t)$ is @@ -329,7 +339,6 @@ c^Tx^* + tc^Tw + {x^*}^TDx^* + 2t{x^*}^TDw + t^2 w^TDw \\ \end{eqnarray*} By condition 3., this tends to $-\infty$ for $t\rightarrow\infty$, so the problem is indeed unbounded. -\end{ccAdvanced} \ccMethod{Unboundedness_certificate_iterator unboundedness_certificate_begin() const;} @@ -342,6 +351,10 @@ is \ccc{ET}, and the valid iterator range has length $n$. \ccMethod{Unboundedness_certificate_iterator unboundedness_certificate_end();} {returns the corresponding past-the-end iterator.} +\ccExample +\ccReferToExampleCode{QP_solver/unboundedness_certificate.cpp} + +\end{ccAdvanced} \ccSeeAlso diff --git a/QP_solver/doc_tex/QP_solver_ref/intro.tex b/QP_solver/doc_tex/QP_solver_ref/intro.tex index d05ae5c6974..b7244986420 100644 --- a/QP_solver/doc_tex/QP_solver_ref/intro.tex +++ b/QP_solver/doc_tex/QP_solver_ref/intro.tex @@ -44,32 +44,21 @@ $\quad$ (for linear and quadratic programs read from an input stream in Then there are specific models for any of the four program concepts above; these are useful if you want to maintain the program data yourself, since -they simply wrap random access iterators over the program data. +they simply wrap random access iterators over the program data and involve +no further copying of data. \ccRefIdfierPage{Quadratic_program_from_iterators}\\ $\quad$ (for quadratic programs that wrap given iterators, without copying -data) \\ -\ccRefIdfierPage{Quadratic_program_from_pointers}\\ -$\quad$ (for quadratic programs that wrap given pointers, without copying data) \ccRefIdfierPage{Linear_program_from_iterators}\\ -$\quad$ (for linear programs that wrap given iterators, without copying -data) \\ -\ccRefIdfierPage{Linear_program_from_pointers}\\ -$\quad$ (for linear programs that wrap given pointers, without copying -data) +$\quad$ (for linear programs wrapping given iterators) \ccRefIdfierPage{Nonnegative_quadratic_program_from_iterators}\\ -$\quad$ (for nonnegative quadratic programs, wrapping given iterators)\\ -\ccRefIdfierPage{Nonnegative_quadratic_program_from_pointers}\\ -$\quad$ (for nonnegative quadratic programs, wrapping given pointers) +$\quad$ (for nonnegative quadratic programs, wrapping given iterators) \ccRefIdfierPage{Nonnegative_linear_program_from_iterators}\\ -$\quad$ (for nonnegative linear programs, wrapping given iterators)\\ -\ccRefIdfierPage{Nonnegative_linear_program_from_pointers}\\ -$\quad$ (for nonnegative linear programs, wrapping given pointers) - +$\quad$ (for nonnegative linear programs, wrapping given iterators) \ccHeading{Functions} In case you want to construct a program from complicated iterators diff --git a/QP_solver/doc_tex/QP_solver_ref/main.tex b/QP_solver/doc_tex/QP_solver_ref/main.tex index 0af64d3154c..6785a54f865 100644 --- a/QP_solver/doc_tex/QP_solver_ref/main.tex +++ b/QP_solver/doc_tex/QP_solver_ref/main.tex @@ -18,16 +18,12 @@ \input{QP_solver_ref/Quadratic_program_from_mps} \input{QP_solver_ref/Quadratic_program_from_iterators} -\input{QP_solver_ref/Quadratic_program_from_pointers} \input{QP_solver_ref/Linear_program_from_iterators} -\input{QP_solver_ref/Linear_program_from_pointers} \input{QP_solver_ref/Nonnegative_quadratic_program_from_iterators} -\input{QP_solver_ref/Nonnegative_quadratic_program_from_pointers} \input{QP_solver_ref/Nonnegative_linear_program_from_iterators} -\input{QP_solver_ref/Nonnegative_linear_program_from_pointers} \input{QP_solver_ref/make_quadratic_program_from_iterators.tex} \input{QP_solver_ref/make_linear_program_from_iterators.tex} diff --git a/QP_solver/doc_tex/QP_solver_ref/make_linear_program_from_iterators.tex b/QP_solver/doc_tex/QP_solver_ref/make_linear_program_from_iterators.tex index 62cd8d2ef2f..29c0ed09061 100644 --- a/QP_solver/doc_tex/QP_solver_ref/make_linear_program_from_iterators.tex +++ b/QP_solver/doc_tex/QP_solver_ref/make_linear_program_from_iterators.tex @@ -8,14 +8,14 @@ iterators are too complicated (or of too little interest for you) to write them down explicitly. \ccFunction{template < - typename A_it, - typename B_it, - typename R_it, - typename FL_it, - typename L_it, - typename FU_it, - typename U_it, - typename C_it > + A_it, + B_it, + R_it, + FL_it, + L_it, + FU_it, + U_it, + C_it > Linear_program_from_iterators make_linear_program_from_iterators ( int n, int m, @@ -27,10 +27,16 @@ make_linear_program_from_iterators ( const FU_it& fu, const U_it& u, const C_it& c, - typename std::iterator_traits::value_type c0 = - typename std::iterator_traits::value_type(0));} + std::iterator_traits::value_type c0 = + std::iterator_traits::value_type(0));} {returns an instance of \ccc{Linear_program_from_iterators}, constructed from the given iterators.} +\ccExample +The following example demonstrates the typical usage of makers +with the simpler function \ccc{make_nonnegative_linear_program_from_iterators}. + +\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp2.h} + \ccSeeAlso \ccc{Linear_program_from_iterators} \end{ccRefFunction} diff --git a/QP_solver/doc_tex/QP_solver_ref/make_nonnegative_linear_program_from_iterators.tex b/QP_solver/doc_tex/QP_solver_ref/make_nonnegative_linear_program_from_iterators.tex index b2ed65aa1be..b5c9a4e9dd3 100644 --- a/QP_solver/doc_tex/QP_solver_ref/make_nonnegative_linear_program_from_iterators.tex +++ b/QP_solver/doc_tex/QP_solver_ref/make_nonnegative_linear_program_from_iterators.tex @@ -9,10 +9,10 @@ iterators are too complicated (or of too little interest for you) to write them down explicitly. \ccFunction{template < - typename A_it, - typename B_it, - typename R_it, - typename C_it > + A_it, + B_it, + R_it, + C_it > Nonnegative_linear_program_from_iterators make_nonnegative_linear_program_from_iterators ( @@ -21,10 +21,13 @@ make_nonnegative_linear_program_from_iterators ( const B_it& b, const R_it& r, const C_it& c, - typename std::iterator_traits::value_type c0 = - typename std::iterator_traits::value_type(0));} + std::iterator_traits::value_type c0 = + std::iterator_traits::value_type(0));} {returns an instance of \ccc{Nonnegative_linear_program_from_iterators}, constructed from the given iterators.} +\ccExample +\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp2.h} + \ccSeeAlso \ccc{Nonnegative_linear_program_from_iterators} \end{ccRefFunction} diff --git a/QP_solver/doc_tex/QP_solver_ref/make_nonnegative_quadratic_program_from_iterators.tex b/QP_solver/doc_tex/QP_solver_ref/make_nonnegative_quadratic_program_from_iterators.tex index 10c63a1c367..2dfae2b43f7 100644 --- a/QP_solver/doc_tex/QP_solver_ref/make_nonnegative_quadratic_program_from_iterators.tex +++ b/QP_solver/doc_tex/QP_solver_ref/make_nonnegative_quadratic_program_from_iterators.tex @@ -8,11 +8,11 @@ iterators are too complicated (or of too little interest for you) to write them down explicitly. \ccFunction{template < - typename A_it, - typename B_it, - typename R_it, - typename D_it, - typename C_it > + A_it, + B_it, + R_it, + D_it, + C_it > Nonnegative_quadratic_program_from_iterators make_nonnegative_quadratic_program_from_iterators ( @@ -22,10 +22,15 @@ make_nonnegative_quadratic_program_from_iterators ( const R_it& r, const D_it& d, const C_it& c, - typename std::iterator_traits::value_type c0 = - typename std::iterator_traits::value_type(0));} + std::iterator_traits::value_type c0 = + std::iterator_traits::value_type(0));} {returns an instance of \ccc{Nonnegative_quadratic_program_from_iterators}, constructed from the given iterators.} +\ccExample +The following example demonstrates the typical usage of makers +with the simpler function \ccc{make_nonnegative_linear_program_from_iterators}. + +\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp2.h} \ccSeeAlso \ccc{Nonnegative_quadratic_program_from_iterators} \end{ccRefFunction} diff --git a/QP_solver/doc_tex/QP_solver_ref/make_quadratic_program_from_iterators.tex b/QP_solver/doc_tex/QP_solver_ref/make_quadratic_program_from_iterators.tex index f1c48b44c0c..d46bd3728dd 100644 --- a/QP_solver/doc_tex/QP_solver_ref/make_quadratic_program_from_iterators.tex +++ b/QP_solver/doc_tex/QP_solver_ref/make_quadratic_program_from_iterators.tex @@ -8,15 +8,15 @@ iterators are too complicated (or of too little interest for you) to write them down explicitly. \ccFunction{template < - typename A_it, - typename B_it, - typename R_it, - typename FL_it, - typename L_it, - typename FU_it, - typename U_it, - typename D_it, - typename C_it > + A_it, + B_it, + R_it, + FL_it, + L_it, + FU_it, + U_it, + D_it, + C_it > Quadratic_program_from_iterators make_quadratic_program_from_iterators ( int n, int m, @@ -29,10 +29,17 @@ make_quadratic_program_from_iterators ( const U_it& u, const D_it& d, const C_it& c, - typename std::iterator_traits::value_type c0 = - typename std::iterator_traits::value_type(0));} + std::iterator_traits::value_type c0 = + std::iterator_traits::value_type(0));} {returns an instance of \ccc{Quadratic_program_from_iterators}, constructed from the given iterators.} +\ccExample +The following example demonstrates the typical usage of makers +with the simpler function \ccc{make_nonnegative_linear_program_from_iterators}. + +\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp2.h} + + \ccSeeAlso \ccc{Quadratic_program_from_iterators} \end{ccRefFunction} diff --git a/QP_solver/doc_tex/QP_solver_ref/print_linear_program.tex b/QP_solver/doc_tex/QP_solver_ref/print_linear_program.tex index 9dd7054046b..36554a67f9a 100644 --- a/QP_solver/doc_tex/QP_solver_ref/print_linear_program.tex +++ b/QP_solver/doc_tex/QP_solver_ref/print_linear_program.tex @@ -17,4 +17,12 @@ by \ccc{problem_name}.} \ccHeading{Requirements} Output operators are defined for all entry types of \ccc{lp}. +\ccExample +\ccReferToExampleCode{QP_solver/print_first_lp.cpp} + +\ccSeeAlso + +The concept + +\ccc{LinearProgramInterface} \end{ccRefFunction} diff --git a/QP_solver/doc_tex/QP_solver_ref/print_nonnegative_linear_program.tex b/QP_solver/doc_tex/QP_solver_ref/print_nonnegative_linear_program.tex index bf2faedb68e..3e0c79f0c51 100644 --- a/QP_solver/doc_tex/QP_solver_ref/print_nonnegative_linear_program.tex +++ b/QP_solver/doc_tex/QP_solver_ref/print_nonnegative_linear_program.tex @@ -17,4 +17,13 @@ by \ccc{problem_name}.} \ccHeading{Requirements} Output operators are defined for all entry types of \ccc{lp}. +\ccExample +\ccReferToExampleCode{QP_solver/print_first_nonnegative_lp.cpp} + +\ccSeeAlso + +The concept + +\ccc{NonnegativeLinearProgramInterface} + \end{ccRefFunction} diff --git a/QP_solver/doc_tex/QP_solver_ref/print_nonnegative_quadratic_program.tex b/QP_solver/doc_tex/QP_solver_ref/print_nonnegative_quadratic_program.tex index bfd6912c8b1..dadf2856775 100644 --- a/QP_solver/doc_tex/QP_solver_ref/print_nonnegative_quadratic_program.tex +++ b/QP_solver/doc_tex/QP_solver_ref/print_nonnegative_quadratic_program.tex @@ -17,4 +17,12 @@ by \ccc{problem_name}.} \ccHeading{Requirements} Output operators are defined for all entry types of \ccc{qp}. +\ccExample +\ccReferToExampleCode{QP_solver/print_first_nonnegative_qp.cpp} + +\ccSeeAlso + +The concept + +\ccc{NonnegativeQuadraticProgramInterface} \end{ccRefFunction} diff --git a/QP_solver/doc_tex/QP_solver_ref/print_quadratic_program.tex b/QP_solver/doc_tex/QP_solver_ref/print_quadratic_program.tex index b0ec66c86d6..c7a038dd10d 100644 --- a/QP_solver/doc_tex/QP_solver_ref/print_quadratic_program.tex +++ b/QP_solver/doc_tex/QP_solver_ref/print_quadratic_program.tex @@ -16,4 +16,13 @@ The name of the program will be the one provided by \ccc{problem_name}.} \ccHeading{Requirements} Output operators are defined for all entry types of \ccc{qp}. +\ccExample +\ccReferToExampleCode{QP_solver/print_first_qp.cpp} + +\ccSeeAlso + +The concept + +\ccc{QuadraticProgramInterface} + \end{ccRefFunction} diff --git a/QP_solver/doc_tex/QP_solver_ref/solve_linear_program.tex b/QP_solver/doc_tex/QP_solver_ref/solve_linear_program.tex index 14bcadc0549..665d027d161 100644 --- a/QP_solver/doc_tex/QP_solver_ref/solve_linear_program.tex +++ b/QP_solver/doc_tex/QP_solver_ref/solve_linear_program.tex @@ -17,18 +17,31 @@ with exact number type \ccc{ET}.} be an exact type, and all entries of \ccc{lp} are convertible to \ccc{ET}. +Here are some recommended combinations of input type (the type of +the \ccc{lp} entries) and \ccc{ET}. + +\begin{tabular}{lll} +input type &| & \ccc{ET} \\ \hline +\ccc{double} &| & \ccc{MP_Float}, \ccc{Gmpzf}, or \ccc{Gmpq} \\ +\ccc{int} &| & \ccc{MP_Float}, or \ccc{Gmpz} \\ +any exact type \ccc{NT} &|& \ccc{NT} +\end{tabular} + {\bf Note:} by default, this function performs a large number of runtime-checks to ensure consistency during the solution process. However, these checks slow down the computations by a considerable factor. For maximum efficiency, it is advisable to define the macros \texttt{CGAL\_QP\_NO\_ASSERTIONS} or \texttt{NDEBUG}. +\ccExample +\ccReferToExampleCode{QP_solver/first_lp.cpp} + \ccSeeAlso The models of \ccRefIdfierPage{LinearProgramInterface}: -\ccRefIdfierPage{Quadratic_program}\\ -\ccRefIdfierPage{Quadratic_program_from_mps}\\ -\ccRefIdfierPage{Linear_program_from_iterators}\\ -\ccRefIdfierPage{Linear_program_from_pointers} +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps}\\ +\ccc{Linear_program_from_iterators} + \end{ccRefFunction} diff --git a/QP_solver/doc_tex/QP_solver_ref/solve_nonnegative_linear_program.tex b/QP_solver/doc_tex/QP_solver_ref/solve_nonnegative_linear_program.tex index 3906380a28e..1f4bdf17470 100644 --- a/QP_solver/doc_tex/QP_solver_ref/solve_nonnegative_linear_program.tex +++ b/QP_solver/doc_tex/QP_solver_ref/solve_nonnegative_linear_program.tex @@ -7,7 +7,7 @@ Integral Domain \ccc{ET} for its computations. \ccFunction{template Quadratic_program_solution solve_nonnegative_linear_program - (const NonegativeLinearProgramInterface& lp, const ET&);} + (const NonnegativeLinearProgramInterface& lp, const ET&);} {returns the solution of the nonnegative linear program \ccc{lp}, solved with exact number type \ccc{ET}.} @@ -17,18 +17,30 @@ with exact number type \ccc{ET}.} be an exact type, and all entries of \ccc{lp} are convertible to \ccc{ET}. +Here are some recommended combinations of input type (the type of +the \ccc{lp} entries) and \ccc{ET}. + +\begin{tabular}{lll} +input type &| & \ccc{ET} \\ \hline +\ccc{double} &| & \ccc{MP_Float}, \ccc{Gmpzf}, or \ccc{Gmpq} \\ +\ccc{int} &| & \ccc{MP_Float}, or \ccc{Gmpz} \\ +any exact type \ccc{NT} &|& \ccc{NT} +\end{tabular} + {\bf Note:} by default, this function performs a large number of runtime-checks to ensure consistency during the solution process. However, these checks slow down the computations by a considerable factor. For maximum efficiency, it is advisable to define the macros \texttt{CGAL\_QP\_NO\_ASSERTIONS} or \texttt{NDEBUG}. +\ccExample +\ccReferToExampleCode{QP_solver/first_nonnegative_lp.cpp} + \ccSeeAlso The models of \ccRefIdfierPage{NonnegativeLinearProgramInterface}: -\ccRefIdfierPage{Quadratic_program}\\ -\ccRefIdfierPage{Quadratic_program_from_mps}\\ -\ccRefIdfierPage{Nonnegative_linear_program_from_iterators}\\ -\ccRefIdfierPage{Nonnegative_linear_program_from_pointers} +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps}\\ +\ccc{Nonnegative_linear_program_from_iterators} \end{ccRefFunction} diff --git a/QP_solver/doc_tex/QP_solver_ref/solve_nonnegative_quadratic_program.tex b/QP_solver/doc_tex/QP_solver_ref/solve_nonnegative_quadratic_program.tex index 6a863bf7b72..c2590efb4a6 100644 --- a/QP_solver/doc_tex/QP_solver_ref/solve_nonnegative_quadratic_program.tex +++ b/QP_solver/doc_tex/QP_solver_ref/solve_nonnegative_quadratic_program.tex @@ -17,18 +17,31 @@ with exact number type \ccc{ET}.} be an exact type, and all entries of \ccc{qp} are convertible to \ccc{ET}. +Here are some recommended combinations of input type (the type of +the \ccc{qp} entries) and \ccc{ET}. + +\begin{tabular}{lll} +input type &| & \ccc{ET} \\ \hline +\ccc{double} &| & \ccc{MP_Float}, \ccc{Gmpzf}, or \ccc{Gmpq} \\ +\ccc{int} &| & \ccc{MP_Float}, or \ccc{Gmpz} \\ +any exact type \ccc{NT} &|& \ccc{NT} +\end{tabular} + {\bf Note:} by default, this function performs a large number of runtime-checks to ensure consistency during the solution process. However, these checks slow down the computations by a considerable factor. For maximum efficiency, it is advisable to define the macros \texttt{CGAL\_QP\_NO\_ASSERTIONS} or \texttt{NDEBUG}. +\ccExample +\ccReferToExampleCode{QP_solver/first_nonnegative_qp.cpp} + \ccSeeAlso The models of \ccRefIdfierPage{NonnegativeQuadraticProgramInterface}: -\ccRefIdfierPage{Quadratic_program}\\ -\ccRefIdfierPage{Quadratic_program_from_mps}\\ -\ccRefIdfierPage{Nonnegative_quadratic_program_from_iterators}\\ -\ccRefIdfierPage{Nonnegative_quadratic_program_from_pointers} +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps}\\ +\ccc{Nonnegative_quadratic_program_from_iterators} + \end{ccRefFunction} diff --git a/QP_solver/doc_tex/QP_solver_ref/solve_quadratic_program.tex b/QP_solver/doc_tex/QP_solver_ref/solve_quadratic_program.tex index 7bd3a9a7f67..8c57330561d 100644 --- a/QP_solver/doc_tex/QP_solver_ref/solve_quadratic_program.tex +++ b/QP_solver/doc_tex/QP_solver_ref/solve_quadratic_program.tex @@ -17,19 +17,30 @@ with exact number type \ccc{ET}.} be an exact type, and all entries of \ccc{qp} are convertible to \ccc{ET}. +Here are some recommended combinations of input type (the type of +the \ccc{qp} entries) and \ccc{ET}. + +\begin{tabular}{lll} +input type &| & \ccc{ET} \\ \hline +\ccc{double} &| & \ccc{MP_Float}, \ccc{Gmpzf}, or \ccc{Gmpq} \\ +\ccc{int} &| & \ccc{MP_Float}, or \ccc{Gmpz} \\ +any exact type \ccc{NT} &|& \ccc{NT} +\end{tabular} + {\bf Note:} by default, this function performs a large number of runtime-checks to ensure consistency during the solution process. However, these checks slow down the computations by a considerable factor. For maximum efficiency, it is advisable to define the macros \texttt{CGAL\_QP\_NO\_ASSERTIONS} or \texttt{NDEBUG}. +\ccExample +\ccReferToExampleCode{QP_solver/first_qp.cpp} + \ccSeeAlso The models of \ccRefIdfierPage{QuadraticProgramInterface}: -\ccRefIdfierPage{Quadratic_program}\\ -\ccRefIdfierPage{Quadratic_program_from_mps}\\ -\ccRefIdfierPage{Quadratic_program_from_iterators}\\ -\ccRefIdfierPage{Quadratic_program_from_pointers} - +\ccc{Quadratic_program}\\ +\ccc{Quadratic_program_from_mps}\\ +\ccc{Quadratic_program_from_iterators} \end{ccRefFunction} diff --git a/QP_solver/examples/QP_solver/convex_hull_containment.cpp b/QP_solver/examples/QP_solver/convex_hull_containment.cpp index 1aea7732220..ccd8986882a 100644 --- a/QP_solver/examples/QP_solver/convex_hull_containment.cpp +++ b/QP_solver/examples/QP_solver/convex_hull_containment.cpp @@ -14,7 +14,7 @@ bool is_in_convex_hull (const Point_d& p, { CGAL::Quadratic_program_solution s = solve_convex_hull_containment_lp (p, begin, end, CGAL::MP_Float()); - return s.status() != CGAL::QP_INFEASIBLE; + return !s.is_infeasible(); } int main() diff --git a/QP_solver/examples/QP_solver/first_lp.cpp b/QP_solver/examples/QP_solver/first_lp.cpp index 07ae0ff1fc1..447c8072002 100644 --- a/QP_solver/examples/QP_solver/first_lp.cpp +++ b/QP_solver/examples/QP_solver/first_lp.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -12,29 +13,22 @@ typedef CGAL::Gmpz ET; #endif // program and solution types -typedef CGAL::Linear_program_from_pointers Program; +typedef CGAL::Quadratic_program Program; typedef CGAL::Quadratic_program_solution Solution; int main() { - int Ax[] = {1, -1}; // column for x - int Ay[] = {1, 2}; // column for y - int* A[] = {Ax, Ay}; // A comes columnwise - int b[] = {7, 4}; // right-hand side - CGAL::Comparison_result - r[] = {CGAL::SMALLER, CGAL::SMALLER}; // constraints are "<=" - bool fl[] = {true, true}; // both x, y are lower-bounded - int l[] = {0, 0}; - bool fu[] = {false, true}; // only y is upper-bounded - int u[] = {0, 4}; // x's u-entry is ignored - int c[] = {0, -32}; - int c0 = 64; // constant term - - // now construct the linear program; the first two parameters are - // the number of variables and the number of constraints (rows of A) - Program lp (2, 2, A, b, r, fl, l, fu, u, c, c0); + // by default, we have a nonnegative QP with Ax <= b + Program lp (CGAL::SMALLER, true, 0, false, 0); + + // now set the non-default entries: 0 <-> x, 1 <-> y + lp.set_a(0, 0, 1); lp.set_a(1, 0, 1); lp.set_b(0, 7); // x + y <= 7 + lp.set_a(0, 1, -1); lp.set_a(1, 1, 2); lp.set_b(1, 4); // -x + 2y <= 4 + lp.set_u(1, true, 4); // y <= 4 + lp.set_c(1, -32); // -32y + lp.set_c0(64); // +64 // solve the program, using ET as the exact type - Solution s = CGAL::solve_linear_program(lp, ET()); + Solution s = CGAL::solve_quadratic_program(lp, ET()); // output solution if (s.is_optimal()) { // we know that, don't we? diff --git a/QP_solver/examples/QP_solver/first_lp.mps b/QP_solver/examples/QP_solver/first_lp.mps new file mode 100644 index 00000000000..f93b0b33d2b --- /dev/null +++ b/QP_solver/examples/QP_solver/first_lp.mps @@ -0,0 +1,18 @@ +NAME first_lp +ROWS + N obj + L c0 + L c1 +COLUMNS + x0 c0 1 + x0 c1 -1 + x1 obj -32 + x1 c0 1 + x1 c1 2 +RHS + rhs obj -64 + rhs c0 7 + rhs c1 4 +BOUNDS + UP BND x1 4 +ENDATA diff --git a/QP_solver/examples/QP_solver/first_lp_from_iterators.cpp b/QP_solver/examples/QP_solver/first_lp_from_iterators.cpp new file mode 100644 index 00000000000..68368571b28 --- /dev/null +++ b/QP_solver/examples/QP_solver/first_lp_from_iterators.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include + +// choose exact integral type +#ifndef CGAL_USE_GMP +#include +typedef CGAL::MP_Float ET; +#else +#include +typedef CGAL::Gmpz ET; +#endif + +// program and solution types +typedef CGAL::Linear_program_from_iterators +, // for r + bool*, // for fl + int*, // for l + bool*, // for fu + int*, // for u + int*> // for c +Program; +typedef CGAL::Quadratic_program_solution Solution; + +int main() { + int Ax[] = {1, -1}; // column for x + int Ay[] = {1, 2}; // column for y + int* A[] = {Ax, Ay}; // A comes columnwise + int b[] = {7, 4}; // right-hand side + CGAL::Const_oneset_iterator + r( CGAL::SMALLER); // constraints are "<=" + bool fl[] = {true, true}; // both x, y are lower-bounded + int l[] = {0, 0}; + bool fu[] = {false, true}; // only y is upper-bounded + int u[] = {0, 4}; // x's u-entry is ignored + int c[] = {0, -32}; + int c0 = 64; // constant term + + // now construct the linear program; the first two parameters are + // the number of variables and the number of constraints (rows of A) + Program lp (2, 2, A, b, r, fl, l, fu, u, c, c0); + + // solve the program, using ET as the exact type + Solution s = CGAL::solve_linear_program(lp, ET()); + + // output solution + if (s.is_optimal()) { // we know that, don't we? + std::cout << "Optimal feasible solution: "; + for (Solution::Variable_value_iterator it = s.variable_values_begin(); + it != s.variable_values_end(); ++it) + std::cout << *it << " "; + std::cout << std::endl << "Optimal objective function value: " + << s.objective_value() << std::endl; + } + + return 0; +} diff --git a/QP_solver/examples/QP_solver/first_lp_from_mps.cpp b/QP_solver/examples/QP_solver/first_lp_from_mps.cpp new file mode 100644 index 00000000000..86960cf9ff8 --- /dev/null +++ b/QP_solver/examples/QP_solver/first_lp_from_mps.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +// choose exact integral type +#ifndef CGAL_USE_GMP +#include +typedef CGAL::MP_Float ET; +#else +#include +typedef CGAL::Gmpz ET; +#endif + +// program and solution types +typedef CGAL::Quadratic_program_from_mps Program; +typedef CGAL::Quadratic_program_solution Solution; + +int main() { + std::ifstream in ("first_lp.mps"); + Program lp(in); // read program from file + assert (lp.is_valid()); // we should have a valid mps file,... + assert (lp.is_linear());// ...and it encodes a linear program + + // solve the program, using ET as the exact type + Solution s = CGAL::solve_linear_program(lp, ET()); + + // output solution + if (s.is_optimal()) { // we know that, don't we? + std::cout << "Optimal feasible solution: "; + for (Solution::Variable_value_iterator it = s.variable_values_begin(); + it != s.variable_values_end(); ++it) + std::cout << *it << " "; + std::cout << std::endl << "Optimal objective function value: " + << s.objective_value() << std::endl; + } + + return 0; +} diff --git a/QP_solver/examples/QP_solver/first_nonnegative_lp.cpp b/QP_solver/examples/QP_solver/first_nonnegative_lp.cpp index 23197bb903e..97e4f07f60a 100644 --- a/QP_solver/examples/QP_solver/first_nonnegative_lp.cpp +++ b/QP_solver/examples/QP_solver/first_nonnegative_lp.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -12,24 +13,20 @@ typedef CGAL::Gmpz ET; #endif // program and solution types -typedef CGAL::Nonnegative_linear_program_from_pointers Program; +typedef CGAL::Quadratic_program Program; typedef CGAL::Quadratic_program_solution Solution; int main() { - int Ax[] = {1, -1}; // column for x - int Ay[] = {1, 2}; // column for y - int* A[] = {Ax, Ay}; // A comes columnwise - int b[] = {7, 4}; // right-hand side - CGAL::Comparison_result - r[] = {CGAL::SMALLER, CGAL::SMALLER}; // constraints are "<=" - int c[] = {0, -32}; - - // now construct the linear program; the first two parameters are - // the number of variables and the number of constraints (rows of A) - Program lp (2, 2, A, b, r, c); // constant term defaults to 0 + // by default, we have a nonnegative QP with Ax <= b + Program lp (CGAL::SMALLER, true, 0, false, 0); + + // now set the non-default entries: 0 <-> x, 1 <-> y + lp.set_a(0, 0, 1); lp.set_a(1, 0, 1); lp.set_b(0, 7); // x + y <= 7 + lp.set_a(0, 1, -1); lp.set_a(1, 1, 2); lp.set_b(1, 4); // -x + 2y <= 4 + lp.set_c(1, -32); // -32y // solve the program, using ET as the exact type - Solution s = CGAL::solve_nonnegative_linear_program(lp, ET()); + Solution s = CGAL::solve_quadratic_program(lp, ET()); // output solution if (s.is_optimal()) { // we know that, don't we? diff --git a/QP_solver/examples/QP_solver/first_nonnegative_lp.mps b/QP_solver/examples/QP_solver/first_nonnegative_lp.mps new file mode 100644 index 00000000000..13a49f4cd47 --- /dev/null +++ b/QP_solver/examples/QP_solver/first_nonnegative_lp.mps @@ -0,0 +1,15 @@ +NAME first_nonnegative_lp +ROWS + N obj + L c0 + L c1 +COLUMNS + x0 c0 1 + x0 c1 -1 + x1 obj -32 + x1 c0 1 + x1 c1 2 +RHS + rhs c0 7 + rhs c1 4 +ENDATA diff --git a/QP_solver/examples/QP_solver/first_nonnegative_lp_from_iterators.cpp b/QP_solver/examples/QP_solver/first_nonnegative_lp_from_iterators.cpp new file mode 100644 index 00000000000..eb63d6d4f54 --- /dev/null +++ b/QP_solver/examples/QP_solver/first_nonnegative_lp_from_iterators.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +// choose exact integral type +#ifndef CGAL_USE_GMP +#include +typedef CGAL::MP_Float ET; +#else +#include +typedef CGAL::Gmpz ET; +#endif + +// program and solution types +typedef CGAL::Nonnegative_linear_program_from_iterators +, // for r + int*> // for c +Program; +typedef CGAL::Quadratic_program_solution Solution; + +int main() { + int Ax[] = {1, -1}; // column for x + int Ay[] = {1, 2}; // column for y + int* A[] = {Ax, Ay}; // A comes columnwise + int b[] = {7, 4}; // right-hand side + CGAL::Const_oneset_iterator + r( CGAL::SMALLER); // constraints are "<=" + int c[] = {0, -32}; + + // now construct the linear program; the first two parameters are + // the number of variables and the number of constraints (rows of A) + Program lp (2, 2, A, b, r, c); // constant term defaults to 0 + + // solve the program, using ET as the exact type + Solution s = CGAL::solve_nonnegative_linear_program(lp, ET()); + + // output solution + if (s.is_optimal()) { // we know that, don't we? + std::cout << "Optimal feasible solution: "; + for (Solution::Variable_value_iterator it = s.variable_values_begin(); + it != s.variable_values_end(); ++it) + std::cout << *it << " "; + std::cout << std::endl << "Optimal objective function value: " + << s.objective_value() << std::endl; + } + + return 0; +} diff --git a/QP_solver/examples/QP_solver/first_nonnegative_lp_from_mps.cpp b/QP_solver/examples/QP_solver/first_nonnegative_lp_from_mps.cpp new file mode 100644 index 00000000000..387a31fe693 --- /dev/null +++ b/QP_solver/examples/QP_solver/first_nonnegative_lp_from_mps.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include + +// choose exact integral type +#ifndef CGAL_USE_GMP +#include +typedef CGAL::MP_Float ET; +#else +#include +typedef CGAL::Gmpz ET; +#endif + +// program and solution types +typedef CGAL::Quadratic_program_from_mps Program; +typedef CGAL::Quadratic_program_solution Solution; + +int main() { + std::ifstream in ("first_nonnegative_lp.mps"); + Program lp(in); // read program from file + assert (lp.is_valid()); // we should have a valid mps file,... + assert (lp.is_linear());// ..and it encodes a linear program,... + assert (lp.is_nonnegative()); // ...and it should be nonnegative + + // solve the program, using ET as the exact type + Solution s = CGAL::solve_nonnegative_linear_program(lp, ET()); + + // output solution + if (s.is_optimal()) { // we know that, don't we? + std::cout << "Optimal feasible solution: "; + for (Solution::Variable_value_iterator it = s.variable_values_begin(); + it != s.variable_values_end(); ++it) + std::cout << *it << " "; + std::cout << std::endl << "Optimal objective function value: " + << s.objective_value() << std::endl; + } + + return 0; +} diff --git a/QP_solver/examples/QP_solver/first_nonnegative_qp.cpp b/QP_solver/examples/QP_solver/first_nonnegative_qp.cpp index 03fd19929b6..db103ef56a4 100644 --- a/QP_solver/examples/QP_solver/first_nonnegative_qp.cpp +++ b/QP_solver/examples/QP_solver/first_nonnegative_qp.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -12,28 +13,22 @@ typedef CGAL::Gmpz ET; #endif // program and solution types -typedef CGAL::Nonnegative_quadratic_program_from_pointers Program; +typedef CGAL::Quadratic_program Program; typedef CGAL::Quadratic_program_solution Solution; int main() { - int Ax[] = {1, -1}; // column for x - int Ay[] = {1, 2}; // column for y - int* A[] = {Ax, Ay}; // A comes columnwise - int b[] = {7, 4}; // right-hand side - CGAL::Comparison_result - r[] = {CGAL::SMALLER, CGAL::SMALLER}; // constraints are "<=" - int D1[] = {2}; // 2D_{1,1} - int D2[] = {0, 8}; // 2D_{2,1}, 2D_{2,2} - int* D[] = {D1, D2}; // D-entries on/below diagonal - int c[] = {0, -32}; - int c0 = 64; // constant term - - // now construct the quadratic program; the first two parameters are - // the number of variables and the number of constraints (rows of A) - Program qp (2, 2, A, b, r, D, c, c0); + // by default, we have a nonnegative QP with Ax <= b + Program qp (CGAL::SMALLER, true, 0, false, 0); + + // now set the non-default entries: 0 <-> x, 1 <-> y + qp.set_a(0, 0, 1); qp.set_a(1, 0, 1); qp.set_b(0, 7); // x + y <= 7 + qp.set_a(0, 1, -1); qp.set_a(1, 1, 2); qp.set_b(1, 4); // -x + 2y <= 4 + qp.set_d(0, 0, 2); qp.set_d (1, 1, 8); // x^2 + 4 y^2 + qp.set_c(1, -32); // -32y + qp.set_c0(64); // +64 // solve the program, using ET as the exact type - Solution s = CGAL::solve_nonnegative_quadratic_program(qp, ET()); + Solution s = CGAL::solve_quadratic_program(qp, ET()); // output solution if (s.is_optimal()) { // we know that, don't we? diff --git a/QP_solver/examples/QP_solver/first_nonnegative_qp.mps b/QP_solver/examples/QP_solver/first_nonnegative_qp.mps new file mode 100644 index 00000000000..a260cd7db8e --- /dev/null +++ b/QP_solver/examples/QP_solver/first_nonnegative_qp.mps @@ -0,0 +1,19 @@ +NAME first_nonnegative_qp +ROWS + N obj + L c0 + L c1 +COLUMNS + x0 c0 1 + x0 c1 -1 + x1 obj -32 + x1 c0 1 + x1 c1 2 +RHS + rhs obj -64 + rhs c0 7 + rhs c1 4 +QMATRIX + x0 x0 2 + x1 x1 8 +ENDATA diff --git a/QP_solver/examples/QP_solver/first_nonnegative_qp_from_iterators.cpp b/QP_solver/examples/QP_solver/first_nonnegative_qp_from_iterators.cpp new file mode 100644 index 00000000000..27ea78fdc5e --- /dev/null +++ b/QP_solver/examples/QP_solver/first_nonnegative_qp_from_iterators.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +// choose exact integral type +#ifndef CGAL_USE_GMP +#include +typedef CGAL::MP_Float ET; +#else +#include +typedef CGAL::Gmpz ET; +#endif + +// program and solution types +typedef CGAL::Nonnegative_quadratic_program_from_iterators +, // for r + int**, // for D + int*> // for c +Program; +typedef CGAL::Quadratic_program_solution Solution; + +int main() { + int Ax[] = {1, -1}; // column for x + int Ay[] = {1, 2}; // column for y + int* A[] = {Ax, Ay}; // A comes columnwise + int b[] = {7, 4}; // right-hand side + CGAL::Const_oneset_iterator + r( CGAL::SMALLER); // constraints are "<=" + int D1[] = {2}; // 2D_{1,1} + int D2[] = {0, 8}; // 2D_{2,1}, 2D_{2,2} + int* D[] = {D1, D2}; // D-entries on/below diagonal + int c[] = {0, -32}; + int c0 = 64; // constant term + + // now construct the quadratic program; the first two parameters are + // the number of variables and the number of constraints (rows of A) + Program qp (2, 2, A, b, r, D, c, c0); + + // solve the program, using ET as the exact type + Solution s = CGAL::solve_nonnegative_quadratic_program(qp, ET()); + + // output solution + if (s.is_optimal()) { // we know that, don't we? + std::cout << "Optimal feasible solution: "; + for (Solution::Variable_value_iterator it = s.variable_values_begin(); + it != s.variable_values_end(); ++it) + std::cout << *it << " "; + std::cout << std::endl << "Optimal objective function value: " + << s.objective_value() << std::endl; + } + + return 0; +} diff --git a/QP_solver/examples/QP_solver/first_nonnegative_qp_from_mps.cpp b/QP_solver/examples/QP_solver/first_nonnegative_qp_from_mps.cpp new file mode 100644 index 00000000000..7e2cdd293ae --- /dev/null +++ b/QP_solver/examples/QP_solver/first_nonnegative_qp_from_mps.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +// choose exact integral type +#ifndef CGAL_USE_GMP +#include +typedef CGAL::MP_Float ET; +#else +#include +typedef CGAL::Gmpz ET; +#endif + +// program and solution types +typedef CGAL::Quadratic_program_from_mps Program; +typedef CGAL::Quadratic_program_solution Solution; + +int main() { + std::ifstream in ("first_nonnegative_qp.mps"); + Program qp(in); // read program from file + assert (qp.is_valid()); // we should have a valid mps file,... + assert (qp.is_nonnegative()); // ...and it should be nonnegative + + // solve the program, using ET as the exact type + Solution s = CGAL::solve_nonnegative_quadratic_program(qp, ET()); + + // output solution + if (s.is_optimal()) { // we know that, don't we? + std::cout << "Optimal feasible solution: "; + for (Solution::Variable_value_iterator it = s.variable_values_begin(); + it != s.variable_values_end(); ++it) + std::cout << *it << " "; + std::cout << std::endl << "Optimal objective function value: " + << s.objective_value() << std::endl; + } + + return 0; +} diff --git a/QP_solver/examples/QP_solver/first_qp.cpp b/QP_solver/examples/QP_solver/first_qp.cpp index 7b271db1121..882c5446175 100644 --- a/QP_solver/examples/QP_solver/first_qp.cpp +++ b/QP_solver/examples/QP_solver/first_qp.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -12,29 +13,20 @@ typedef CGAL::Gmpz ET; #endif // program and solution types -typedef CGAL::Quadratic_program_from_pointers Program; +typedef CGAL::Quadratic_program Program; typedef CGAL::Quadratic_program_solution Solution; int main() { - int Ax[] = {1, -1}; // column for x - int Ay[] = {1, 2}; // column for y - int* A[] = {Ax, Ay}; // A comes columnwise - int b[] = {7, 4}; // right-hand side - CGAL::Comparison_result - r[] = {CGAL::SMALLER, CGAL::SMALLER}; // constraints are "<=" - bool fl[] = {true, true}; // both x, y are lower-bounded - int l[] = {0, 0}; - bool fu[] = {false, true}; // only y is upper-bounded - int u[] = {0, 4}; // x's u-entry is ignored - int D1[] = {2}; // 2D_{1,1} - int D2[] = {0, 8}; // 2D_{2,1}, 2D_{2,2} - int* D[] = {D1, D2}; // D-entries on/below diagonal - int c[] = {0, -32}; - int c0 = 64; // constant term - - // now construct the quadratic program; the first two parameters are - // the number of variables and the number of constraints (rows of A) - Program qp (2, 2, A, b, r, fl, l, fu, u, D, c, c0); + // by default, we have a nonnegative QP with Ax <= b + Program qp (CGAL::SMALLER, true, 0, false, 0); + + // now set the non-default entries: 0 <-> x, 1 <-> y + qp.set_a(0, 0, 1); qp.set_a(1, 0, 1); qp.set_b(0, 7); // x + y <= 7 + qp.set_a(0, 1, -1); qp.set_a(1, 1, 2); qp.set_b(1, 4); // -x + 2y <= 4 + qp.set_u(1, true, 4); // y <= 4 + qp.set_d(0, 0, 2); qp.set_d (1, 1, 8); // x^2 + 4 y^2 + qp.set_c(1, -32); // -32y + qp.set_c0(64); // +64 // solve the program, using ET as the exact type Solution s = CGAL::solve_quadratic_program(qp, ET()); @@ -49,7 +41,5 @@ int main() { << s.objective_value() << std::endl; } - CGAL::print_quadratic_program(std::cout, qp); - return 0; } diff --git a/QP_solver/examples/QP_solver/first_qp.mps b/QP_solver/examples/QP_solver/first_qp.mps new file mode 100644 index 00000000000..cddf7ca8960 --- /dev/null +++ b/QP_solver/examples/QP_solver/first_qp.mps @@ -0,0 +1,21 @@ +NAME first_qp +ROWS + N obj + L c0 + L c1 +COLUMNS + x0 c0 1 + x0 c1 -1 + x1 obj -32 + x1 c0 1 + x1 c1 2 +RHS + rhs obj -64 + rhs c0 7 + rhs c1 4 +BOUNDS + UP BND x1 4 +QMATRIX + x0 x0 2 + x1 x1 8 +ENDATA diff --git a/QP_solver/examples/QP_solver/first_qp_from_iterators.cpp b/QP_solver/examples/QP_solver/first_qp_from_iterators.cpp new file mode 100644 index 00000000000..16d64c47a3f --- /dev/null +++ b/QP_solver/examples/QP_solver/first_qp_from_iterators.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +// choose exact integral type +#ifndef CGAL_USE_GMP +#include +typedef CGAL::MP_Float ET; +#else +#include +typedef CGAL::Gmpz ET; +#endif + +// program and solution types +typedef CGAL::Quadratic_program_from_iterators +, // for r + bool*, // for fl + int*, // for l + bool*, // for fu + int*, // for u + int**, // for D + int*> // for c +Program; +typedef CGAL::Quadratic_program_solution Solution; + +int main() { + int Ax[] = {1, -1}; // column for x + int Ay[] = {1, 2}; // column for y + int* A[] = {Ax, Ay}; // A comes columnwise + int b[] = {7, 4}; // right-hand side + CGAL::Const_oneset_iterator + r( CGAL::SMALLER); // constraints are "<=" + bool fl[] = {true, true}; // both x, y are lower-bounded + int l[] = {0, 0}; + bool fu[] = {false, true}; // only y is upper-bounded + int u[] = {0, 4}; // x's u-entry is ignored + int D1[] = {2}; // 2D_{1,1} + int D2[] = {0, 8}; // 2D_{2,1}, 2D_{2,2} + int* D[] = {D1, D2}; // D-entries on/below diagonal + int c[] = {0, -32}; + int c0 = 64; // constant term + + // now construct the quadratic program; the first two parameters are + // the number of variables and the number of constraints (rows of A) + Program qp (2, 2, A, b, r, fl, l, fu, u, D, c, c0); + + // solve the program, using ET as the exact type + Solution s = CGAL::solve_quadratic_program(qp, ET()); + + // output solution + if (s.is_optimal()) { // we know that, don't we? + std::cout << "Optimal feasible solution: "; + for (Solution::Variable_value_iterator it = s.variable_values_begin(); + it != s.variable_values_end(); ++it) + std::cout << *it << " "; + std::cout << std::endl << "Optimal objective function value: " + << s.objective_value() << std::endl; + } + + return 0; +} diff --git a/QP_solver/examples/QP_solver/first_qp_from_mps.cpp b/QP_solver/examples/QP_solver/first_qp_from_mps.cpp new file mode 100644 index 00000000000..f3b08664d9b --- /dev/null +++ b/QP_solver/examples/QP_solver/first_qp_from_mps.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include + +// choose exact integral type +#ifndef CGAL_USE_GMP +#include +typedef CGAL::MP_Float ET; +#else +#include +typedef CGAL::Gmpz ET; +#endif + +// program and solution types +typedef CGAL::Quadratic_program_from_mps Program; +typedef CGAL::Quadratic_program_solution 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 + if (s.is_optimal()) { // we know that, don't we? + std::cout << "Optimal feasible solution: "; + for (Solution::Variable_value_iterator it = s.variable_values_begin(); + it != s.variable_values_end(); ++it) + std::cout << *it << " "; + std::cout << std::endl << "Optimal objective function value: " + << s.objective_value() << std::endl; + } + + return 0; +} diff --git a/QP_solver/examples/QP_solver/important_variables.cpp b/QP_solver/examples/QP_solver/important_variables.cpp index 64ed92ef8c1..d996b6a5a8b 100644 --- a/QP_solver/examples/QP_solver/important_variables.cpp +++ b/QP_solver/examples/QP_solver/important_variables.cpp @@ -12,26 +12,29 @@ typedef CGAL::Quadratic_program_solution Solution; int main() { std::vector points; - // convex hull: line spanned by {(0,0), (1,0),..., (9,0)} - for (int j=0; j<10; ++j) - points.push_back (Point_d (j, 0)); - - for (double f=0.5; f<10; ++f) { - Point_d p (f, 0.0); - Solution s = solve_convex_hull_containment_lp - (p, points.begin(), points.end(), CGAL::MP_Float()); - std::cout << p; - if (s.status() == CGAL::QP_INFEASIBLE) - std::cout << " is not in the convex hull." << std::endl; - else { - std::cout << " is a convex combination of the points "; - Solution::Index_iterator it = s.basic_variable_indices_begin(); - Solution::Index_iterator end = s.basic_variable_indices_end(); - for (; it != end; ++it) - std::cout << points[*it] << " "; - std::cout << std::endl; + // convex hull: 4-gon spanned by {(1,0), (4,1), (4,4), (2,3)} + points.push_back (Point_d (1, 0)); + points.push_back (Point_d (4, 1)); + points.push_back (Point_d (4, 4)); + points.push_back (Point_d (2, 3)); + + // test all 25 integer points in [0,4]^2 + for (int i=0; i<=4; ++i) + for (int j=0; j<=4; ++j) { + Point_d p (i, j); + Solution s = solve_convex_hull_containment_lp + (p, points.begin(), points.end(), CGAL::MP_Float()); + std::cout << p; + if (s.is_infeasible()) + std::cout << " is not in the convex hull\n"; + else { + assert (s.is_optimal()); + std::cout << " is a convex combination of the points "; + Solution::Index_iterator it = s.basic_variable_indices_begin(); + Solution::Index_iterator end = s.basic_variable_indices_end(); + for (; it != end; ++it) std::cout << *it << " "; + std::cout << std::endl; + } } - } - return 0; } diff --git a/QP_solver/examples/QP_solver/print_first_lp.cpp b/QP_solver/examples/QP_solver/print_first_lp.cpp new file mode 100644 index 00000000000..40fc015825e --- /dev/null +++ b/QP_solver/examples/QP_solver/print_first_lp.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +// program type +typedef CGAL::Quadratic_program Program; + +int main() { + // by default, we have a nonnegative QP with Ax <= b + Program lp (CGAL::SMALLER, true, 0, false, 0); + + // now set the non-default entries: 0 <-> x, 1 <-> y + lp.set_a(0, 0, 1); lp.set_a(1, 0, 1); lp.set_b(0, 7); // x + y <= 7 + lp.set_a(0, 1, -1); lp.set_a(1, 1, 2); lp.set_b(1, 4); // -x + 2y <= 4 + lp.set_u(1, true, 4); // y <= 4 + lp.set_c(1, -32); // -32y + lp.set_c0(64); // +64 + + // print the program in MPS format + CGAL::print_linear_program(std::cout, lp, "first_lp"); + + return 0; +} diff --git a/QP_solver/examples/QP_solver/print_first_nonnegative_lp.cpp b/QP_solver/examples/QP_solver/print_first_nonnegative_lp.cpp new file mode 100644 index 00000000000..7c0f8e4a87f --- /dev/null +++ b/QP_solver/examples/QP_solver/print_first_nonnegative_lp.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +// program type +typedef CGAL::Quadratic_program Program; + +int main() { + // by default, we have a nonnegative QP with Ax <= b + Program lp (CGAL::SMALLER, true, 0, false, 0); + + // now set the non-default entries: 0 <-> x, 1 <-> y + lp.set_a(0, 0, 1); lp.set_a(1, 0, 1); lp.set_b(0, 7); // x + y <= 7 + lp.set_a(0, 1, -1); lp.set_a(1, 1, 2); lp.set_b(1, 4); // -x + 2y <= 4 + lp.set_c(1, -32); // -32y + + // print the program in MPS format + CGAL::print_nonnegative_linear_program + (std::cout, lp, "first_nonnegative_lp"); + + return 0; +} diff --git a/QP_solver/examples/QP_solver/print_first_nonnegative_qp.cpp b/QP_solver/examples/QP_solver/print_first_nonnegative_qp.cpp new file mode 100644 index 00000000000..3e218e25fb1 --- /dev/null +++ b/QP_solver/examples/QP_solver/print_first_nonnegative_qp.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +// program type +typedef CGAL::Quadratic_program Program; + +int main() { + // by default, we have a nonnegative QP with Ax <= b + Program qp (CGAL::SMALLER, true, 0, false, 0); + + // now set the non-default entries: 0 <-> x, 1 <-> y + qp.set_a(0, 0, 1); qp.set_a(1, 0, 1); qp.set_b(0, 7); // x + y <= 7 + qp.set_a(0, 1, -1); qp.set_a(1, 1, 2); qp.set_b(1, 4); // -x + 2y <= 4 + qp.set_d(0, 0, 2); qp.set_d (1, 1, 8); // x^2 + 4 y^2 + qp.set_c(1, -32); // -32y + qp.set_c0(64); // +64 + + // print the program in MPS format + CGAL::print_nonnegative_quadratic_program + (std::cout, qp, "first_nonnegative_qp"); + + return 0; +} diff --git a/QP_solver/examples/QP_solver/print_first_qp.cpp b/QP_solver/examples/QP_solver/print_first_qp.cpp new file mode 100644 index 00000000000..973724e0d1e --- /dev/null +++ b/QP_solver/examples/QP_solver/print_first_qp.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +// program type +typedef CGAL::Quadratic_program Program; + +int main() { + // by default, we have a nonnegative QP with Ax <= b + Program qp (CGAL::SMALLER, true, 0, false, 0); + + // now set the non-default entries: 0 <-> x, 1 <-> y + qp.set_a(0, 0, 1); qp.set_a(1, 0, 1); qp.set_b(0, 7); // x + y <= 7 + qp.set_a(0, 1, -1); qp.set_a(1, 1, 2); qp.set_b(1, 4); // -x + 2y <= 4 + qp.set_u(1, true, 4); // y <= 4 + qp.set_d(0, 0, 2); qp.set_d (1, 1, 8); // x^2 + 4 y^2 + qp.set_c(1, -32); // -32y + qp.set_c0(64); // +64 + + // print the program in MPS format + CGAL::print_nonnegative_quadratic_program + (std::cout, qp, "first_qp"); + + return 0; +} diff --git a/QP_solver/include/CGAL/QP_models.h b/QP_solver/include/CGAL/QP_models.h index 4d7ea8b74a0..26a1da0c237 100644 --- a/QP_solver/include/CGAL/QP_models.h +++ b/QP_solver/include/CGAL/QP_models.h @@ -33,15 +33,11 @@ // this file defines the following models: // - Quadratic_program_from_iterators -// - Quadratic_program_from_pointers // - Quadratic_program // - Quadratic_program_from_mps // - Nonngative_quadratic_program_from_iterators -// - Nonengative_quadratic_program_from_pointers // - Linear_program_from_iterators -// - Linear_program_from_pointers // - Nonngative_linear_program_from_iterators -// - Nonengative_linear_program_from_pointers // for convenience, every model is actually a model of the // concept QuadraticProgramInterface: @@ -177,38 +173,6 @@ make_quadratic_program_from_iterators ( (n, m, a, b, r, fl, l, fu, u, d, c, c0); } -// Quadratic_program_from_pointers -// ------------------------------- -template -class Quadratic_program_from_pointers : - public Quadratic_program_from_iterators - -{ -public: - typedef NT_ NT; -private: - typedef Quadratic_program_from_iterators - Base; -public: - QP_MODEL_ITERATOR_TYPES; - Quadratic_program_from_pointers - ( - int n, int m, // number of variables / constraints - const A_iterator& a, - const B_iterator& b, - const R_iterator& r, - const FL_iterator& fl, - const L_iterator& l, - const FU_iterator& fu, - const U_iterator& u, - const D_iterator& d, - const C_iterator& c, - const C_entry& c0 = C_entry(0)) - : Base (n, m, a, b, r, fl, l, fu, u, d, c, c0) - {} -}; // Linear_program_from_iterators // ----------------------------- @@ -280,35 +244,6 @@ make_linear_program_from_iterators ( (n, m, a, b, r, fl, l, fu, u, c, c0); } -// Linear_program_from_pointers -// ---------------------------- -template -class Linear_program_from_pointers : - public Linear_program_from_iterators - -{ -public: - typedef NT_ NT; -private: - typedef Linear_program_from_iterators - Base; -public: - QP_MODEL_ITERATOR_TYPES; - Linear_program_from_pointers ( - int n, int m, // number of variables / constraints - const A_iterator& a, - const B_iterator& b, - const R_iterator& r, - const FL_iterator& fl, - const L_iterator& l, - const FU_iterator& fu, - const U_iterator& u, - const C_iterator& c, - const C_entry& c0 = C_entry(0) - ) - : Base (n, m, a, b, r, fl, l, fu, u, c, c0) - {} -}; // Nonnegative_quadratic_program_from_iterators // -------------------------------------------- @@ -379,35 +314,6 @@ make_nonnegative_quadratic_program_from_iterators ( (n, m, a, b, r, d, c, c0); } -// Nonnegative_Quadratic_program_from_pointers -// ------------------------------------------- -template -class Nonnegative_quadratic_program_from_pointers : - public Nonnegative_quadratic_program_from_iterators - -{ -public: - typedef NT_ NT; -private: - typedef Nonnegative_quadratic_program_from_iterators - Base; -public: - QP_MODEL_ITERATOR_TYPES; - Nonnegative_quadratic_program_from_pointers ( - int n, int m, // number of variables / constraints - const A_iterator& a, - const B_iterator& b, - const R_iterator& r, - const D_iterator& d, - const C_iterator& c, - const C_entry& c0 = C_entry(0) - ) - : Base (n, m, a, b, r, d, c, c0) - {} -}; - - - // Nonnegative_linear_program_from_iterators // ----------------------------------------- @@ -475,31 +381,6 @@ make_nonnegative_linear_program_from_iterators ( (n, m, a, b, r, c, c0); } -// Nonnegative_linear_program_from_pointers -// ---------------------------------------- -template -class Nonnegative_linear_program_from_pointers : - public Nonnegative_linear_program_from_iterators - -{ -public: - typedef NT_ NT; -private: - typedef Nonnegative_linear_program_from_iterators - Base; -public: - QP_MODEL_ITERATOR_TYPES; - Nonnegative_linear_program_from_pointers ( - int n, int m, // number of variables / constraints - const A_iterator& a, - const B_iterator& b, - const R_iterator& r, - const C_iterator& c, - const C_entry& c0 = C_entry(0) - ) - : Base (n, m, a, b, r, c, c0) - {} -}; namespace QP_model_detail { // maps a container to its begin-iterator, as specified by HowToBegin @@ -579,10 +460,10 @@ private: // default settings CGAL::Comparison_result default_r; // from constructor - bool default_fl; // true - NT default_l; // 0 - bool default_fu; // false - NT default_u; // dummy + bool default_fl; // from constructor + NT default_l; // from constructor + bool default_fu; // from constructor + NT default_u; // from constructor protected: bool is_valid_; private: diff --git a/QP_solver/test/QP_solver/test_default_bounds.cpp b/QP_solver/test/QP_solver/test_default_bounds.cpp index 514ae666d02..86d70c90377 100644 --- a/QP_solver/test/QP_solver/test_default_bounds.cpp +++ b/QP_solver/test/QP_solver/test_default_bounds.cpp @@ -14,13 +14,30 @@ typedef CGAL::MP_Float ET; typedef CGAL::Gmpz ET; #endif +int fl; +int fu; +int l; +int u; +int r; + +// inline void check(bool cond) +// { +// if (!cond) { +// std::cout << "fl = " << fl << ", " +// << " l = " << l << ", " +// << "fu = " << fu << ", " +// << " u = " << u << ", " +// << " r = " << r << std::endl; +// } +// } + int main() { - for (bool fl = false; fl < true; ++fl) - for (bool fu = false; fu < true; ++fu) - for (int l = -2; l < 0; ++l) - for (int u = 0; u < 2; ++u) - for (int r = -1; r < 1; ++r) { + for (fl = 0; fl < 2; ++fl) + for (fu = 0; fu < 2; ++fu) + for (l = -2; l <= 0; ++l) + for (u = 0; u <= 2; ++u) + for (r = -1; r < 1; ++r) { // generate empty program with all possible // defaults, and test solver / bound status functions CGAL::Quadratic_program qp @@ -40,7 +57,7 @@ int main() // now manipulate program qp.set_c(0, 1); // min x_0 - // l <= x_0 <= u + // l <= x_0 <= u // test solver s = CGAL::solve_quadratic_program (qp, ET()); if (fl) { @@ -101,13 +118,13 @@ int main() assert (s.is_unbounded()); // manipulate program - qp.set_c(0, -1); // max x_0 + qp.set_c(0, -1); // min -x_0 // test solver s = CGAL::solve_quadratic_program (qp, ET()); if (fu) { assert (s.is_optimal()); - assert (s.objective_value() == u); + assert (s.objective_value() == -u); } else assert (s.is_unbounded()); diff --git a/QP_solver/test/QP_solver/test_random_qp.cpp b/QP_solver/test/QP_solver/test_random_qp.cpp index dde3c4634da..5646501c9e9 100644 --- a/QP_solver/test/QP_solver/test_random_qp.cpp +++ b/QP_solver/test/QP_solver/test_random_qp.cpp @@ -16,7 +16,17 @@ typedef CGAL::Gmpz ET; #endif // program and solution types -typedef CGAL::Quadratic_program_from_pointers Program; +typedef CGAL::Quadratic_program_from_iterators + // for c +Program; typedef CGAL::Quadratic_program_solution Solution; // randum number generator