mirror of https://github.com/CGAL/cgal
Matrix_search
This commit is contained in:
parent
9d0678d397
commit
9b0bf475e6
|
|
@ -2684,6 +2684,16 @@ Manual_tools/test/Manual_tools/cgal_test eol=lf
|
||||||
Manual_tools/test/Manual_tools/html.orig.tgz -text svneol=unset#application/gzip
|
Manual_tools/test/Manual_tools/html.orig.tgz -text svneol=unset#application/gzip
|
||||||
Matrix_search/demo/Matrix_search/help/index.html svneol=native#text/html
|
Matrix_search/demo/Matrix_search/help/index.html svneol=native#text/html
|
||||||
Matrix_search/demo/Matrix_search/help/rindex.html svneol=native#text/html
|
Matrix_search/demo/Matrix_search/help/rindex.html svneol=native#text/html
|
||||||
|
Matrix_search/doc/Matrix_search/CGAL/Dynamic_matrix.h -text
|
||||||
|
Matrix_search/doc/Matrix_search/CGAL/Sorted_matrix_search_traits_adaptor.h -text
|
||||||
|
Matrix_search/doc/Matrix_search/CGAL/monotone_matrix_search.h -text
|
||||||
|
Matrix_search/doc/Matrix_search/CGAL/sorted_matrix_search.h -text
|
||||||
|
Matrix_search/doc/Matrix_search/Concepts/BasicMatrix.h -text
|
||||||
|
Matrix_search/doc/Matrix_search/Concepts/MonotoneMatrixSearchTraits.h -text
|
||||||
|
Matrix_search/doc/Matrix_search/Concepts/SortedMatrixSearchTraits.h -text
|
||||||
|
Matrix_search/doc/Matrix_search/Matrix_search.txt -text
|
||||||
|
Matrix_search/doc/Matrix_search/PkgDescription.txt -text
|
||||||
|
Matrix_search/doc/Matrix_search/fig/matrix.png -text svneol=unset#image/png
|
||||||
Matrix_search/doc_tex/Matrix_search/matrix.png -text
|
Matrix_search/doc_tex/Matrix_search/matrix.png -text
|
||||||
Matrix_search/test/Matrix_search/rectangular_p_center_2_random1_test.cmd eol=lf
|
Matrix_search/test/Matrix_search/rectangular_p_center_2_random1_test.cmd eol=lf
|
||||||
Matrix_search/test/Matrix_search/rectangular_p_center_2_random2_test.cmd eol=lf
|
Matrix_search/test/Matrix_search/rectangular_p_center_2_random2_test.cmd eol=lf
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@ STRIP_FROM_PATH =
|
||||||
STRIP_FROM_INC_PATH = ../../Algebraic_foundations/doc/Algebraic_foundations \
|
STRIP_FROM_INC_PATH = ../../Algebraic_foundations/doc/Algebraic_foundations \
|
||||||
../../Number_types/doc/Number_types \
|
../../Number_types/doc/Number_types \
|
||||||
../../STL_Extension/doc/STL_Extension \
|
../../STL_Extension/doc/STL_Extension \
|
||||||
../../Modular_arithmetic/doc/Modular_arithmetic
|
../../Modular_arithmetic/doc/Modular_arithmetic \
|
||||||
|
../../Matrix_search/doc/Matrix_search
|
||||||
SHORT_NAMES = NO
|
SHORT_NAMES = NO
|
||||||
JAVADOC_AUTOBRIEF = YES
|
JAVADOC_AUTOBRIEF = YES
|
||||||
QT_AUTOBRIEF = YES
|
QT_AUTOBRIEF = YES
|
||||||
|
|
@ -52,8 +53,9 @@ ALIASES += cgalbib{1}="<dl class=\"section\"><dt>BibTeX:</dt><dd>\
|
||||||
ALIASES += license{1}="<dl class=\"section\"><dt>License:</dt><dd>\1</dd></dl>"
|
ALIASES += license{1}="<dl class=\"section\"><dt>License:</dt><dd>\1</dd></dl>"
|
||||||
ALIASES += "models=\xrefitem modelss \"Models\" \"Models\""
|
ALIASES += "models=\xrefitem modelss \"Models\" \"Models\""
|
||||||
ALIASES += "refines=\xrefitem refiness \"Refines\" \"Refines\""
|
ALIASES += "refines=\xrefitem refiness \"Refines\" \"Refines\""
|
||||||
|
ALIASES += "requires=\xrefitem requiress \"Requirements\" \"Requirements\""
|
||||||
ALIASES += "hasModel=\xrefitem asModelss \"Has Models\" \"Has Models\""
|
ALIASES += "hasModel=\xrefitem asModelss \"Has Models\" \"Has Models\""
|
||||||
ALIASES += "advanced=\attention
|
ALIASES += advanced=\attention
|
||||||
ALIASES += "debug=\xrefitem debugs \"Debug\" \"Debug\""
|
ALIASES += "debug=\xrefitem debugs \"Debug\" \"Debug\""
|
||||||
ALIASES += "require=\xrefitem requires \"Requirements\" \"Requirements\""
|
ALIASES += "require=\xrefitem requires \"Requirements\" \"Requirements\""
|
||||||
ALIASES += beginadvanced=""
|
ALIASES += beginadvanced=""
|
||||||
|
|
@ -134,6 +136,7 @@ INPUT = ../../Algebraic_foundations/doc/Algebraic_foundations \
|
||||||
../../Number_types/doc/Number_types \
|
../../Number_types/doc/Number_types \
|
||||||
../../STL_Extension/doc/STL_Extension \
|
../../STL_Extension/doc/STL_Extension \
|
||||||
../../Modular_arithmetic/doc/Modular_arithmetic \
|
../../Modular_arithmetic/doc/Modular_arithmetic \
|
||||||
|
../../Matrix_search/doc/Matrix_search \
|
||||||
.. \
|
.. \
|
||||||
.
|
.
|
||||||
# ../../AABB_tree/doc/AABB_tree \
|
# ../../AABB_tree/doc/AABB_tree \
|
||||||
|
|
@ -188,7 +191,6 @@ INPUT = ../../Algebraic_foundations/doc/Algebraic_foundations \
|
||||||
# ../../Min_sphere_d/doc/Min_sphere_d \
|
# ../../Min_sphere_d/doc/Min_sphere_d \
|
||||||
# ../../Min_sphere_of_spheres_d/doc/Min_sphere_of_spheres_d \
|
# ../../Min_sphere_of_spheres_d/doc/Min_sphere_of_spheres_d \
|
||||||
# ../../Modifier/doc/Modifier \
|
# ../../Modifier/doc/Modifier \
|
||||||
# ../../Modular_arithmetic/doc/Modular_arithmetic \
|
|
||||||
# ../../Nef_2/doc/Nef_2 \
|
# ../../Nef_2/doc/Nef_2 \
|
||||||
# ../../Nef_3/doc/Nef_3 \
|
# ../../Nef_3/doc/Nef_3 \
|
||||||
# ../../Nef_S2/doc/Nef_S2 \
|
# ../../Nef_S2/doc/Nef_S2 \
|
||||||
|
|
@ -239,13 +241,15 @@ EXAMPLE_PATH = ../../Algebraic_foundations/examples/Algebraic_foundati
|
||||||
../../Number_types/examples/Number_types \
|
../../Number_types/examples/Number_types \
|
||||||
../../Convex_hull_2/examples/Convex_hull_2 \
|
../../Convex_hull_2/examples/Convex_hull_2 \
|
||||||
../../STL_Extension/examples/STL_Extension \
|
../../STL_Extension/examples/STL_Extension \
|
||||||
../../Modular_arithmetic/examples/Modular_arithmetic
|
../../Modular_arithmetic/examples/Modular_arithmetic \
|
||||||
|
../../Matrix_search/examples/Matrix_search
|
||||||
EXAMPLE_PATTERNS = *
|
EXAMPLE_PATTERNS = *
|
||||||
EXAMPLE_RECURSIVE = YES
|
EXAMPLE_RECURSIVE = YES
|
||||||
IMAGE_PATH = ../../Algebraic_foundations/doc/Algebraic_foundations/fig \
|
IMAGE_PATH = ../../Algebraic_foundations/doc/Algebraic_foundations/fig \
|
||||||
../../Number_types/doc/Number_types/fig \
|
../../Number_types/doc/Number_types/fig \
|
||||||
../../STL_Extension/doc/STL_Extension/fig \
|
../../STL_Extension/doc/STL_Extension/fig \
|
||||||
../../Modular_arithmetic/doc/Modular_arithmetic/fig
|
../../Modular_arithmetic/doc/Modular_arithmetic/fig \
|
||||||
|
../../Matrix_search/doc/Matrix_search/fig
|
||||||
INPUT_FILTER =
|
INPUT_FILTER =
|
||||||
FILTER_PATTERNS =
|
FILTER_PATTERNS =
|
||||||
FILTER_SOURCE_FILES = NO
|
FILTER_SOURCE_FILES = NO
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,115 @@
|
||||||
|
namespace CGAL {
|
||||||
|
/// \ingroup PkgMatrixSearch
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// The class `Dynamic_matrix` is an adaptor for an
|
||||||
|
/// arbitrary matrix class `M` to provide the dynamic operations
|
||||||
|
/// needed for monotone matrix search.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// Requirements
|
||||||
|
/// --------------
|
||||||
|
/// `M` is a model for `BasicMatrix`.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// \models ::BasicMatrix
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// \sa `BasicMatrix`
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// Implementation
|
||||||
|
/// --------------
|
||||||
|
/// All operations take constant time except for
|
||||||
|
/// `extract_all_even_rows` which needs time linear in the number
|
||||||
|
/// of rows.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
template< M >
|
||||||
|
class Dynamic_matrix {
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \name Creation
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced initializes `d` to `m`. `m` is <I>not</I> copied, we only store a reference.
|
||||||
|
*/
|
||||||
|
Dynamic_matrix( const M& m);
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns the number of columns.
|
||||||
|
*/
|
||||||
|
int number_of_columns() const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns the number of rows.
|
||||||
|
*/
|
||||||
|
int number_of_rows() const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns the entry at position (`row`, `column`).
|
||||||
|
|
||||||
|
\pre \f$ 0 \le\f$ `row` \f$ <\f$ `number_of_rows()`
|
||||||
|
\pre \f$ 0 \le\f$ `column` \f$ <\f$ `number_of_columns()`
|
||||||
|
*/
|
||||||
|
Entry operator()( int row, int column) const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced replace column `old` with column number `new`.
|
||||||
|
\pre \f$ 0 \le\f$ `old`, `new` \f$ <\f$ `number_of_columns()`
|
||||||
|
*/
|
||||||
|
void replace_column( int old, int new);
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns a new Matrix consisting of all rows of `d` with even index, (i.e. first row is row \f$ 0\f$ of `d`, second row is row \f$ 2\f$ of `d` etc.). \pre `number_of_rows()` \f$ > 0\f$.
|
||||||
|
*/
|
||||||
|
Matrix* extract_all_even_rows() const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced deletes the rightmost columns, such that `d` becomes quadratic.
|
||||||
|
|
||||||
|
\pre `number_of_columns()` \f$ \ge\f$ `number_of_rows()`
|
||||||
|
\post `number_of_rows()` \f$ ==\f$ `number_of_columns()`
|
||||||
|
*/
|
||||||
|
void shrink_to_quadratic_size();
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
}; /* class Dynamic_matrix */
|
||||||
|
} /* namespace CGAL */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,116 @@
|
||||||
|
namespace CGAL {
|
||||||
|
/// \ingroup PkgMatrixSearch
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// The class `Sorted_matrix_search_traits_adaptor` can be used as an
|
||||||
|
/// adaptor to create sorted matrix search traits classes for
|
||||||
|
/// arbitrary feasibility test and matrix classes `F` resp.
|
||||||
|
/// `M`.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// \models ::SortedMatrixSearchTraits
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// Requirements
|
||||||
|
/// --------------
|
||||||
|
///
|
||||||
|
/// <OL>
|
||||||
|
/// <LI>`M` is a model for `BasicMatrix` <I>and</I>
|
||||||
|
/// <LI>`F` defines a copy constructor and a monotone `bool
|
||||||
|
/// operator()( const Value&)`.
|
||||||
|
/// </OL>
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
template< F,M >
|
||||||
|
class Sorted_matrix_search_traits_adaptor {
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \name Creation
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced initializes `t` to use `m` for feasibility testing.
|
||||||
|
*/
|
||||||
|
Sorted_matrix_search_traits_adaptor<F,M>( const F&
|
||||||
|
m);
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Types
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced typedef to `M`.
|
||||||
|
*/
|
||||||
|
typedef Hidden_type Matrix;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Types
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced typedef to `Matrix::Value`.
|
||||||
|
*/
|
||||||
|
typedef Hidden_type Value;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Types
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced typedef to
|
||||||
|
`std::less<Value>`.
|
||||||
|
*/
|
||||||
|
typedef Hidden_type Compare_strictly;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Types
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced typedef to
|
||||||
|
`std::less_equal<Value>`.
|
||||||
|
*/
|
||||||
|
typedef Hidden_type Compare_non_strictly;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns the `Compare_strictly` object to be used for the search.
|
||||||
|
*/
|
||||||
|
Compare_strictly compare_strictly()
|
||||||
|
const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns the `Compare_non_strictly` object to be used for the search.
|
||||||
|
*/
|
||||||
|
Compare_non_strictly compare_non_strictly()
|
||||||
|
const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced uses the feasibility test given during creation.
|
||||||
|
*/
|
||||||
|
bool is_feasible(const Value& a);
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}; /* class Sorted_matrix_search_traits_adaptor */
|
||||||
|
} /* namespace CGAL */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
///
|
||||||
|
namespace CGAL {
|
||||||
|
/// \ingroup PkgMatrixSearch
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// The function `monotone_matrix_search` computes the maxima for all
|
||||||
|
/// rows of a totally monotone matrix.
|
||||||
|
/// More precisely, monotony for matrices is defined as follows.
|
||||||
|
/// Let \f$ K\f$ be a totally ordered set, \f$ M \in K^{(n,\, m)}\f$
|
||||||
|
/// a matrix over \f$ K\f$ and for \f$ 0 \le i < n\f$:
|
||||||
|
/// \f[
|
||||||
|
/// rmax_M(i) :\in \left\{ \min_{0 \le j < m} j \: \left|\:
|
||||||
|
/// M[i,\, j] = \max_{0 \le k < m} M[i,\, k] \right.\right\}
|
||||||
|
/// \f]
|
||||||
|
/// the (leftmost) column containing the maximum entry in row
|
||||||
|
/// \f$ i\f$. \f$ M\f$ is called monotone, iff
|
||||||
|
/// \f[
|
||||||
|
/// \forall\, 0 \le i_1 < i_2 < n\: :\: rmax_M(i_1) \le
|
||||||
|
/// rmax_M(i_2)\; .
|
||||||
|
/// \f]
|
||||||
|
/// \f$ M\f$ is totally monotone, iff all of its submatrices are
|
||||||
|
/// monotone (or equivalently: iff all \f$ 2 \times 2\f$ submatrices are
|
||||||
|
/// monotone).
|
||||||
|
///
|
||||||
|
/// It computes the maximum (as specified by `compare_strictly`)
|
||||||
|
/// entry for each row of `m` and writes the corresponding column
|
||||||
|
/// to `t`, i.e. `t[i]` is set to the index of the column
|
||||||
|
/// containing the maximum element in row `i`. The maximum \f$ m_r\f$
|
||||||
|
/// of a row \f$ r\f$ is the leftmost element for which
|
||||||
|
/// `compare_strictly`\f$ (m_r,\,x)\f$ is false for all elements \f$ x\f$ in
|
||||||
|
/// \f$ r\f$.
|
||||||
|
/// \pre `t` points to a structure of size at least
|
||||||
|
/// `m.number_of_rows()`
|
||||||
|
/// \require `Matrix` is a model for `MonotoneMatrixSearchTraits`
|
||||||
|
/// \require Value type of `RandomAccessIC` is `int`.
|
||||||
|
/// \require If `compare_strictly` is defined, it is an adaptable binary function: `Matrix::Value` \f$ \times\f$
|
||||||
|
/// `Matrix::Value` \f$ \rightarrow\f$ `bool` describing a strict
|
||||||
|
/// (non-reflexive) total ordering on `Matrix::Value`.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// \sa `CGAL::extremal_polygon_2`
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// Implementation
|
||||||
|
/// --------------
|
||||||
|
/// The implementation uses an algorithm by Aggarwal
|
||||||
|
/// et al.\cite akmsw-gamsa-87. The runtime is linear in the number
|
||||||
|
/// of rows and columns of the matrix.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
template < class Matrix, class RandomAccessIC,
|
||||||
|
class Compare_strictly > void monotone_matrix_search( const
|
||||||
|
Matrix& m, RandomAccessIC t, const Compare_strictly&
|
||||||
|
compare_strictly = less< Matrix::Value >());
|
||||||
|
} /* namespace CGAL */
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
///
|
||||||
|
namespace CGAL {
|
||||||
|
/// \ingroup PkgMatrixSearch
|
||||||
|
///
|
||||||
|
/// The function `sorted_matrix_search` selects the smallest entry
|
||||||
|
/// in a set of sorted matrices that fulfills a certain feasibility
|
||||||
|
/// criterion.
|
||||||
|
/// More exactly, a matrix \f$ M = (m_{i j}) \in S^{r \times l}\f$
|
||||||
|
/// (over a totally ordered set \f$ S\f$) is sorted, iff
|
||||||
|
/// \f{eqnarray*}{
|
||||||
|
/// \forall \, 1 \le i \le r,\; 1 \le j < l\; :\; m_{i j} \le m_{i (j+1)}
|
||||||
|
/// \;\; {\it and}\\
|
||||||
|
/// \forall \, 1 \le i < r,\; 1 \le j \le l\; :\; m_{i j} \le m_{(i+1) j}
|
||||||
|
/// \;\;.
|
||||||
|
/// \f}
|
||||||
|
/// Now let \f$ \mathcal{M}\f$ be a set of \f$ n\f$ sorted matrices over \f$ S\f$
|
||||||
|
/// and \f$ f\f$ be a monotone predicate on \f$ S\f$, i.e.
|
||||||
|
///
|
||||||
|
/// \f[
|
||||||
|
/// f\: :\: S \longrightarrow\, \textit{bool} \quad{\rm with}\quad f(r)
|
||||||
|
/// \;\Longrightarrow\; \forall\, t \in S\,,\: t > r \; :\; f(t)\;.
|
||||||
|
/// \f]
|
||||||
|
///
|
||||||
|
/// If we assume there is any feasible element in one of the matrices
|
||||||
|
/// in \f$ \mathcal{M}\f$, there certainly is a smallest such element. This is the one
|
||||||
|
/// we are searching for.
|
||||||
|
/// The feasibility test as well as some other parameters can (and
|
||||||
|
/// have to) be customized through a traits class.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// It returns the element `x` in one of the sorted matrices from the
|
||||||
|
/// range \f$ \left[ f,\, l \right)\f$, for which `t.is_feasible( x)`
|
||||||
|
/// is true and `t.compare( x, y)` is true for all other
|
||||||
|
/// `y` values from any matrix for which `t.is_feasible(
|
||||||
|
/// y)` is true.
|
||||||
|
/// \pre All matrices in \f$ \left[f,\, l\right)\f$ are sorted according to `Traits::compare_non_strictly`.
|
||||||
|
/// \pre There is at least one entry \f$ x\f$ in a matrix \f$ M \in \left[f,\, l\right)\f$ for which `Traits::is_feasible(x)` is true.
|
||||||
|
///
|
||||||
|
/// \require `Traits` is a model for `SortedMatrixSearchTraits`.
|
||||||
|
/// \require Value type of `RandomAccessIterator` is `Traits::Matrix`.
|
||||||
|
///
|
||||||
|
/// \sa `SortedMatrixSearchTraits`
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// Implementation
|
||||||
|
/// --------------
|
||||||
|
/// The implementation uses an algorithm by
|
||||||
|
/// Frederickson and Johnson\cite fj-fkppc-83 \cite fj-gsrsm-84 and runs in
|
||||||
|
/// \f$ \mathcal{O}(n \cdot k + f \cdot \log (n \cdot k))\f$, where \f$ n\f$ is
|
||||||
|
/// the number of input matrices, \f$ k\f$ denotes the maximal dimension of
|
||||||
|
/// any input matrix and \f$ f\f$ the time needed for one feasibility test.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// Example
|
||||||
|
/// --------------
|
||||||
|
/// In the following program we build a random vector \f$ a =
|
||||||
|
/// (a_i)_{i = 1,\,\ldots,\,5}\f$ (elements drawn uniformly from \f$ \{
|
||||||
|
/// 0,\,\ldots,\,99 \}\f$) and construct a Cartesian matrix \f$ M\f$
|
||||||
|
/// containing as elements all sums \f$ a_i + a_j,\: i,\,j \in
|
||||||
|
/// \{1,\,\ldots,\,5\}\f$. If \f$ a\f$ is sorted, \f$ M\f$ is sorted as well. So
|
||||||
|
/// we can apply `sorted_matrix_search` to compute the upper bound
|
||||||
|
/// for the maximal entry of \f$ a\f$ in \f$ M\f$.
|
||||||
|
/// \cgalexample{Matrix_search/sorted_matrix_search.cpp}
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
template < class RandomAccessIterator, class
|
||||||
|
Traits > Traits::Value sorted_matrix_search(
|
||||||
|
RandomAccessIterator f, RandomAccessIterator l, const Traits&
|
||||||
|
t);
|
||||||
|
} /* namespace CGAL */
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
/// \ingroup PkgMatrixSearchConcepts
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// A class `BasicMatrix` has to provide the following
|
||||||
|
/// types and operations in order to be a model for
|
||||||
|
/// `BasicMatrix`.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// \hasModel CGAL::Dynamic_matrix<M>
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// \sa `SortedMatrixSearchTraits`
|
||||||
|
///
|
||||||
|
class BasicMatrix {
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \name Types
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced The type of a matrix entry. It has to define
|
||||||
|
a copy constructor.
|
||||||
|
*/
|
||||||
|
typedef Hidden_type Value;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns the number of columns.
|
||||||
|
*/
|
||||||
|
int number_of_columns() const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns the number of rows.
|
||||||
|
*/
|
||||||
|
int number_of_rows() const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns the entry at position (`row`, `column`).
|
||||||
|
|
||||||
|
\pre \f$ 0 \le\f$ `row` \f$ <\f$ `number_of_rows()`
|
||||||
|
\pre \f$ 0 \le\f$ `column` \f$ <\f$ `number_of_columns()`
|
||||||
|
*/
|
||||||
|
Entry operator()( int row, int column) const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
}; /* concept BasicMatrix */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
/// \ingroup PkgMatrixSearchConcepts
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// The concept `MonotoneMatrixSearchTraits` is a refinement of
|
||||||
|
/// `BasicMatrix` and defines types and operations needed to
|
||||||
|
/// compute the maxima for all rows of a totally monotone matrix using
|
||||||
|
/// the function `monotone_matrix_search`.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// Notes
|
||||||
|
/// --------------
|
||||||
|
///
|
||||||
|
/// <UL>
|
||||||
|
/// <LI>For the sake of efficiency (and in order to achieve the time
|
||||||
|
/// bounds claimed for `monotone_matrix_search`), all these
|
||||||
|
/// operations have to be realized in constant time - except for
|
||||||
|
/// `extract_all_even_rows` which may take linear time.
|
||||||
|
/// <LI>There is an adaptor `Dynamic_matrix` that can be used to
|
||||||
|
/// add most of the functionality described above to arbitrary
|
||||||
|
/// matrix classes.
|
||||||
|
/// </UL>
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// \hasModel CGAL::Dynamic_matrix<M>
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// \sa `CGAL::monotone_matrix_search`
|
||||||
|
///
|
||||||
|
class MonotoneMatrixSearchTraits {
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \name Types
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced The type of a matrix entry.
|
||||||
|
*/
|
||||||
|
typedef Hidden_type Value;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns the number of columns.
|
||||||
|
*/
|
||||||
|
int number_of_columns() const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns the number of rows.
|
||||||
|
*/
|
||||||
|
int number_of_rows() const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns the entry at position (`row`, `column`).
|
||||||
|
|
||||||
|
\pre \f$ 0 \le\f$ `row` \f$ <\f$ `number_of_rows()`
|
||||||
|
\pre \f$ 0 \le\f$ `column` \f$ <\f$ `number_of_columns()`
|
||||||
|
*/
|
||||||
|
Entry operator()( int row, int column) const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced replace column `old` with column number `new`.
|
||||||
|
|
||||||
|
\pre \f$ 0 \le\f$ `old`, `new` \f$ <\f$ `number_of_columns()`
|
||||||
|
*/
|
||||||
|
void replace_column( int old, int new);
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns a new Matrix consisting of all rows of `m` with even index, (i.e. first row is row \f$ 0\f$ of `m`, second row is row \f$ 2\f$ of `m` etc.). \pre `number_of_rows()` \f$ > 0\f$.
|
||||||
|
*/
|
||||||
|
Matrix* extract_all_even_rows() const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced deletes the rightmost columns, such that `m` becomes quadratic.
|
||||||
|
|
||||||
|
\pre `number_of_columns()` \f$ \ge\f$ `number_of_rows()`
|
||||||
|
\post `number_of_rows()` \f$ ==\f$ `number_of_columns()`
|
||||||
|
*/
|
||||||
|
void shrink_to_quadratic_size();
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
}; /* concept MonotoneMatrixSearchTraits */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,97 @@
|
||||||
|
/// \ingroup PkgMatrixSearchConcepts
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// The concept `SortedMatrixSearchTraits` defines types and operations
|
||||||
|
/// needed to compute the smallest entry in a set of sorted matrices
|
||||||
|
/// that fulfills a certain feasibility criterion using the function
|
||||||
|
/// `sorted_matrix_search`.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// \hasModel CGAL::Sorted_matrix_search_traits_adaptor<F,M>
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// \sa `BasicMatrix`
|
||||||
|
///
|
||||||
|
class SortedMatrixSearchTraits {
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \name Types
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced The class used for representing matrices.
|
||||||
|
It has to be a model for `BasicMatrix`.
|
||||||
|
*/
|
||||||
|
typedef Hidden_type Matrix;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Types
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced The class used for representing the matrix elements.
|
||||||
|
*/
|
||||||
|
typedef Matrix::Value Value;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Types
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced An adaptable binary function
|
||||||
|
class: `Value` \f$ \times\f$ `Value` \f$ \rightarrow\f$ `bool`
|
||||||
|
defining a non-reflexive total order on `Value`. This
|
||||||
|
determines the direction of the search.
|
||||||
|
*/
|
||||||
|
typedef Hidden_type Compare_strictly;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Types
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced An adaptable binary function
|
||||||
|
class: `Value` \f$ \times\f$ `Value` \f$ \rightarrow\f$ `bool`
|
||||||
|
defining the reflexive total order on `Value` corresponding
|
||||||
|
to `Compare_strictly`.
|
||||||
|
*/
|
||||||
|
typedef Hidden_type Compare_non_strictly;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns the `Compare_strictly` object to be used for the search.
|
||||||
|
*/
|
||||||
|
Compare_strictly compare_strictly()
|
||||||
|
const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced returns the `Compare_non_strictly` object to be used for the search.
|
||||||
|
*/
|
||||||
|
Compare_non_strictly compare_non_strictly()
|
||||||
|
const;
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
/// \name Operations
|
||||||
|
/// @{
|
||||||
|
/*!
|
||||||
|
\advanced The predicate to determine whether an element `a` is feasible. It has to be monotone in the sense that `compare( a, b)` and `is_feasible( a)` imply `is_feasible( b)`.
|
||||||
|
*/
|
||||||
|
bool is_feasible( const Value& a);
|
||||||
|
/// @}
|
||||||
|
|
||||||
|
}; /* concept SortedMatrixSearchTraits */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
namespace CGAL {
|
||||||
|
/*!
|
||||||
|
\page chap:MatrixSearch Monotone and Sorted Matrix Search
|
||||||
|
\authors Michael Hoffmann
|
||||||
|
\par Reference Manual:
|
||||||
|
\ref PkgMatrixSearch
|
||||||
|
|
||||||
|
`CGAL::monotone_matrix_search` and `CGAL::sorted_matrix_search`
|
||||||
|
are techniques that deal with the problem of efficiently finding
|
||||||
|
largest entries in matrices with certain structural properties. Many
|
||||||
|
concrete problems can be modelled as matrix search problems, and for
|
||||||
|
some of them we provide explicit solutions that allow you to solve
|
||||||
|
them without knowing about the matrix search technique. Examples are,
|
||||||
|
the computation of all furthest neighbors for the vertices of a convex
|
||||||
|
polygon, maximal \f$ k\f$-gons inscribed into a planar point set, and
|
||||||
|
computing rectangular \f$ p\f$-centers.
|
||||||
|
|
||||||
|
*/
|
||||||
|
} // namespace CGAL
|
||||||
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
/// \defgroup PkgMatrixSearch Monotone and Sorted Matrix Search
|
||||||
|
|
||||||
|
/// \defgroup PkgMatrixSearchConcepts Concepts
|
||||||
|
/// \ingroup PkgMatrixSearch
|
||||||
|
/*!
|
||||||
|
\addtogroup PkgMatrixSearch
|
||||||
|
<table cellpadding="2" cellspacing="0">
|
||||||
|
<tr>
|
||||||
|
<td colspan="2"><h1>Monotone and Sorted Matrix Search </h1></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td rowspan="2">\image html matrix.png "" </td>
|
||||||
|
<td>
|
||||||
|
\par Michael Hoffmann
|
||||||
|
|
||||||
|
\par "" This package provides a matrix search framework, which is the underlying technique for the computation of all furthest neighbors for the vertices of a convex polygon, maximal k-gons inscribed into a planar point set, and computing rectangular p-centers.
|
||||||
|
|
||||||
|
\since \cgal 1.1
|
||||||
|
|
||||||
|
\cgalbib{cgal:h-msms-12}
|
||||||
|
|
||||||
|
\license{ \ref licensesGPL "GPL" }
|
||||||
|
|
||||||
|
\par Resources:
|
||||||
|
\ref chap:MatrixSearch "User Manual"
|
||||||
|
</td>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
# Assertions #
|
||||||
|
|
||||||
|
The optimization code uses infix `OPTIMISATION` in the assertions,
|
||||||
|
e.g. defining the compiler flag
|
||||||
|
`CGAL_OPTIMISATION_NO_PRECONDITIONS` switches precondition
|
||||||
|
checking off, cf. Section \ref secchecks .
|
||||||
|
|
||||||
|
# Classified References Pages #
|
||||||
|
|
||||||
|
- `CGAL::monotone_matrix_search`
|
||||||
|
- `CGAL::Dynamic_matrix<M>`
|
||||||
|
- `MonotoneMatrixSearchTraits`
|
||||||
|
- `BasicMatrix`
|
||||||
|
|
||||||
|
- `CGAL::sorted_matrix_search`
|
||||||
|
- `CGAL::Sorted_matrix_search_traits_adaptor<F,M>`
|
||||||
|
- `SortedMatrixSearchTraits`
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
|
|
@ -10,8 +10,8 @@ namespace CGAL {
|
||||||
/// However, already existing objects do not lose their value with respect to the
|
/// However, already existing objects do not lose their value with respect to the
|
||||||
/// old prime and can be reused after restoring the old prime.
|
/// old prime and can be reused after restoring the old prime.
|
||||||
/// Since the type is based on double
|
/// Since the type is based on double
|
||||||
/// arithmetic the prime is restricted to values less than \f$2^26\f$.
|
/// arithmetic the prime is restricted to values less than \f$2^{26}\f$.
|
||||||
/// The initial value of \f$p\f$ is 67111067.
|
/// The initial value of \f$p\f$ is \f$67111067\f$.
|
||||||
///
|
///
|
||||||
/// Please note that the implementation of class `CGAL::Residue` requires a mantissa
|
/// Please note that the implementation of class `CGAL::Residue` requires a mantissa
|
||||||
/// precision according to the IEEE Standard for Floating-Point Arithmetic (IEEE 754).
|
/// precision according to the IEEE Standard for Floating-Point Arithmetic (IEEE 754).
|
||||||
|
|
@ -52,7 +52,7 @@ Residue(const Residue& m);
|
||||||
/// \name Creation
|
/// \name Creation
|
||||||
/// @{
|
/// @{
|
||||||
/*!
|
/*!
|
||||||
introduces a variable `x`, which is initialized with \f$i % p\f$;
|
introduces a variable `x`, which is initialized with \f$i \mod p\f$;
|
||||||
*/
|
*/
|
||||||
Residue(int i);
|
Residue(int i);
|
||||||
/// @}
|
/// @}
|
||||||
|
|
@ -60,7 +60,7 @@ Residue(int i);
|
||||||
/// \name Creation
|
/// \name Creation
|
||||||
/// @{
|
/// @{
|
||||||
/*!
|
/*!
|
||||||
introduces a variable `x`, which is initialized with \f$i % p\f$;
|
introduces a variable `x`, which is initialized with \f$i \mod p\f$;
|
||||||
*/
|
*/
|
||||||
Residue(long i);
|
Residue(long i);
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue