24 #ifndef PPL_Linear_System_inlines_hh
25 #define PPL_Linear_System_inlines_hh 1
34 template <
typename Row>
37 return rows.external_memory_in_bytes();
40 template <
typename Row>
46 template <
typename Row>
53 PPL_ASSERT(!sorted || check_sorted());
57 template <
typename Row>
64 template <
typename Row>
70 index_first_pending(0),
77 template <
typename Row>
85 index_first_pending(0),
92 template <
typename Row>
95 return index_first_pending;
98 template <
typename Row>
101 PPL_ASSERT(num_rows() >= first_pending_row());
102 return num_rows() - first_pending_row();
105 template <
typename Row>
108 index_first_pending = num_rows();
112 template <
typename Row>
115 index_first_pending = i;
119 template <
typename Row>
123 space_dimension_(y.space_dimension_),
124 row_topology(y.row_topology),
125 representation_(y.representation_) {
132 template <
typename Row>
136 space_dimension_(y.space_dimension_),
137 row_topology(y.row_topology),
142 Row row(y.
rows[i], r);
151 template <
typename Row>
155 space_dimension_(y.space_dimension_),
156 row_topology(y.row_topology),
157 index_first_pending(y.index_first_pending),
159 representation_(y.representation_) {
163 template <
typename Row>
168 space_dimension_(y.space_dimension_),
169 row_topology(y.row_topology),
170 index_first_pending(y.index_first_pending),
176 Row row(y.
rows[i], r);
182 template <
typename Row>
191 template <
typename Row>
198 template <
typename Row>
212 template <
typename Row>
217 index_first_pending = 0;
219 space_dimension_ = 0;
224 template <
typename Row>
231 rows[i].mark_as_necessarily_closed();
235 template <
typename Row>
239 PPL_ASSERT(space_dimension() > 0);
243 rows[i].mark_as_not_necessarily_closed();
247 template <
typename Row>
250 if (topology() == t) {
254 rows[i].set_topology(t);
260 template <
typename Row>
266 template <
typename Row>
272 template <
typename Row>
278 template <
typename Row>
284 template <
typename Row>
290 template <
typename Row>
296 template <
typename Row>
302 template <
typename Row>
308 template <
typename Row>
314 template <
typename Row>
320 template <
typename Row>
326 template <
typename Row>
329 return representation_;
332 template <
typename Row>
337 rows[i].set_representation(r);
342 template <
typename Row>
348 template <
typename Row>
351 return space_dimension_;
354 template <
typename Row>
358 rows[i].set_space_dimension_no_ok(space_dim);
360 space_dimension_ = space_dim;
363 template <
typename Row>
366 set_space_dimension_no_ok(space_dim);
370 template <
typename Row>
373 const bool keep_sorted) {
374 PPL_ASSERT(i < num_rows());
375 const bool was_pending = (i >= index_first_pending);
377 if (sorted && keep_sorted && !was_pending) {
379 swap(rows[j], rows[j-1]);
387 const bool last_row_is_pending = (num_rows() - 1 >= index_first_pending);
388 if (was_pending == last_row_is_pending) {
390 swap(rows[i], rows.back());
394 PPL_ASSERT(!was_pending);
395 PPL_ASSERT(last_row_is_pending);
398 swap(rows[i], rows[index_first_pending - 1]);
402 swap(rows[i], rows.back());
408 --index_first_pending;
412 template <
typename Row>
415 remove_row_no_ok(i, keep_sorted);
420 template <
typename Row>
425 PPL_ASSERT(first <= last);
426 PPL_ASSERT(last <= num_rows());
435 PPL_ASSERT(first >= index_first_pending || last <= index_first_pending);
437 const bool were_pending = (first >= index_first_pending);
440 if (sorted && keep_sorted && !were_pending) {
443 swap(rows[i], rows[i - n]);
446 rows.resize(rows.size() - n);
449 index_first_pending -= n;
463 if (index_first_pending == num_rows()) {
465 PPL_ASSERT(!were_pending);
467 swap_row_intervals(first, last, offset);
469 rows.resize(rows.size() - n);
472 index_first_pending -= n;
480 swap_row_intervals(first, last, offset);
482 rows.resize(rows.size() - n);
485 index_first_pending -= n;
488 PPL_ASSERT(rows.size() - n < index_first_pending);
489 PPL_ASSERT(rows.size() > index_first_pending);
490 PPL_ASSERT(!were_pending);
494 PPL_ASSERT(index_first_pending >= last);
495 swap_row_intervals(first, last, index_first_pending - last);
498 index_first_pending -= n;
499 first = index_first_pending;
503 swap_row_intervals(first, last, num_rows() - last);
506 rows.resize(rows.size() - n);
513 template <
typename Row>
518 PPL_ASSERT(first <= last);
519 PPL_ASSERT(last + offset <= num_rows());
522 bool first_interval_has_pending_rows = (last > index_first_pending);
523 bool second_interval_has_pending_rows = (last + offset > index_first_pending);
524 bool first_interval_has_not_pending_rows = (first < index_first_pending);
525 bool second_interval_has_not_pending_rows = (first + offset < index_first_pending);
526 PPL_ASSERT(first_interval_has_not_pending_rows
527 == !first_interval_has_pending_rows);
528 PPL_ASSERT(second_interval_has_not_pending_rows
529 == !second_interval_has_pending_rows);
530 PPL_ASSERT(first_interval_has_pending_rows
531 == second_interval_has_pending_rows);
534 if (first + offset < last) {
547 swap(rows[i], rows[i + offset]);
550 if (first < index_first_pending) {
558 template <
typename Row>
564 std::vector<dimension_type> sorted_indexes = indexes;
565 std::sort(sorted_indexes.begin(), sorted_indexes.end());
566 PPL_ASSERT(indexes == sorted_indexes);
570 if (!indexes.empty()) {
571 PPL_ASSERT(indexes.back() < num_rows());
576 if (indexes.empty()) {
581 typedef std::vector<dimension_type>::const_iterator itr_t;
588 itr_t itr = indexes.begin();
589 itr_t itr_end = indexes.end();
590 while (itr != itr_end) {
592 PPL_ASSERT(i < rows_size);
599 swap(rows[last_unused_row], rows[i]);
606 for ( ; i < rows_size; ++i) {
607 swap(rows[last_unused_row], rows[i]);
611 PPL_ASSERT(last_unused_row == num_rows() - indexes.size());
615 rows.resize(last_unused_row);
618 if (indexes[0] >= index_first_pending) {
622 if (indexes.back() < index_first_pending) {
624 index_first_pending -= indexes.size();
631 itr_t j = std::lower_bound(indexes.begin(), indexes.end(),
632 index_first_pending);
633 std::iterator_traits<itr_t>::difference_type
634 non_pending = j - indexes.begin();
645 template <
typename Row>
648 PPL_ASSERT(rows.size() >= n);
649 rows.resize(rows.size() - n);
650 if (first_pending_row() > rows.size()) {
651 index_first_pending = rows.size();
656 template <
typename Row>
661 rows[i].permute_space_dimensions(cycle);
667 template <
typename Row>
674 rows[k].swap_space_dimensions(v1, v2);
681 template <
typename Row>
687 template <
typename Row>
690 const Row& y)
const {
694 template <
typename Row>
699 : container(cont), base_index(base) {
702 template <
typename Row>
706 return container[base_index + i].is_equal_to(container[base_index + j]);
710 template <
typename Row>
718 #endif // !defined(PPL_Linear_System_inlines_hh)
void swap(Parma_Polyhedra_Library::Linear_System< Row > &x, Parma_Polyhedra_Library::Linear_System< Row > &y)
Swaps x with y.
dimension_type max_space_dimension()
Returns the maximum space dimension this library can handle.
void swap(CO_Tree &x, CO_Tree &y)
The base class for systems of constraints and generators.
Representation representation() const
Returns the current representation of *this.
size_t dimension_type
An unsigned integral type for representing space dimensions.
void set_index_first_pending_row(dimension_type i)
Sets the index of the first pending row to i.
void resize(dimension_type new_size)
void set_not_necessarily_closed()
Sets the system topology to NOT_NECESSARILY_CLOSED.
Topology topology() const
Returns the system topology.
memory_size_type total_memory_in_bytes() const
Returns the total size in bytes of the memory occupied by *this.
bool is_necessarily_closed() const
Returns true if and only if the system topology is NECESSARILY_CLOSED.
void mark_as_not_necessarily_closed()
Marks the last dimension as the epsilon dimension.
void set_space_dimension(dimension_type space_dim)
Sets the space dimension of the rows in the system to space_dim .
const Row & operator[](dimension_type k) const
Returns a const reference to the k-th row of the system.
dimension_type first_pending_row() const
Returns the index of the first pending row.
Linear_System & operator=(const Linear_System &y)
Assignment operator: pending rows are transformed into non-pending ones.
void clear()
Clears the system deallocating all its rows.
Swapping_Vector< Row > rows
The vector that contains the rows.
void permute_space_dimensions(const std::vector< Variable > &cycle)
Permutes the space dimensions of the matrix.
void remove_row(dimension_type i, bool keep_sorted=false)
Makes the system shrink by removing its i-th row.
void mark_as_necessarily_closed()
Marks the epsilon dimension as a standard dimension.
void set_necessarily_closed()
Sets the system topology to NECESSARILY_CLOSED.
A dimension of the vector space.
bool sorted
true if rows are sorted in the ascending order as defined by bool compare(const Row&, const Row&). If false may not be sorted.
void unset_pending_rows()
Sets the index to indicate that the system has no pending rows.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
Swapping_Vector< Row >::const_iterator iterator
void m_swap(Linear_System &y)
Swaps *this with y.
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
dimension_type num_rows() const
Enable_If< Is_Native< T >::value, memory_size_type >::type external_memory_in_bytes(const T &)
For native types, returns the size in bytes of the memory managed by the type of the (unused) paramet...
Representation representation_
void set_space_dimension_no_ok(dimension_type space_dim)
Sets the space dimension of the rows in the system to space_dim .
bool is_sorted() const
Returns the value of the sortedness flag.
Swapping_Vector< Row >::const_iterator const_iterator
int compare(const Linear_Expression &x, const Linear_Expression &y)
void remove_row_no_ok(dimension_type i, bool keep_sorted=false)
Makes the system shrink by removing its i-th row.
void remove_rows(dimension_type first, dimension_type last, bool keep_sorted=false)
Makes the system shrink by removing the rows in [first,last).
The entire library is confined to this namespace.
dimension_type space_dimension_
void assign_with_pending(const Linear_System &y)
Full assignment operator: pending rows are copied as pending.
void swap_space_dimensions(Variable v1, Variable v2)
Swaps the coefficients of the variables v1 and v2 .
void swap_row_intervals(dimension_type first, dimension_type last, dimension_type offset)
Linear_System(Topology topol, Representation r)
Builds an empty linear system with specified topology.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Linear_System can handle.
void remove_trailing_rows(dimension_type n)
Makes the system shrink by removing its n trailing rows.
void set_representation(Representation r)
Converts *this to the specified representation.
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
dimension_type space_dimension() const
Returns the space dimension of the rows in the system.
bool operator()(dimension_type i, dimension_type j) const
void set_sorted(bool b)
Sets the sortedness flag of the system to b.
void swap(Linear_System< Row > &x, Linear_System< Row > &y)
bool OK() const
Checks if all the invariants are satisfied.
bool operator!=(const Linear_System< Row > &x, const Linear_System< Row > &y)
void set_topology(Topology t)
Sets the system topology to t .
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
bool operator()(const Row &x, const Row &y) const
Unique_Compare(const Swapping_Vector< Row > &cont, dimension_type base=0)
Topology
Kinds of polyhedra domains.
dimension_type index_first_pending
The index of the first pending row.