PPL  0.12.1
Linear_System.inlines.hh
Go to the documentation of this file.
00001 /* Linear_System class implementation: inline functions.
00002    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
00003    Copyright (C) 2010-2012 BUGSENG srl (http://bugseng.com)
00004 
00005 This file is part of the Parma Polyhedra Library (PPL).
00006 
00007 The PPL is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 The PPL is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this program; if not, write to the Free Software Foundation,
00019 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
00020 
00021 For the most up-to-date information see the Parma Polyhedra Library
00022 site: http://bugseng.com/products/ppl/ . */
00023 
00024 #ifndef PPL_Linear_System_inlines_hh
00025 #define PPL_Linear_System_inlines_hh 1
00026 
00027 #include "Bit_Row.defs.hh"
00028 
00029 namespace Parma_Polyhedra_Library {
00030 
00031 inline memory_size_type
00032 Linear_System::external_memory_in_bytes() const {
00033   return Dense_Matrix::external_memory_in_bytes();
00034 }
00035 
00036 inline memory_size_type
00037 Linear_System::total_memory_in_bytes() const {
00038   return sizeof(*this) + external_memory_in_bytes();
00039 }
00040 
00041 inline bool
00042 Linear_System::is_sorted() const {
00043   // The flag `sorted' does not really reflect the sortedness status
00044   // of a system (if `sorted' evaluates to `false' nothing is known).
00045   // This assertion is used to ensure that the system
00046   // is actually sorted when `sorted' value is 'true'.
00047   PPL_ASSERT(!sorted || check_sorted());
00048   return sorted;
00049 }
00050 
00051 inline void
00052 Linear_System::set_sorted(const bool b) {
00053   sorted = b;
00054 }
00055 
00056 inline
00057 Linear_System::Linear_System(Topology topol)
00058   : Dense_Matrix(),
00059     row_topology(topol),
00060     index_first_pending(0),
00061     sorted(true) {
00062 }
00063 
00064 inline
00065 Linear_System::Linear_System(Topology topol,
00066                              dimension_type n_rows, dimension_type n_columns)
00067   : Dense_Matrix(n_rows, n_columns, Linear_Row::Flags(topol)),
00068     row_topology(topol),
00069     index_first_pending(n_rows),
00070     sorted(true) {
00071 }
00072 
00073 inline dimension_type
00074 Linear_System::first_pending_row() const {
00075   return index_first_pending;
00076 }
00077 
00078 inline dimension_type
00079 Linear_System::num_pending_rows() const {
00080   PPL_ASSERT(num_rows() >= first_pending_row());
00081   return num_rows() - first_pending_row();
00082 }
00083 
00084 inline void
00085 Linear_System::unset_pending_rows() {
00086   index_first_pending = num_rows();
00087 }
00088 
00089 inline void
00090 Linear_System::set_index_first_pending_row(const dimension_type i) {
00091   index_first_pending = i;
00092 }
00093 
00094 inline
00095 Linear_System::Linear_System(const Linear_System& y)
00096   : Dense_Matrix(y),
00097     row_topology(y.row_topology) {
00098   unset_pending_rows();
00099   // Previously pending rows may violate sortedness.
00100   sorted = (y.num_pending_rows() > 0) ? false : y.sorted;
00101   PPL_ASSERT(num_pending_rows() == 0);
00102 }
00103 
00104 inline
00105 Linear_System::Linear_System(const Linear_System& y, With_Pending)
00106   : Dense_Matrix(y),
00107     row_topology(y.row_topology),
00108     index_first_pending(y.index_first_pending),
00109     sorted(y.sorted) {
00110 }
00111 
00112 inline Linear_System&
00113 Linear_System::operator=(const Linear_System& y) {
00114   Dense_Matrix::operator=(y);
00115   row_topology = y.row_topology;
00116   unset_pending_rows();
00117   // Previously pending rows may violate sortedness.
00118   sorted = (y.num_pending_rows() > 0) ? false : y.sorted;
00119   PPL_ASSERT(num_pending_rows() == 0);
00120   return *this;
00121 }
00122 
00123 inline void
00124 Linear_System::assign_with_pending(const Linear_System& y) {
00125   Dense_Matrix::operator=(y);
00126   row_topology = y.row_topology;
00127   index_first_pending = y.index_first_pending;
00128   sorted = y.sorted;
00129 }
00130 
00131 inline void
00132 Linear_System::m_swap(Linear_System& y) {
00133   Dense_Matrix::m_swap(y);
00134   using std::swap;
00135   swap(row_topology, y.row_topology);
00136   swap(index_first_pending, y.index_first_pending);
00137   swap(sorted, y.sorted);
00138 }
00139 
00140 inline void
00141 Linear_System::clear() {
00142   // Note: do NOT modify the value of `row_topology'.
00143   Dense_Matrix::clear();
00144   index_first_pending = 0;
00145   sorted = true;
00146 }
00147 
00148 inline void
00149 Linear_System::resize_no_copy(const dimension_type new_n_rows,
00150                               const dimension_type new_n_columns) {
00151   Dense_Matrix::resize_no_copy(new_n_rows, new_n_columns,
00152                          Linear_Row::Flags(row_topology));
00153   // Even though `*this' may happen to keep its sortedness, we believe
00154   // that checking such a property is not worth the effort.  In fact,
00155   // it is very likely that the system will be overwritten as soon as
00156   // we return.
00157   set_sorted(false);
00158 }
00159 
00160 inline void
00161 Linear_System::set_necessarily_closed() {
00162   row_topology = NECESSARILY_CLOSED;
00163   if (!has_no_rows())
00164     set_rows_topology();
00165 }
00166 
00167 inline void
00168 Linear_System::set_not_necessarily_closed() {
00169   row_topology = NOT_NECESSARILY_CLOSED;
00170   if (!has_no_rows())
00171     set_rows_topology();
00172 }
00173 
00174 inline bool
00175 Linear_System::is_necessarily_closed() const {
00176   return row_topology == NECESSARILY_CLOSED;
00177 }
00178 
00179 inline Linear_Row&
00180 Linear_System::operator[](const dimension_type k) {
00181   return static_cast<Linear_Row&>(Dense_Matrix::operator[](k));
00182 }
00183 
00184 inline const Linear_Row&
00185 Linear_System::operator[](const dimension_type k) const {
00186   return static_cast<const Linear_Row&>(Dense_Matrix::operator[](k));
00187 }
00188 
00189 inline Topology
00190 Linear_System::topology() const {
00191   return row_topology;
00192 }
00193 
00194 inline dimension_type
00195 Linear_System::max_space_dimension() {
00196   // Column zero holds the inhomogeneous term or the divisor.
00197   // In NNC linear systems, the last column holds the coefficient
00198   // of the epsilon dimension.
00199   return max_num_columns() - 2;
00200 }
00201 
00202 inline dimension_type
00203 Linear_System::space_dimension() const {
00204   const dimension_type n_columns = num_columns();
00205   return (n_columns == 0)
00206     ? 0
00207     : (n_columns - (is_necessarily_closed() ? 1U : 2U));
00208 }
00209 
00210 inline void
00211 Linear_System::remove_trailing_columns(const dimension_type n) {
00212   Dense_Matrix::remove_trailing_columns(n);
00213   // Have to re-normalize the rows of the system,
00214   // since we removed some coefficients.
00215   strong_normalize();
00216 }
00217 
00218 inline void
00219 Linear_System::permute_columns(const std::vector<dimension_type>& cycles) {
00220   Dense_Matrix::permute_columns(cycles);
00221   // The rows with permuted columns are still normalized but may
00222   // be not strongly normalized: sign normalization is necessary.
00223   sign_normalize();
00224 }
00225 
00227 inline bool
00228 operator!=(const Linear_System& x, const Linear_System& y) {
00229   return !(x == y);
00230 }
00231 
00232 inline bool
00233 Linear_System::Row_Less_Than::operator()(const Dense_Row& x,
00234                                          const Dense_Row& y) const {
00235   return compare(static_cast<const Linear_Row&>(x),
00236                  static_cast<const Linear_Row&>(y)) < 0;
00237 }
00238 
00240 inline void
00241 swap(Linear_System& x, Linear_System& y) {
00242   x.m_swap(y);
00243 }
00244 
00245 inline
00246 Linear_System::With_Bit_Matrix_iterator::
00247 With_Bit_Matrix_iterator(Iter1 iter1, Iter2 iter2)
00248   : i1(iter1), i2(iter2) {
00249 }
00250 
00251 inline
00252 Linear_System::With_Bit_Matrix_iterator::
00253 With_Bit_Matrix_iterator(const With_Bit_Matrix_iterator& y)
00254   : i1(y.i1), i2(y.i2) {
00255 }
00256 
00257 inline
00258 Linear_System::With_Bit_Matrix_iterator::
00259 ~With_Bit_Matrix_iterator() {
00260 }
00261 
00262 inline Linear_System::With_Bit_Matrix_iterator&
00263 Linear_System::With_Bit_Matrix_iterator::
00264 operator=(const With_Bit_Matrix_iterator& y) {
00265   i1 = y.i1;
00266   i2 = y.i2;
00267   return *this;
00268 }
00269 
00270 inline Linear_System::With_Bit_Matrix_iterator&
00271 Linear_System::With_Bit_Matrix_iterator::operator++() {
00272   ++i1;
00273   ++i2;
00274   return *this;
00275 }
00276 
00277 inline Linear_System::With_Bit_Matrix_iterator
00278 Linear_System::With_Bit_Matrix_iterator::operator++(int) {
00279   With_Bit_Matrix_iterator tmp = *this;
00280   operator++();
00281   return tmp;
00282 }
00283 
00284 inline Linear_System::With_Bit_Matrix_iterator&
00285 Linear_System::With_Bit_Matrix_iterator::operator--() {
00286   --i1;
00287   --i2;
00288   return *this;
00289 }
00290 
00291 inline Linear_System::With_Bit_Matrix_iterator
00292 Linear_System::With_Bit_Matrix_iterator::operator--(int) {
00293   With_Bit_Matrix_iterator tmp = *this;
00294   operator--();
00295   return tmp;
00296 }
00297 
00298 inline Linear_System::With_Bit_Matrix_iterator&
00299 Linear_System::With_Bit_Matrix_iterator::operator+=(difference_type d) {
00300   i1 += d;
00301   i2 += d;
00302   return *this;
00303 }
00304 
00305 inline Linear_System::With_Bit_Matrix_iterator
00306 Linear_System::With_Bit_Matrix_iterator::
00307 operator+(difference_type d) const {
00308   With_Bit_Matrix_iterator tmp = *this;
00309   tmp += d;
00310   return tmp;
00311 }
00312 
00313 inline Linear_System::With_Bit_Matrix_iterator&
00314 Linear_System::With_Bit_Matrix_iterator::operator-=(difference_type d) {
00315   i1 -= d;
00316   i2 -= d;
00317   return *this;
00318 }
00319 
00320 inline Linear_System::With_Bit_Matrix_iterator
00321 Linear_System::With_Bit_Matrix_iterator::
00322 operator-(difference_type d) const {
00323   With_Bit_Matrix_iterator tmp = *this;
00324   tmp -= d;
00325   return tmp;
00326 }
00327 
00328 inline Linear_System::With_Bit_Matrix_iterator::difference_type
00329 Linear_System::With_Bit_Matrix_iterator::
00330 operator-(const With_Bit_Matrix_iterator& y) const {
00331   return i1 - y.i1;
00332 }
00333 
00334 inline bool
00335 Linear_System::With_Bit_Matrix_iterator::
00336 operator==(const With_Bit_Matrix_iterator& y) const {
00337   return i1 == y.i1;
00338 }
00339 
00340 inline bool
00341 Linear_System::With_Bit_Matrix_iterator::
00342 operator!=(const With_Bit_Matrix_iterator& y) const {
00343   return i1 != y.i1;
00344 }
00345 
00346 inline bool
00347 Linear_System::With_Bit_Matrix_iterator::
00348 operator<(const With_Bit_Matrix_iterator& y) const {
00349   return i1 < y.i1;
00350 }
00351 
00352 inline Linear_System::With_Bit_Matrix_iterator::reference
00353 Linear_System::With_Bit_Matrix_iterator::operator*() const {
00354   return *i1;
00355 }
00356 
00357 inline Linear_System::With_Bit_Matrix_iterator::pointer
00358 Linear_System::With_Bit_Matrix_iterator::operator->() const {
00359   return &*i1;
00360 }
00361 
00362 inline void
00363 Linear_System::With_Bit_Matrix_iterator::
00364 m_iter_swap(const With_Bit_Matrix_iterator& y) const {
00365   using std::iter_swap;
00366   iter_swap(i1, y.i1);
00367   iter_swap(i2, y.i2);
00368 }
00369 
00370 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00371 
00372 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00373 inline void
00374 iter_swap(Linear_System::With_Bit_Matrix_iterator x,
00375           Linear_System::With_Bit_Matrix_iterator y) {
00376   x.m_iter_swap(y);
00377 }
00378 
00379 } // namespace Parma_Polyhedra_Library
00380 
00381 #endif // !defined(PPL_Linear_System_inlines_hh)