PPL
1.2
|
A finite sparse sequence of coefficients. More...
#include <Sparse_Row_defs.hh>
Public Types | |
typedef CO_Tree::iterator | iterator |
An iterator on the row elements. More... | |
typedef CO_Tree::const_iterator | const_iterator |
A const iterator on the row elements. More... | |
Public Member Functions | |
Sparse_Row (dimension_type n=0) | |
Constructs a row with the specified size. More... | |
Sparse_Row (dimension_type n, dimension_type capacity) | |
Constructs a row with the specified size. More... | |
Sparse_Row (const Sparse_Row &y, dimension_type capacity) | |
Copy constructor with specified capacity. More... | |
Sparse_Row (const Sparse_Row &y, dimension_type sz, dimension_type capacity) | |
Copy constructor with specified size and capacity. More... | |
Sparse_Row (const Dense_Row &row) | |
Constructor from a Dense_Row. More... | |
Sparse_Row (const Dense_Row &y, dimension_type sz, dimension_type capacity) | |
Copy constructor from a Dense_Row with specified size and capacity. More... | |
Sparse_Row & | operator= (const Dense_Row &row) |
void | m_swap (Sparse_Row &x) |
Swaps *this and x. More... | |
dimension_type | size () const |
Returns the size of the row. More... | |
dimension_type | num_stored_elements () const |
Returns the number of elements explicitly stored in the row. More... | |
void | resize (dimension_type n) |
Resizes the row to the specified size. More... | |
void | expand_within_capacity (dimension_type n) |
Resizes the row to size n . More... | |
void | shrink (dimension_type n) |
Resizes the row to size n . More... | |
void | delete_element_and_shift (dimension_type i) |
Deletes the i-th element from the row, shifting the next elements to the left. More... | |
void | add_zeroes_and_shift (dimension_type n, dimension_type i) |
Adds n zeroes before index i . More... | |
iterator | begin () |
Returns an iterator that points at the first stored element. More... | |
const iterator & | end () |
Returns an iterator that points after the last stored element. More... | |
const_iterator | begin () const |
Equivalent to cbegin() . More... | |
const const_iterator & | end () const |
Equivalent to cend() . More... | |
const_iterator | cbegin () const |
Returns an iterator that points at the first element. More... | |
const const_iterator & | cend () const |
Returns an iterator that points after the last element. More... | |
void | clear () |
Resets all the elements of this row. More... | |
Coefficient & | operator[] (dimension_type i) |
Gets a reference to the i-th element. More... | |
Coefficient_traits::const_reference | operator[] (dimension_type i) const |
Equivalent to get(i) , provided for convenience. More... | |
Coefficient_traits::const_reference | get (dimension_type i) const |
Gets the i-th element in the sequence. More... | |
iterator | find (dimension_type i) |
Looks for an element with index i. More... | |
iterator | find (iterator itr, dimension_type i) |
Looks for an element with index i. More... | |
const_iterator | find (dimension_type i) const |
Looks for an element with index i. More... | |
const_iterator | find (const_iterator itr, dimension_type i) const |
Looks for an element with index i. More... | |
iterator | lower_bound (dimension_type i) |
Lower bound of index i. More... | |
iterator | lower_bound (iterator itr, dimension_type i) |
Lower bound of index i. More... | |
const_iterator | lower_bound (dimension_type i) const |
Lower bound of index i. More... | |
const_iterator | lower_bound (const_iterator itr, dimension_type i) const |
Lower bound of index i. More... | |
iterator | insert (dimension_type i, Coefficient_traits::const_reference x) |
Equivalent to (*this)[i] = x; find(i) , but faster. More... | |
iterator | insert (iterator itr, dimension_type i, Coefficient_traits::const_reference x) |
Equivalent to (*this)[i] = x; find(i) , but faster. More... | |
iterator | insert (dimension_type i) |
Equivalent to (*this)[i]; find(i) , but faster. More... | |
iterator | insert (iterator itr, dimension_type i) |
Equivalent to (*this)[i]; find(i) , but faster. More... | |
void | swap_coefficients (dimension_type i, dimension_type j) |
Swaps the i-th element with the j-th element. More... | |
void | fast_swap (dimension_type i, iterator itr) |
void | swap_coefficients (iterator i, iterator j) |
Swaps the element pointed to by i with the element pointed to by j. More... | |
iterator | reset (iterator i) |
Resets to zero the value pointed to by i. More... | |
iterator | reset (iterator first, iterator last) |
Resets to zero the values in the range [first,last). More... | |
void | reset (dimension_type i) |
Resets to zero the i-th element. More... | |
void | reset_after (dimension_type i) |
Resets to zero the elements with index greater than or equal to i. More... | |
void | normalize () |
Normalizes the modulo of coefficients so that they are mutually prime. More... | |
template<typename Func1 , typename Func2 > | |
void | combine_needs_first (const Sparse_Row &y, const Func1 &f, const Func2 &g) |
Calls g(x[i],y[i]), for each i. More... | |
template<typename Func1 , typename Func2 > | |
void | combine_needs_second (const Sparse_Row &y, const Func1 &g, const Func2 &h) |
Calls g(x[i],y[i]), for each i. More... | |
template<typename Func1 , typename Func2 , typename Func3 > | |
void | combine (const Sparse_Row &y, const Func1 &f, const Func2 &g, const Func3 &h) |
Calls g(x[i],y[i]), for each i. More... | |
void | linear_combine (const Sparse_Row &y, Coefficient_traits::const_reference coeff1, Coefficient_traits::const_reference coeff2) |
void | linear_combine (const Sparse_Row &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2, dimension_type start, dimension_type end) |
void | ascii_dump () const |
Writes to std::cerr an ASCII representation of *this . More... | |
void | ascii_dump (std::ostream &s) const |
Writes to s an ASCII representation of *this . More... | |
void | print () const |
Prints *this to std::cerr using operator<< . More... | |
bool | ascii_load (std::istream &s) |
Loads the row from an ASCII representation generated using ascii_dump(). More... | |
memory_size_type | external_memory_in_bytes () const |
Returns the size in bytes of the memory managed by *this . More... | |
memory_size_type | external_memory_in_bytes (dimension_type capacity) const |
Returns the size in bytes of the memory managed by *this . More... | |
memory_size_type | total_memory_in_bytes () const |
Returns the size in bytes of the memory managed by *this . More... | |
memory_size_type | total_memory_in_bytes (dimension_type capacity) const |
Returns the size in bytes of the memory managed by *this . More... | |
bool | OK () const |
Checks the invariant. More... | |
bool | OK (dimension_type capacity) const |
Checks the invariant. More... | |
Static Public Member Functions | |
static dimension_type | max_size () |
Returns the size() of the largest possible Sparse_Row. More... | |
Private Attributes | |
CO_Tree | tree |
The tree used to store the elements. More... | |
dimension_type | size_ |
The size of the row. More... | |
Related Functions | |
(Note that these are not member functions.) | |
bool | operator== (const Sparse_Row &x, const Sparse_Row &y) |
bool | operator!= (const Sparse_Row &x, const Sparse_Row &y) |
void | swap (Parma_Polyhedra_Library::Sparse_Row &x, Parma_Polyhedra_Library::Sparse_Row &y) |
Swaps x with y . More... | |
bool | operator== (const Sparse_Row &x, const Sparse_Row &y) |
Returns true if and only if x and y are equal. More... | |
bool | operator!= (const Sparse_Row &x, const Sparse_Row &y) |
Returns true if and only if x and y are different. More... | |
void | linear_combine (Sparse_Row &x, const Dense_Row &y, Coefficient_traits::const_reference coeff1, Coefficient_traits::const_reference coeff2) |
void | linear_combine (Sparse_Row &x, const Dense_Row &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2, dimension_type start, dimension_type end) |
void | linear_combine (Dense_Row &x, const Sparse_Row &y, Coefficient_traits::const_reference coeff1, Coefficient_traits::const_reference coeff2) |
void | linear_combine (Dense_Row &x, const Sparse_Row &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2, dimension_type start, dimension_type end) |
void | linear_combine (Sparse_Row &x, const Sparse_Row &y, Coefficient_traits::const_reference coeff1, Coefficient_traits::const_reference coeff2) |
void | linear_combine (Sparse_Row &x, const Sparse_Row &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2, dimension_type start, dimension_type end) |
void | swap (Sparse_Row &x, Sparse_Row &y) |
A finite sparse sequence of coefficients.
This class is implemented using a CO_Tree. See the documentation of CO_Tree for details on the implementation and the performance.
This class is a drop-in replacement of Dense_Row, meaning that code using Dense_Row can be ported to Sparse_Row changing only the type. The resulting code will work, but probably needs more CPU and memory (it does not exploit the sparse representation yet).
To take advantage of the sparse representation, the client code must then be modified to use methods which can have a faster implementation on sparse data structures.
The main changes are the replacement of calls to operator[] with calls to find(), lower_bound() or insert(), using hint iterators when possible. Sequential scanning of rows should probably be implemented using iterators rather than indexes, to improve performance. reset() should be called to zero elements.
Definition at line 58 of file Sparse_Row_defs.hh.
A const iterator on the row elements.
This iterator skips non-stored zeroes.
Definition at line 74 of file Sparse_Row_defs.hh.
An iterator on the row elements.
This iterator skips non-stored zeroes.
Definition at line 67 of file Sparse_Row_defs.hh.
|
inlineexplicit |
Constructs a row with the specified size.
n | The size for the new row. |
The row will contain only non-stored zeroes.
This constructor takes time.
Definition at line 32 of file Sparse_Row_inlines.hh.
References OK().
|
inline |
Constructs a row with the specified size.
n | The size for the new row. |
capacity | It is ignored. This parameter is needed for compatibility with Dense_Row. |
The row will contain only non-stored zeroes.
This constructor takes time.
Definition at line 38 of file Sparse_Row_inlines.hh.
References OK().
|
inline |
Copy constructor with specified capacity.
It is assumed that capacity
is greater than or equal to the size of y
.
Definition at line 44 of file Sparse_Row_inlines.hh.
|
inline |
Copy constructor with specified size and capacity.
It is assumed that sz
is less than or equal to capacity
.
Definition at line 49 of file Sparse_Row_inlines.hh.
References OK().
|
explicit |
Constructor from a Dense_Row.
row | The row that will be copied into *this. |
This constructor takes time. Note that constructing of a row of zeroes and then inserting n elements costs
time.
Definition at line 101 of file Sparse_Row.cc.
References OK().
Parma_Polyhedra_Library::Sparse_Row::Sparse_Row | ( | const Dense_Row & | y, |
dimension_type | sz, | ||
dimension_type | capacity | ||
) |
Copy constructor from a Dense_Row with specified size and capacity.
It is assumed that sz
is less than or equal to capacity
.
Definition at line 108 of file Sparse_Row.cc.
References OK().
|
inline |
Adds n
zeroes before index i
.
n | The number of non-stored zeroes that will be added to the row. |
i | The index of the element before which the zeroes will be added. |
Existing elements with index greater than or equal to i
are shifted to the right by n
positions. The size is increased by n
.
Existing iterators are not invalidated, but are shifted to the right by n
if they pointed at or after index i
(i.e., they point to the same, possibly shifted, values as before).
This method takes expected time, where
is the number of elements with index greater than or equal to
i
and the number of stored elements.
Definition at line 105 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::increase_keys_from(), OK(), size_, and tree.
void Parma_Polyhedra_Library::Sparse_Row::ascii_dump | ( | ) | const |
Writes to std::cerr
an ASCII representation of *this
.
void Parma_Polyhedra_Library::Sparse_Row::ascii_dump | ( | std::ostream & | s | ) | const |
Writes to s
an ASCII representation of *this
.
Definition at line 685 of file Sparse_Row.cc.
bool Parma_Polyhedra_Library::Sparse_Row::ascii_load | ( | std::istream & | s | ) |
Loads the row from an ASCII representation generated using ascii_dump().
s | The stream from which the ASCII representation will be loaded. |
Definition at line 701 of file Sparse_Row.cc.
References PPL_DIRTY_TEMP_COEFFICIENT.
|
inline |
Returns an iterator that points at the first stored element.
This method takes time.
Definition at line 113 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::begin(), and tree.
Referenced by Parma_Polyhedra_Library::PIP_Tree_Node::add_constraint(), combine(), combine_needs_first(), combine_needs_second(), Parma_Polyhedra_Library::PIP_Tree_Node::compatibility_check(), Parma_Polyhedra_Library::Dense_Row::Dense_Row(), Parma_Polyhedra_Library::MIP_Problem::erase_artificials(), Parma_Polyhedra_Library::PIP_Solution_Node::generate_cut(), Parma_Polyhedra_Library::Dense_Row::init(), Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::is_better_pivot(), linear_combine(), Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::normalize(), Parma_Polyhedra_Library::MIP_Problem::OK(), Parma_Polyhedra_Library::Dense_Row::operator=(), operator==(), Parma_Polyhedra_Library::MIP_Problem::process_pending_constraints(), Parma_Polyhedra_Library::PIP_Solution_Node::row_sign(), Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::scale(), Parma_Polyhedra_Library::MIP_Problem::second_phase(), Parma_Polyhedra_Library::PIP_Problem::solve(), Parma_Polyhedra_Library::PIP_Solution_Node::solve(), Parma_Polyhedra_Library::MIP_Problem::steepest_edge_exact_entering_index(), Parma_Polyhedra_Library::MIP_Problem::steepest_edge_float_entering_index(), Parma_Polyhedra_Library::swap(), and Parma_Polyhedra_Library::PIP_Solution_Node::update_solution().
|
inline |
Equivalent to cbegin()
.
Definition at line 123 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::cbegin(), and tree.
|
inline |
Returns an iterator that points at the first element.
This method takes time.
Definition at line 133 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::cbegin(), and tree.
|
inline |
Returns an iterator that points after the last element.
This method always returns a reference to the same internal iterator, that is updated at each operation that modifies the structure. Client code can keep a const reference to that iterator instead of keep updating a local iterator.
This method takes time.
Definition at line 138 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::cend(), and tree.
|
inline |
Resets all the elements of this row.
This method takes time.
Definition at line 148 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::clear(), and tree.
void Parma_Polyhedra_Library::Sparse_Row::combine | ( | const Sparse_Row & | y, |
const Func1 & | f, | ||
const Func2 & | g, | ||
const Func3 & | h | ||
) |
Calls g(x[i],y[i]), for each i.
y | The row that will be combined with *this. |
f | A functor that should take a Coefficient&. f(c1) must be equivalent to g(c1, 0). |
g | A functor that should take a Coefficient& and a Coefficient_traits::const_reference. g(c1, c2) must do nothing when both c1 and c2 are zero. |
h | A functor that should take a Coefficient& and a Coefficient_traits::const_reference. h(c1, c2) must be equivalent to g(c1, c2) when c1 is zero. |
This method takes time.
Definition at line 101 of file Sparse_Row_templates.hh.
References begin(), end(), Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), Parma_Polyhedra_Library::CO_Tree::iterator::index(), insert(), and reset().
void Parma_Polyhedra_Library::Sparse_Row::combine_needs_first | ( | const Sparse_Row & | y, |
const Func1 & | f, | ||
const Func2 & | g | ||
) |
Calls g(x[i],y[i]), for each i.
y | The row that will be combined with *this. |
f | A functor that should take a Coefficient&. f(c1) must be equivalent to g(c1, 0). |
g | A functor that should take a Coefficient& and a Coefficient_traits::const_reference. g(c1, c2) must do nothing when c1 is zero. |
This method takes time.
Definition at line 32 of file Sparse_Row_templates.hh.
References begin(), end(), Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), Parma_Polyhedra_Library::CO_Tree::iterator::index(), lower_bound(), and reset().
void Parma_Polyhedra_Library::Sparse_Row::combine_needs_second | ( | const Sparse_Row & | y, |
const Func1 & | g, | ||
const Func2 & | h | ||
) |
Calls g(x[i],y[i]), for each i.
y | The row that will be combined with *this. |
g | A functor that should take a Coefficient& and a Coefficient_traits::const_reference. g(c1, 0) must do nothing, for every c1. |
h | A functor that should take a Coefficient& and a Coefficient_traits::const_reference. h(c1, c2) must be equivalent to g(c1, c2) when c1 is zero. |
This method takes time.
Definition at line 86 of file Sparse_Row_templates.hh.
References begin(), end(), Parma_Polyhedra_Library::CO_Tree::iterator::index(), insert(), and reset().
|
inline |
Deletes the i-th element from the row, shifting the next elements to the left.
i | The index of the element that will be deleted. |
The size of the row is decreased by 1.
This operation invalidates existing iterators.
This method takes amortized time, where k is the number of elements with index greater than i.
Definition at line 97 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::erase_element_and_shift_left(), OK(), size_, and tree.
|
inline |
Returns an iterator that points after the last stored element.
This method always returns a reference to the same internal iterator, that is kept valid. Client code can keep a const reference to that iterator instead of keep updating a local iterator.
This method takes time.
Definition at line 118 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::end(), and tree.
Referenced by Parma_Polyhedra_Library::PIP_Tree_Node::add_constraint(), combine(), combine_needs_first(), combine_needs_second(), Parma_Polyhedra_Library::PIP_Tree_Node::compatibility_check(), Parma_Polyhedra_Library::MIP_Problem::erase_artificials(), fast_swap(), find(), Parma_Polyhedra_Library::PIP_Solution_Node::generate_cut(), get(), Parma_Polyhedra_Library::Dense_Row::init(), Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::is_better_pivot(), Parma_Polyhedra_Library::MIP_Problem::linear_combine(), linear_combine(), lower_bound(), Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::normalize(), Parma_Polyhedra_Library::MIP_Problem::OK(), Parma_Polyhedra_Library::Dense_Row::operator=(), operator==(), Parma_Polyhedra_Library::operator==(), Parma_Polyhedra_Library::MIP_Problem::process_pending_constraints(), Parma_Polyhedra_Library::PIP_Solution_Node::row_sign(), Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::scale(), Parma_Polyhedra_Library::MIP_Problem::second_phase(), Parma_Polyhedra_Library::PIP_Problem::solve(), Parma_Polyhedra_Library::PIP_Solution_Node::solve(), Parma_Polyhedra_Library::MIP_Problem::steepest_edge_exact_entering_index(), Parma_Polyhedra_Library::MIP_Problem::steepest_edge_float_entering_index(), Parma_Polyhedra_Library::swap(), swap_coefficients(), and Parma_Polyhedra_Library::PIP_Solution_Node::update_solution().
|
inline |
Equivalent to cend()
.
Definition at line 128 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::cend(), and tree.
|
inline |
Resizes the row to size n
.
n | The new size for the row. |
This method, with this signature, is needed for compatibility with Dense_Row.
This method takes time.
Definition at line 91 of file Sparse_Row_inlines.hh.
References resize(), and size().
|
inline |
Returns the size in bytes of the memory managed by *this
.
This method takes time.
Definition at line 362 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::external_memory_in_bytes(), and tree.
Referenced by Parma_Polyhedra_Library::MIP_Problem::external_memory_in_bytes(), external_memory_in_bytes(), and total_memory_in_bytes().
|
inline |
Returns the size in bytes of the memory managed by *this
.
This method is provided for compatibility with Dense_Row.
This method takes time.
capacity | This parameter is ignored. |
Definition at line 367 of file Sparse_Row_inlines.hh.
References external_memory_in_bytes().
|
inline |
Equivalent to swap(i,itr.index()), but it assumes that lower_bound(i)==itr.
Iterators that pointed to the itr.index()-th element remain valid but now point to the i-th element. Other iterators are unaffected.
This method takes time.
Definition at line 339 of file Sparse_Row_inlines.hh.
References end(), Parma_Polyhedra_Library::CO_Tree::fast_shift(), lower_bound(), OK(), and tree.
|
inline |
Looks for an element with index i.
i | The index of the desired element. |
If possible, use the find() method that takes a hint iterator, to improve performance.
This method takes time.
Definition at line 180 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::bisect(), end(), Parma_Polyhedra_Library::CO_Tree::iterator::index(), size(), and tree.
Referenced by get(), Parma_Polyhedra_Library::MIP_Problem::linear_combine(), and Parma_Polyhedra_Library::PIP_Solution_Node::solve().
|
inline |
Looks for an element with index i.
i | The index of the desired element. |
itr | It is used as a hint. This method will be faster if the searched element is near to itr . |
The value of itr
does not affect the result of this method, as long it is a valid iterator for this row. itr
may even be end().
This method takes time. If the distance between
itr
and the searched position is , this method takes
time.
Definition at line 192 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::bisect_near(), end(), Parma_Polyhedra_Library::CO_Tree::iterator::index(), size(), and tree.
|
inline |
Looks for an element with index i.
i | The index of the desired element. |
If possible, use the find() method that takes a hint iterator, to improve performance.
This method takes time.
Definition at line 204 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::bisect(), end(), Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), size(), and tree.
|
inline |
Looks for an element with index i.
i | The index of the desired element. |
itr | It is used as a hint. This method will be faster if the searched element is near to itr . |
The value of itr
does not affect the result of this method, as long it is a valid iterator for this row. itr
may even be end().
This method takes time. If the distance between
itr
and the searched position is , this method takes
time.
Definition at line 217 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::bisect_near(), end(), Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), size(), and tree.
|
inline |
Gets the i-th element in the sequence.
i | The index of the desired element. |
If possible, use the insert(), find() or lower_bound() methods with a hint instead of this, to improve performance.
This method takes time.
Definition at line 165 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::Coefficient_zero(), Parma_Polyhedra_Library::CO_Tree::empty(), end(), find(), size_, and tree.
Referenced by Parma_Polyhedra_Library::PIP_Tree_Node::add_constraint(), Parma_Polyhedra_Library::PIP_Tree_Node::compatibility_check(), Parma_Polyhedra_Library::MIP_Problem::compute_generator(), Parma_Polyhedra_Library::PIP_Solution_Node::generate_cut(), Parma_Polyhedra_Library::MIP_Problem::get_exiting_base_index(), Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::is_better_pivot(), Parma_Polyhedra_Library::MIP_Problem::linear_combine(), Parma_Polyhedra_Library::MIP_Problem::pivot(), Parma_Polyhedra_Library::MIP_Problem::process_pending_constraints(), Parma_Polyhedra_Library::PIP_Solution_Node::row_sign(), Parma_Polyhedra_Library::PIP_Solution_Node::solve(), Parma_Polyhedra_Library::MIP_Problem::steepest_edge_float_entering_index(), and Parma_Polyhedra_Library::PIP_Solution_Node::update_solution().
|
inline |
Equivalent to (*this)[i] = x; find(i)
, but faster.
i | The index of the desired element. |
x | The value that will be associated to the element. |
If possible, use versions of this method that take a hint, to improve performance.
This operation invalidates existing iterators.
This method takes amortized time.
Definition at line 305 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::insert(), size_, and tree.
Referenced by combine(), combine_needs_second(), Parma_Polyhedra_Library::PIP_Solution_Node::generate_cut(), operator[](), Parma_Polyhedra_Library::MIP_Problem::process_pending_constraints(), Parma_Polyhedra_Library::PIP_Problem::solve(), Parma_Polyhedra_Library::PIP_Solution_Node::solve(), and Parma_Polyhedra_Library::PIP_Solution_Node::update_tableau().
|
inline |
Equivalent to (*this)[i] = x; find(i)
, but faster.
i | The index of the desired element. |
x | The value that will be associated to the element. |
itr | It is used as a hint. This method will be faster if the searched element is near to itr , even faster than (*this)[i] = x . |
The value of itr
does not affect the result of this method, as long it is a valid iterator for this row. itr
may even be end().
This operation invalidates existing iterators.
This method takes amortized time. If the distance between
itr
and the searched position is and the row already contains an element with this index, this method takes
time.
Definition at line 311 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::insert(), size_, and tree.
|
inline |
Equivalent to (*this)[i]; find(i)
, but faster.
i | The index of the desired element. |
If possible, use versions of this method that take a hint, to improve performance.
This operation invalidates existing iterators.
This method takes amortized time.
Definition at line 318 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::insert(), size_, and tree.
|
inline |
Equivalent to (*this)[i]; find(i)
, but faster.
i | The index of the desired element. |
itr | It is used as a hint. This method will be faster if the searched element is near to itr , even faster than (*this)[i] . |
The value of itr
does not affect the result of this method, as long it is a valid iterator for this row. itr
may even be end().
This operation invalidates existing iterators.
This method takes amortized time. If the distance between
itr
and the searched position is and the row already contains an element with this index, this method takes
time.
Definition at line 324 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::insert(), size_, and tree.
void Parma_Polyhedra_Library::Sparse_Row::linear_combine | ( | const Sparse_Row & | y, |
Coefficient_traits::const_reference | coeff1, | ||
Coefficient_traits::const_reference | coeff2 | ||
) |
Executes (*this)[i] = (*this)[i]*coeff1 + y[i]*coeff2
, for each i.
y | The row that will be combined with *this. |
coeff1 | The coefficient used for elements of *this. This must not be 0. |
coeff2 | The coefficient used for elements of y. This must not be 0. |
This method takes time.
Definition at line 370 of file Sparse_Row.cc.
References Parma_Polyhedra_Library::add_mul_assign(), begin(), end(), Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), Parma_Polyhedra_Library::CO_Tree::iterator::index(), and Parma_Polyhedra_Library::CO_Tree::m_swap().
Referenced by Parma_Polyhedra_Library::MIP_Problem::linear_combine().
void Parma_Polyhedra_Library::Sparse_Row::linear_combine | ( | const Sparse_Row & | y, |
Coefficient_traits::const_reference | c1, | ||
Coefficient_traits::const_reference | c2, | ||
dimension_type | start, | ||
dimension_type | end | ||
) |
Equivalent to (*this)[i] = (*this)[i] * c1 + y[i] * c2
, for each i in [start, end).
This method, unlike the other linear_combine() method, detects when coeff1==1 and/or coeff2==1 or coeff2==-1 in order to save some work.
Definition at line 503 of file Sparse_Row.cc.
References Parma_Polyhedra_Library::add_mul_assign(), Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), Parma_Polyhedra_Library::CO_Tree::iterator::index(), lower_bound(), and Parma_Polyhedra_Library::neg_assign().
|
inline |
Lower bound of index i.
i | The index of the desired element. |
If possible, use the find() method that takes a hint iterator, to improve performance.
This method takes time.
Definition at line 229 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::bisect(), end(), Parma_Polyhedra_Library::CO_Tree::iterator::index(), size(), and tree.
Referenced by combine_needs_first(), Parma_Polyhedra_Library::Dense_Row::Dense_Row(), fast_swap(), Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::have_a_common_variable(), linear_combine(), Parma_Polyhedra_Library::MIP_Problem::OK(), Parma_Polyhedra_Library::operator==(), Parma_Polyhedra_Library::MIP_Problem::second_phase(), Parma_Polyhedra_Library::MIP_Problem::steepest_edge_exact_entering_index(), and Parma_Polyhedra_Library::MIP_Problem::steepest_edge_float_entering_index().
|
inline |
Lower bound of index i.
i | The index of the desired element. |
itr | It is used as a hint. This method will be faster if the searched element is near to itr . |
The value of itr
does not affect the result of this method, as long it is a valid iterator for this row. itr
may even be end().
This method takes time. If the distance between
itr
and the searched position is , this method takes
time.
Definition at line 248 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::bisect_near(), end(), Parma_Polyhedra_Library::CO_Tree::iterator::index(), size(), and tree.
|
inline |
Lower bound of index i.
i | The index of the desired element. |
If possible, use the find() method that takes a hint iterator, to improve performance.
This method takes time.
Definition at line 267 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::bisect(), end(), Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), size(), and tree.
|
inline |
Lower bound of index i.
i | The index of the desired element. |
itr | It is used as a hint. This method will be faster if the searched element is near to itr . |
The value of itr
does not affect the result of this method, as long it is a valid iterator for this row. itr
may even be end().
This method takes time. If the distance between
itr
and the searched position is , this method takes
time.
Definition at line 286 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::bisect_near(), end(), Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), size(), and tree.
|
inline |
Swaps *this and x.
x | The row that will be swapped with *this. |
This method takes time.
Definition at line 57 of file Sparse_Row_inlines.hh.
References OK(), size_, swap(), Parma_Polyhedra_Library::swap(), and tree.
Referenced by Parma_Polyhedra_Library::MIP_Problem::erase_artificials(), Parma_Polyhedra_Library::PIP_Solution_Node::solve(), and swap().
|
inlinestatic |
Returns the size() of the largest possible Sparse_Row.
Definition at line 143 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::max_size().
void Parma_Polyhedra_Library::Sparse_Row::normalize | ( | ) |
Normalizes the modulo of coefficients so that they are mutually prime.
Computes the Greatest Common Divisor (GCD) among the elements of the row and normalizes them by the GCD itself.
This method takes time.
Definition at line 210 of file Sparse_Row.cc.
References Parma_Polyhedra_Library::exact_div_assign(), Parma_Polyhedra_Library::gcd_assign(), Parma_Polyhedra_Library::neg_assign(), PPL_DIRTY_TEMP_COEFFICIENT, and Parma_Polyhedra_Library::Boundary_NS::sgn().
Referenced by Parma_Polyhedra_Library::MIP_Problem::linear_combine().
|
inline |
Returns the number of elements explicitly stored in the row.
This is equivalent to std::distance(begin(), end()), but it's much faster.
This method takes time.
Definition at line 71 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::size(), and tree.
bool Parma_Polyhedra_Library::Sparse_Row::OK | ( | ) | const |
Checks the invariant.
Definition at line 742 of file Sparse_Row.cc.
References Parma_Polyhedra_Library::CO_Tree::const_iterator::index().
Referenced by add_zeroes_and_shift(), delete_element_and_shift(), fast_swap(), m_swap(), reset(), resize(), Sparse_Row(), and swap_coefficients().
bool Parma_Polyhedra_Library::Sparse_Row::OK | ( | dimension_type | capacity | ) | const |
Checks the invariant.
This method is provided for compatibility with Dense_Row.
capacity | This parameter is ignored. |
Definition at line 752 of file Sparse_Row.cc.
PPL::Sparse_Row & Parma_Polyhedra_Library::Sparse_Row::operator= | ( | const Dense_Row & | row | ) |
Definition at line 118 of file Sparse_Row.cc.
References Parma_Polyhedra_Library::swap().
|
inline |
Gets a reference to the i-th element.
i | The index of the desired element. |
For read-only access it's better to use get(), that avoids allocating space for zeroes.
If possible, use the insert(), find() or lower_bound() methods with a hint instead of this, to improve performance.
This operation invalidates existing iterators.
This method takes amortized time when there is already an element with index
i
, and otherwise.
Definition at line 153 of file Sparse_Row_inlines.hh.
References insert(), and size_.
|
inline |
Equivalent to get(i)
, provided for convenience.
This method takes time.
Definition at line 160 of file Sparse_Row_inlines.hh.
void Parma_Polyhedra_Library::Sparse_Row::print | ( | ) | const |
Prints *this
to std::cerr
using operator<<
.
|
inline |
Resets to zero the value pointed to by i.
i | An iterator pointing to the element that will be reset (not stored anymore). |
By calling this method instead of getting a reference to the value and setting it to zero, the element will no longer be stored.
This operation invalidates existing iterators.
This method takes amortized time.
Definition at line 347 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::erase(), OK(), and tree.
Referenced by combine(), combine_needs_first(), combine_needs_second(), and Parma_Polyhedra_Library::Expression_Hide_Inhomo< T >::get_row().
PPL::Sparse_Row::iterator Parma_Polyhedra_Library::Sparse_Row::reset | ( | iterator | first, |
iterator | last | ||
) |
Resets to zero the values in the range [first,last).
first | An iterator pointing to the first element to reset. |
last | An iterator pointing after the last element to reset. |
By calling this method instead of getting a reference to the values and setting them to zero, the elements will no longer be stored.
This operation invalidates existing iterators.
This method takes amortized time, where k is the number of elements in [first,last).
Definition at line 171 of file Sparse_Row.cc.
References Parma_Polyhedra_Library::CO_Tree::iterator::index().
|
inline |
Resets to zero the i-th element.
i | The index of the element to reset. |
By calling this method instead of getting a reference to the value and setting it to zero, the element will no longer be stored.
This operation invalidates existing iterators.
This method takes amortized time.
Definition at line 354 of file Sparse_Row_inlines.hh.
References Parma_Polyhedra_Library::CO_Tree::erase(), OK(), size(), and tree.
void Parma_Polyhedra_Library::Sparse_Row::reset_after | ( | dimension_type | i | ) |
Resets to zero the elements with index greater than or equal to i.
i | The index of the first element to reset. |
By calling this method instead of getting a reference to the values and setting them to zero, the elements will no longer be stored.
This operation invalidates existing iterators.
This method takes amortized time, where k is the number of elements with index greater than or equal to i.
Definition at line 193 of file Sparse_Row.cc.
Referenced by resize().
|
inline |
Resizes the row to the specified size.
n | The new size for the row. |
This method takes amortized time when shrinking the row and removing the trailing k elements. It takes
time when enlarging the row.
Definition at line 76 of file Sparse_Row_inlines.hh.
References OK(), reset_after(), and size_.
Referenced by expand_within_capacity(), Parma_Polyhedra_Library::Expression_Hide_Last< T >::get_row(), and shrink().
|
inline |
Resizes the row to size n
.
n | The new size for the row. |
This method, with this signature, is needed for compatibility with Dense_Row.
This method takes amortized time where k is the number of removed elements.
Definition at line 85 of file Sparse_Row_inlines.hh.
References resize(), and size().
|
inline |
Returns the size of the row.
This method takes time.
Definition at line 66 of file Sparse_Row_inlines.hh.
References size_.
Referenced by Parma_Polyhedra_Library::Dense_Row::Dense_Row(), expand_within_capacity(), find(), Parma_Polyhedra_Library::Expression_Hide_Last< T >::get_row(), Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::have_a_common_variable(), Parma_Polyhedra_Library::Dense_Row::init(), Parma_Polyhedra_Library::MIP_Problem::linear_combine(), lower_bound(), Parma_Polyhedra_Library::Dense_Row::operator=(), operator==(), Parma_Polyhedra_Library::operator==(), reset(), shrink(), and Parma_Polyhedra_Library::swap().
void Parma_Polyhedra_Library::Sparse_Row::swap_coefficients | ( | dimension_type | i, |
dimension_type | j | ||
) |
Swaps the i-th element with the j-th element.
i | The index of an element. |
j | The index of another element. |
This operation invalidates existing iterators.
This method takes amortized time.
Definition at line 127 of file Sparse_Row.cc.
References Parma_Polyhedra_Library::CO_Tree::iterator::index(), PPL_DIRTY_TEMP_COEFFICIENT, and Parma_Polyhedra_Library::swap().
Swaps the element pointed to by i with the element pointed to by j.
i | An iterator pointing to an element. |
j | An iterator pointing to another element. |
This method takes time.
Definition at line 330 of file Sparse_Row_inlines.hh.
References end(), OK(), swap(), and Parma_Polyhedra_Library::swap().
|
inline |
Returns the size in bytes of the memory managed by *this
.
This method takes time.
Definition at line 372 of file Sparse_Row_inlines.hh.
References external_memory_in_bytes().
Referenced by total_memory_in_bytes().
|
inline |
Returns the size in bytes of the memory managed by *this
.
This method is provided for compatibility with Dense_Row.
This method takes time.
capacity | This parameter is ignored. |
Definition at line 377 of file Sparse_Row_inlines.hh.
References total_memory_in_bytes().
|
related |
Equivalent to x[i] = x[i] * c1 + y[i] * c2
, for each i in [start, end).
|
related |
Equivalent to x[i] = x[i] * c1 + y[i] * c2
, for each i in [start, end).
This function detects when coeff1==1 and/or coeff2==1 or coeff2==-1 in order to save some work.
|
related |
Equivalent to x[i] = x[i] * c1 + y[i] * c2
, for each i in [start, end).
|
related |
Equivalent to x[i] = x[i] * c1 + y[i] * c2
, for each i in [start, end).
This function detects when coeff1==1 and/or coeff2==1 or coeff2==-1 in order to save some work.
|
related |
Equivalent to x[i] = x[i] * c1 + y[i] * c2
, for each i in [start, end).
|
related |
Equivalent to x[i] = x[i] * c1 + y[i] * c2
, for each i in [start, end).
This function detects when coeff1==1 and/or coeff2==1 or coeff2==-1 in order to save some work.
|
related |
Definition at line 805 of file Sparse_Row.cc.
|
related |
Returns true
if and only if x
and y
are different.
|
related |
Definition at line 758 of file Sparse_Row.cc.
References begin(), end(), Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), and size().
|
related |
Returns true
if and only if x
and y
are equal.
|
related |
Definition at line 385 of file Sparse_Row_inlines.hh.
References m_swap().
|
related |
Swaps x
with y
.
Referenced by m_swap(), and swap_coefficients().
|
private |
The size of the row.
The elements contained in this row have indexes that are less than size_.
Definition at line 822 of file Sparse_Row_defs.hh.
Referenced by add_zeroes_and_shift(), delete_element_and_shift(), get(), insert(), m_swap(), operator[](), resize(), and size().
|
private |
The tree used to store the elements.
Definition at line 816 of file Sparse_Row_defs.hh.
Referenced by add_zeroes_and_shift(), begin(), cbegin(), cend(), clear(), delete_element_and_shift(), end(), external_memory_in_bytes(), fast_swap(), find(), get(), insert(), lower_bound(), m_swap(), num_stored_elements(), and reset().