PPL  1.2
Linear_Expression_Impl_defs.hh
Go to the documentation of this file.
1 /* Linear_Expression_Impl class declaration.
2  Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3  Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_Linear_Expression_Impl_defs_hh
25 #define PPL_Linear_Expression_Impl_defs_hh 1
26 
29 #include "Coefficient_defs.hh"
30 #include "Variable_defs.hh"
31 #include "Variables_Set_defs.hh"
32 #include "Dense_Row_defs.hh"
33 #include "Sparse_Row_defs.hh"
34 #include <cstddef>
35 
36 namespace Parma_Polyhedra_Library {
37 
38 namespace IO_Operators {
39 
40 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
41 
43 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
44 template <typename Row>
45 std::ostream&
46 operator<<(std::ostream& s, const Linear_Expression_Impl<Row>& e);
47 
48 } // namespace IO_Operators
49 
50 } // namespace Parma_Polyhedra_Library
51 
52 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
53 
101 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
102 template <typename Row>
104  : public Linear_Expression_Interface {
105 public:
108 
111 
113  template <typename Row2>
115 
118 
120  virtual ~Linear_Expression_Impl();
121 
123  virtual bool OK() const;
124 
129  explicit Linear_Expression_Impl(Coefficient_traits::const_reference n);
130 
132 
138 
140  virtual Representation representation() const;
141 
144 
147  class const_iterator: public const_iterator_interface {
148  public:
149  explicit const_iterator(const Row& row, dimension_type i);
150 
154  virtual const_iterator_interface* clone() const;
155 
159  virtual void operator++();
160 
164  virtual void operator--();
165 
167  virtual reference operator*() const;
168 
170 
173  virtual Variable variable() const;
174 
176 
180  virtual bool operator==(const const_iterator_interface& x) const;
181 
182  private:
183 
184  void skip_zeroes_forward();
185  void skip_zeroes_backward();
186 
187  const Row* row;
188  typename Row::const_iterator itr;
189  };
190 
193  virtual const_iterator_interface* begin() const;
194 
197  virtual const_iterator_interface* end() const;
198 
205 
208 
210  virtual dimension_type space_dimension() const;
211 
213  virtual void set_space_dimension(dimension_type n);
214 
216  virtual Coefficient_traits::const_reference coefficient(Variable v) const;
217 
219  virtual void set_coefficient(Variable v,
220  Coefficient_traits::const_reference n);
221 
223  virtual Coefficient_traits::const_reference inhomogeneous_term() const;
224 
226  virtual void set_inhomogeneous_term(Coefficient_traits::const_reference n);
227 
230 
243  virtual void linear_combine(const Linear_Expression_Interface& y, Variable v);
244 
247  virtual void linear_combine(const Linear_Expression_Interface& y,
248  Coefficient_traits::const_reference c1,
249  Coefficient_traits::const_reference c2);
250 
253  virtual void linear_combine_lax(const Linear_Expression_Interface& y,
254  Coefficient_traits::const_reference c1,
255  Coefficient_traits::const_reference c2);
256 
258  virtual void swap_space_dimensions(Variable v1, Variable v2);
259 
261 
266  virtual void remove_space_dimensions(const Variables_Set& vars);
267 
271 
273 
284  virtual void permute_space_dimensions(const std::vector<Variable>& cycle);
285 
287  virtual bool is_zero() const;
288 
293  virtual bool all_homogeneous_terms_are_zero() const;
294 
299  virtual memory_size_type total_memory_in_bytes() const;
300 
303 
305  virtual void ascii_dump(std::ostream& s) const;
306 
312  virtual bool ascii_load(std::istream& s);
313 
316  dimension_type space_dim);
317 
320  virtual bool is_equal_to(const Linear_Expression_Interface& x) const;
321 
324 
328  virtual void normalize();
329 
332  virtual void sign_normalize();
333 
338  virtual void negate(dimension_type first, dimension_type last);
339 
340  virtual Linear_Expression_Impl&
341  operator+=(Coefficient_traits::const_reference n);
342  virtual Linear_Expression_Impl&
343  operator-=(Coefficient_traits::const_reference n);
344 
346 
357  virtual int compare(const Linear_Expression_Interface& y) const;
358 
359  virtual Linear_Expression_Impl&
361  virtual Linear_Expression_Impl& operator+=(const Variable v);
362  virtual Linear_Expression_Impl&
364  virtual Linear_Expression_Impl& operator-=(const Variable v);
365  virtual Linear_Expression_Impl&
366  operator*=(Coefficient_traits::const_reference n);
367  virtual Linear_Expression_Impl&
368  operator/=(Coefficient_traits::const_reference n);
369 
370  virtual void negate();
371 
372  virtual Linear_Expression_Impl&
373  add_mul_assign(Coefficient_traits::const_reference n, const Variable v);
374 
375  virtual Linear_Expression_Impl&
376  sub_mul_assign(Coefficient_traits::const_reference n, const Variable v);
377 
378  virtual void add_mul_assign(Coefficient_traits::const_reference factor,
379  const Linear_Expression_Interface& e2);
380 
381  virtual void sub_mul_assign(Coefficient_traits::const_reference factor,
382  const Linear_Expression_Interface& e2);
383 
384  virtual void print(std::ostream& s) const;
385 
390  virtual bool all_zeroes(const Variables_Set& vars) const;
391 
395  Variable first, Variable last) const;
396 
397  // NOTE: This method is public, but it's not exposed in Linear_Expression,
398  // so that it can be used internally in the PPL, by friends of
399  // Linear_Expression.
401  virtual Coefficient_traits::const_reference get(dimension_type i) const;
402 
403  // NOTE: This method is public, but it's not exposed in Linear_Expression,
404  // so that it can be used internally in the PPL, by friends of
405  // Linear_Expression.
407  virtual void set(dimension_type i, Coefficient_traits::const_reference n);
408 
409  // NOTE: This method is public, but it's not exposed in Linear_Expression,
410  // so that it can be used internally in the PPL, by friends of
411  // Linear_Expression.
416  virtual bool all_zeroes(dimension_type start, dimension_type end) const;
417 
418  // NOTE: This method is public, but it's not exposed in Linear_Expression,
419  // so that it can be used internally in the PPL, by friends of
420  // Linear_Expression.
425 
426  // NOTE: This method is public, but it's not exposed in Linear_Expression,
427  // so that it can be used internally in the PPL, by friends of
428  // Linear_Expression.
433  virtual Coefficient gcd(dimension_type start, dimension_type end) const;
434 
435  // NOTE: This method is public, but it's not exposed in Linear_Expression,
436  // so that it can be used internally in the PPL, by friends of
437  // Linear_Expression.
438  virtual void exact_div_assign(Coefficient_traits::const_reference c,
440 
441  // NOTE: This method is public, but it's not exposed in Linear_Expression,
442  // so that it can be used internally in the PPL, by friends of
443  // Linear_Expression.
445  virtual void mul_assign(Coefficient_traits::const_reference n,
447 
448  // NOTE: This method is public, but it's not exposed in Linear_Expression,
449  // so that it can be used internally in the PPL, by friends of
450  // Linear_Expression.
453 
466  virtual void
468 
469  // NOTE: This method is public, but it's not exposed in Linear_Expression,
470  // so that it can be used internally in the PPL, by friends of
471  // Linear_Expression.
474  virtual void linear_combine(const Linear_Expression_Interface& y,
475  Coefficient_traits::const_reference c1,
476  Coefficient_traits::const_reference c2,
478 
479  // NOTE: This method is public, but it's not exposed in Linear_Expression,
480  // so that it can be used internally in the PPL, by friends of
481  // Linear_Expression.
484  virtual void linear_combine_lax(const Linear_Expression_Interface& y,
485  Coefficient_traits::const_reference c1,
486  Coefficient_traits::const_reference c2,
488 
489  // NOTE: This method is public, but it's not exposed in Linear_Expression,
490  // so that it can be used internally in the PPL, by friends of
491  // Linear_Expression.
494  virtual dimension_type last_nonzero() const;
495 
496  // NOTE: This method is public, but it's not exposed in Linear_Expression,
497  // so that it can be used internally in the PPL, by friends of
498  // Linear_Expression.
503  virtual bool
504  all_zeroes_except(const Variables_Set& vars,
505  dimension_type start, dimension_type end) const;
506 
507  // NOTE: This method is public, but it's not exposed in Linear_Expression,
508  // so that it can be used internally in the PPL, by friends of
509  // Linear_Expression.
511  virtual void
514  dimension_type start, dimension_type end) const;
515 
516  // NOTE: This method is public, but it's not exposed in Linear_Expression,
517  // so that it can be used internally in the PPL, by friends of
518  // Linear_Expression.
520  virtual int
522  dimension_type start, dimension_type end) const;
523 
524  // NOTE: This method is public, but it's not exposed in Linear_Expression,
525  // so that it can be used internally in the PPL, by friends of
526  // Linear_Expression.
529  virtual dimension_type
530  first_nonzero(dimension_type first, dimension_type last) const;
531 
532  // NOTE: This method is public, but it's not exposed in Linear_Expression,
533  // so that it can be used internally in the PPL, by friends of
534  // Linear_Expression.
537  virtual dimension_type
538  last_nonzero(dimension_type first, dimension_type last) const;
539 
540  // NOTE: This method is public, but it's not exposed in Linear_Expression,
541  // so that it can be used internally in the PPL, by friends of
542  // Linear_Expression.
544  virtual void has_a_free_dimension_helper(std::set<dimension_type>& x) const;
545 
546  // NOTE: This method is public, but it's not exposed in Linear_Expression,
547  // so that it can be used internally in the PPL, by friends of
548  // Linear_Expression.
550  virtual bool is_equal_to(const Linear_Expression_Interface& x,
551  dimension_type start, dimension_type end) const;
552 
553  // NOTE: This method is public, but it's not exposed in Linear_Expression,
554  // so that it can be used internally in the PPL, by friends of
555  // Linear_Expression.
558  virtual bool is_equal_to(const Linear_Expression_Interface& x,
559  Coefficient_traits::const_reference c1,
560  Coefficient_traits::const_reference c2,
561  dimension_type start, dimension_type end) const;
562 
563  // NOTE: This method is public, but it is not exposed in
564  // Linear_Expression, so that it can be used internally in the PPL,
565  // by friends of Linear_Expression.
567  virtual void get_row(Dense_Row& r) const;
568 
569  // NOTE: This method is public, but it is not exposed in
570  // Linear_Expression, so that it can be used internally in the PPL,
571  // by friends of Linear_Expression.
573  virtual void get_row(Sparse_Row& r) const;
574 
576 
580  Linear_Expression_Impl(dimension_type space_dim, bool);
581 
584 
597  template <typename Row2>
599 
602  template <typename Row2>
604  Coefficient_traits::const_reference c1,
605  Coefficient_traits::const_reference c2);
606 
609  template <typename Row2>
611  Coefficient_traits::const_reference c1,
612  Coefficient_traits::const_reference c2);
613 
616  template <typename Row2>
617  bool is_equal_to(const Linear_Expression_Impl<Row2>& x) const;
618 
619  template <typename Row2>
621  template <typename Row2>
623 
624  template <typename Row2>
626  sub_mul_assign(Coefficient_traits::const_reference n,
629 
630  template <typename Row2>
631  void add_mul_assign(Coefficient_traits::const_reference factor,
632  const Linear_Expression_Impl<Row2>& e2);
633 
634  template <typename Row2>
635  void sub_mul_assign(Coefficient_traits::const_reference factor,
636  const Linear_Expression_Impl<Row2>& e2);
637 
640 
653  template <typename Row2>
655 
658  template <typename Row2>
660  Coefficient_traits::const_reference c1,
661  Coefficient_traits::const_reference c2,
663 
666  template <typename Row2>
668  Coefficient_traits::const_reference c1,
669  Coefficient_traits::const_reference c2,
671 
673 
684  template <typename Row2>
685  int compare(const Linear_Expression_Impl<Row2>& y) const;
686 
688  template <typename Row2>
689  void
692  dimension_type start, dimension_type end) const;
693 
696  template <typename Row2>
698  dimension_type start, dimension_type end) const;
699 
701  template <typename Row2>
703  dimension_type start, dimension_type end) const;
704 
707  template <typename Row2>
709  Coefficient_traits::const_reference c1,
710  Coefficient_traits::const_reference c2,
711  dimension_type start, dimension_type end) const;
712 
715  template <typename Row2>
717  Variable first, Variable last) const;
718 
719 private:
720 
721  void construct(const Linear_Expression_Interface& e);
723  dimension_type space_dim);
724 
725  template <typename Row2>
727  template <typename Row2>
729  dimension_type space_dim);
730 
731  Row row;
732 
733  template <typename Row2>
735 
736 }; // class Parma_Polyhedra_Library::Linear_Expression_Impl
737 
738 
739 namespace Parma_Polyhedra_Library {
740 
741 // NOTE: declaring explicit specializations.
742 
743 template <>
744 bool
746 template <>
747 bool
749 
750 template <>
751 bool
753 template <>
754 bool
756 
757 template <>
758 bool
760  dimension_type end) const;
761 template <>
762 bool
764  dimension_type end) const;
765 
766 template <>
767 bool
769 ::all_zeroes(const Variables_Set& vars) const;
770 template <>
771 bool
773 ::all_zeroes(const Variables_Set& vars) const;
774 
775 template <>
776 bool
779  dimension_type start, dimension_type end) const;
780 template <>
781 bool
784  dimension_type start, dimension_type end) const;
785 
786 template <>
790 template <>
794 
795 template <>
798  dimension_type end) const;
799 template <>
802  dimension_type end) const;
803 
804 template <>
805 void
807 ::has_a_free_dimension_helper(std::set<dimension_type>& x) const;
808 template <>
809 void
811 ::has_a_free_dimension_helper(std::set<dimension_type>& x) const;
812 
813 template <>
814 template <>
815 bool
818  Variable first, Variable last) const;
819 template <>
820 template <>
821 bool
824  Variable first, Variable last) const;
825 template <>
826 template <>
827 bool
830  Variable first, Variable last) const;
831 template <>
832 template <>
833 bool
836  Variable first, Variable last) const;
837 
838 template <>
839 bool
841 template <>
842 bool
844 
845 template <>
848 template <>
851 
852 template <>
855 ::last_nonzero(dimension_type first, dimension_type last) const;
856 template <>
859 ::last_nonzero(dimension_type first, dimension_type last) const;
860 
861 template <>
864  dimension_type end) const;
865 template <>
868  dimension_type end) const;
869 
870 template <>
871 void
874 template <>
875 void
878 
879 template <>
882 template <>
885 
886 template <>
887 void
889 template <>
890 void
892 
893 template <>
894 void
896 template <>
897 void
899 
900 } // namespace Parma_Polyhedra_Library
901 
902 
905 
906 #endif // !defined(PPL_Linear_Expression_Impl_defs_hh)
virtual Linear_Expression_Impl & operator+=(Coefficient_traits::const_reference n)
virtual void has_a_free_dimension_helper(std::set< dimension_type > &x) const
Removes from the set x all the indexes of nonzero elements of *this.
virtual dimension_type first_nonzero(dimension_type first, dimension_type last) const
A finite sequence of coefficients.
virtual void linear_combine(const Linear_Expression_Interface &y, Variable v)
size_t dimension_type
An unsigned integral type for representing space dimensions.
An std::set of variables' indexes.
virtual Coefficient_traits::const_reference inhomogeneous_term() const
Returns the inhomogeneous term of *this.
virtual void set_inhomogeneous_term(Coefficient_traits::const_reference n)
Sets the inhomogeneous term of *this to n.
virtual void swap_space_dimensions(Variable v1, Variable v2)
Swaps the coefficients of the variables v1 and v2 .
virtual bool have_a_common_variable(const Linear_Expression_Interface &x, Variable first, Variable last) const
virtual bool OK() const
Checks if all the invariants are satisfied.
A finite sparse sequence of coefficients.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Linear_Expression_Impl can handle.
virtual void remove_space_dimensions(const Variables_Set &vars)
Removes all the specified dimensions from the expression.
virtual void set_coefficient(Variable v, Coefficient_traits::const_reference n)
Sets the coefficient of v in *this to n.
virtual Linear_Expression_Impl & operator-=(Coefficient_traits::const_reference n)
virtual Variable variable() const
Returns the variable of the coefficient pointed to by *this.
virtual dimension_type num_zeroes(dimension_type start, dimension_type end) const
Returns the number of zero coefficient in [start, end).
virtual void exact_div_assign(Coefficient_traits::const_reference c, dimension_type start, dimension_type end)
A dimension of the vector space.
virtual memory_size_type total_memory_in_bytes() const
Returns a lower bound to the total size in bytes of the memory occupied by *this. ...
virtual int compare(const Linear_Expression_Interface &y) const
The basic comparison function.
virtual Linear_Expression_Impl & operator*=(Coefficient_traits::const_reference n)
virtual void get_row(Dense_Row &r) const
Sets r to a copy of the row that implements *this.
virtual Linear_Expression_Impl & add_mul_assign(Coefficient_traits::const_reference n, const Variable v)
virtual bool all_zeroes_except(const Variables_Set &vars, dimension_type start, dimension_type end) const
Returns true if each coefficient in [start,end) is *not* in , disregarding coefficients of variables ...
virtual memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
virtual bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
virtual bool is_zero() const
Returns true if and only if *this is .
virtual void set_space_dimension(dimension_type n)
Sets the dimension of the vector space enclosing *this to n .
virtual int scalar_product_sign(const Linear_Expression_Interface &y, dimension_type start, dimension_type end) const
Computes the sign of the sum of (*this)[i]*y[i], for each i in [start,end).
virtual bool is_equal_to(const Linear_Expression_Interface &x) const
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
virtual void set(dimension_type i, Coefficient_traits::const_reference n)
Sets the i-th coefficient to n.
Linear_Expression_Impl()
Default constructor: returns a copy of Linear_Expression_Impl::zero().
virtual void ascii_dump(std::ostream &s) const
Writes to s an ASCII representation of *this.
virtual void shift_space_dimensions(Variable v, dimension_type n)
The entire library is confined to this namespace.
Definition: version.hh:61
virtual Linear_Expression_Impl & operator/=(Coefficient_traits::const_reference n)
virtual dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
virtual Coefficient_traits::const_reference coefficient(Variable v) const
Returns the coefficient of v in *this.
virtual void mul_assign(Coefficient_traits::const_reference n, dimension_type start, dimension_type end)
Equivalent to (*this)[i] *= n, for each i in [start, end).
virtual bool operator==(const const_iterator_interface &x) const
Compares *this with x .
virtual Coefficient gcd(dimension_type start, dimension_type end) const
Returns the gcd of the nonzero coefficients in [start,end). If all the coefficients in this range are...
virtual Linear_Expression_Impl & sub_mul_assign(Coefficient_traits::const_reference n, const Variable v)
virtual void linear_combine_lax(const Linear_Expression_Interface &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2)
virtual void scalar_product_assign(Coefficient &result, const Linear_Expression_Interface &y, dimension_type start, dimension_type end) const
Sets results to the sum of (*this)[i]*y[i], for each i in [start,end).
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
Coefficient c
Definition: PIP_Tree.cc:64
virtual bool all_zeroes(const Variables_Set &vars) const
Returns true if the coefficient of each variable in vars[i] is .
virtual const_iterator_interface * lower_bound(Variable v) const
virtual bool all_homogeneous_terms_are_zero() const
Returns true if and only if all the homogeneous terms of *this are .
virtual void permute_space_dimensions(const std::vector< Variable > &cycle)
Permutes the space dimensions of the expression.
virtual Representation representation() const
Returns the current representation of this linear expression.
virtual reference operator*() const
Returns the current element.
virtual dimension_type last_nonzero() const