PPL  1.2
Generator_defs.hh
Go to the documentation of this file.
1 /* Generator 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_Generator_defs_hh
25 #define PPL_Generator_defs_hh 1
26 
27 #include "Generator_types.hh"
28 #include "Scalar_Products_types.hh"
29 #include "Variables_Set_types.hh"
33 #include "Polyhedron_types.hh"
34 #include "Grid_Generator_types.hh"
36 #include "MIP_Problem_types.hh"
37 #include "Grid_types.hh"
38 
39 #include "Variable_defs.hh"
41 #include "Checked_Number_defs.hh"
42 #include "distances_defs.hh"
43 #include "Topology_types.hh"
46 
47 #include <iosfwd>
48 
49 namespace Parma_Polyhedra_Library {
50 
51 // Put them in the namespace here to declare them friend later.
52 
53 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
54 
89 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
90 int compare(const Generator& x, const Generator& y);
91 
92 namespace IO_Operators {
93 
95 
96 std::ostream& operator<<(std::ostream& s, const Generator& g);
97 
98 } // namespace IO_Operators
99 
101 
102 void swap(Generator& x, Generator& y);
103 
104 } // namespace Parma_Polyhedra_Library
105 
106 
108 
286 public:
287 
289 
295 
297 
302  static Generator line(const Linear_Expression& e,
303  Representation r = default_representation);
304 
306 
311  static Generator ray(const Linear_Expression& e,
312  Representation r = default_representation);
313 
315 
322  static Generator point(const Linear_Expression& e
324  Coefficient_traits::const_reference d
325  = Coefficient_one(),
326  Representation r = default_representation);
327 
329  static Generator point(Representation r);
330 
332  static Generator point(const Linear_Expression& e,
333  Representation r);
334 
336  explicit Generator(Representation r = default_representation);
337 
339 
346  static Generator
348  Coefficient_traits::const_reference d = Coefficient_one(),
349  Representation r = default_representation);
350 
352  static Generator
354 
356  static Generator
358 
361  Generator(const Generator& g);
362 
364  Generator(const Generator& g, Representation r);
365 
368  Generator(const Generator& g, dimension_type space_dim);
369 
371  Generator(const Generator& g, dimension_type space_dim, Representation r);
372 
374  ~Generator();
375 
377  Generator& operator=(const Generator& g);
378 
381 
384 
387 
390 
393  void set_space_dimension(dimension_type space_dim);
394 
397 
399 
408  bool remove_space_dimensions(const Variables_Set& vars);
409 
411 
422  void permute_space_dimensions(const std::vector<Variable>& cycle);
423 
427 
429  enum Type {
438  };
439 
441  Type type() const;
442 
444  bool is_line() const;
445 
447  bool is_ray() const;
448 
449 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
450 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
452  bool is_line_or_ray() const;
453 
455  bool is_point() const;
456 
458  bool is_closure_point() const;
459 
461 
466  Coefficient_traits::const_reference coefficient(Variable v) const;
467 
469 
473  Coefficient_traits::const_reference divisor() const;
474 
476  static void initialize();
477 
479  static void finalize();
480 
482  static const Generator& zero_dim_point();
483 
488  static const Generator& zero_dim_closure_point();
489 
495 
498 
505  bool is_equivalent_to(const Generator& y) const;
506 
508 
512  bool is_equal_to(const Generator& y) const;
513 
515  bool OK() const;
516 
518 
524  bool ascii_load(std::istream& s);
525 
527  void m_swap(Generator& y);
528 
533  expr_type expression() const;
534 
535 private:
537  enum Kind {
540  };
541 
544 
547 
550 
556 
562 
571 
573 
574  Generator(dimension_type space_dim, Kind kind, Topology topology,
575  Representation r = default_representation);
576 
581  bool is_line_or_equality() const;
582 
587  bool is_ray_or_point_or_inequality() const;
588 
591 
594 
596 
597  Topology topology() const;
599 
604  bool is_not_necessarily_closed() const;
605 
610  bool is_necessarily_closed() const;
612 
614 
615 
617  void set_topology(Topology x);
618 
620  void set_necessarily_closed();
621 
625 
627 
632 
634 
639 
641 
652  void linear_combine(const Generator& y, dimension_type i);
653 
657 
662 
667  void
668  throw_dimension_incompatible(const char* method,
669  const char* v_name,
670  Variable v) const;
671 
676  void
677  throw_invalid_argument(const char* method, const char* reason) const;
678 
680  bool is_ray_or_point() const;
681 
683  void set_is_line();
684 
686  void set_is_ray_or_point();
687 
695  bool is_matching_closure_point(const Generator& p) const;
696 
698  Coefficient_traits::const_reference epsilon_coefficient() const;
699 
701  void set_epsilon_coefficient(Coefficient_traits::const_reference n);
702 
707  void sign_normalize();
708 
715  void strong_normalize();
716 
721  bool check_strong_normalized() const;
722 
728  void fancy_print(std::ostream& s) const;
729 
731  friend class Linear_System<Generator>;
737  // FIXME: the following friend declaration should be avoided.
739  // This is for access to Linear_Expression in `insert'.
743 
744  friend std::ostream&
746  const Generator& g);
747 
748  friend int
749  compare(const Generator& x, const Generator& y);
750 };
751 
752 
753 namespace Parma_Polyhedra_Library {
754 
756 
757 Generator line(const Linear_Expression& e,
759 
761 
762 Generator ray(const Linear_Expression& e,
764 
771 Generator
772 point(const Linear_Expression& e = Linear_Expression::zero(),
773  Coefficient_traits::const_reference d = Coefficient_one(),
775 
777 
778 Generator
779 point(Representation r);
780 
787 Generator
788 point(const Linear_Expression& e, Representation r);
789 
796 Generator
797 closure_point(const Linear_Expression& e = Linear_Expression::zero(),
798  Coefficient_traits::const_reference d = Coefficient_one(),
800 
802 
803 Generator
804 closure_point(Representation r);
805 
812 Generator
813 closure_point(const Linear_Expression& e, Representation r);
814 
816 
817 bool operator==(const Generator& x, const Generator& y);
818 
820 
821 bool operator!=(const Generator& x, const Generator& y);
822 
824 
838 template <typename To>
839 bool rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
840  const Generator& x,
841  const Generator& y,
842  Rounding_Dir dir);
843 
845 
859 template <typename Temp, typename To>
860 bool rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
861  const Generator& x,
862  const Generator& y,
863  Rounding_Dir dir);
864 
866 
880 template <typename Temp, typename To>
881 bool rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
882  const Generator& x,
883  const Generator& y,
884  Rounding_Dir dir,
885  Temp& tmp0,
886  Temp& tmp1,
887  Temp& tmp2);
888 
890 
904 template <typename To>
905 bool euclidean_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
906  const Generator& x,
907  const Generator& y,
908  Rounding_Dir dir);
909 
911 
925 template <typename Temp, typename To>
926 bool rectilinear_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
927  const Generator& x,
928  const Generator& y,
929  Rounding_Dir dir);
930 
932 
946 template <typename Temp, typename To>
947 bool euclidean_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
948  const Generator& x,
949  const Generator& y,
950  Rounding_Dir dir,
951  Temp& tmp0,
952  Temp& tmp1,
953  Temp& tmp2);
954 
956 
970 template <typename To>
971 bool l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
972  const Generator& x,
973  const Generator& y,
974  Rounding_Dir dir);
975 
977 
991 template <typename Temp, typename To>
992 bool l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
993  const Generator& x,
994  const Generator& y,
995  Rounding_Dir dir);
996 
998 
1012 template <typename Temp, typename To>
1013 bool l_infinity_distance_assign(Checked_Number<To, Extended_Number_Policy>& r,
1014  const Generator& x,
1015  const Generator& y,
1016  Rounding_Dir dir,
1017  Temp& tmp0,
1018  Temp& tmp1,
1019  Temp& tmp2);
1020 
1021 namespace IO_Operators {
1022 
1024 
1025 std::ostream& operator<<(std::ostream& s, const Generator::Type& t);
1026 
1027 } // namespace IO_Operators
1028 
1029 } // namespace Parma_Polyhedra_Library
1030 
1031 #include "Generator_inlines.hh"
1032 
1033 #endif // !defined(PPL_Generator_defs_hh)
void linear_combine(const Generator &y, dimension_type i)
Linearly combines *this with y so that i-th coefficient is 0.
Definition: Generator.cc:207
bool is_not_necessarily_closed() const
Returns true if and only if the topology of *this row is not necessarily closed.
void m_swap(Generator &y)
Swaps *this with y.
Scalar product sign function object depending on topology.
bool operator!=(const Box< ITV > &x, const Box< ITV > &y)
Definition: Box_inlines.hh:264
void set_necessarily_closed()
Sets to NECESSARILY_CLOSED the topological kind of *this row.
void swap(CO_Tree &x, CO_Tree &y)
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
The base class for systems of constraints and generators.
size_t dimension_type
An unsigned integral type for representing space dimensions.
An std::set of variables' indexes.
An adapter for Linear_Expression objects.
void shift_space_dimensions(Variable v, dimension_type n)
void throw_invalid_argument(const char *method, const char *reason) const
Throw a std::invalid_argument exception containing the appropriate error message. ...
Definition: Generator.cc:48
A line, ray, point or closure point.
Linear_Expression expr
The linear expression encoding *this.
memory_size_type total_memory_in_bytes() const
Returns a lower bound to the total size in bytes of the memory occupied by *this. ...
bool is_line_or_ray() const
Returns true if and only if *this is a line or a ray.
Rounding_Dir
Rounding directions for arithmetic computations.
Representation representation() const
Returns the current representation of *this.
static const Generator & zero_dim_point()
Returns the origin of the zero-dimensional space .
static Generator ray(const Linear_Expression &e, Representation r=default_representation)
Returns the ray of direction e.
Definition: Generator.cc:128
bool is_ray_or_point() const
Returns true if and only if *this is not a line.
bool is_equal_to(const Generator &y) const
Returns true if *this is identical to y.
Definition: Generator.cc:258
std::ostream & operator<<(std::ostream &s, const Ask_Tell< D > &x)
static const Generator * zero_dim_closure_point_p
Holds (between class initialization and finalization) a pointer to the origin of the zero-dimensional...
friend int compare(const Generator &x, const Generator &y)
Expression_Hide_Last< Expression_Hide_Inhomo< Linear_Expression > > expr_type
The type of the (adapted) internal expression.
expr_type expression() const
Partial read access to the (adapted) internal expression.
void set_is_line_or_equality()
Sets to LINE_OR_EQUALITY the kind of *this row.
void fancy_print(std::ostream &s) const
A print function, with fancy, more human-friendly output.
Definition: Generator.cc:303
bool is_equivalent_to(const Generator &y) const
Returns true if and only if *this and y are equivalent generators.
Definition: Generator.cc:226
bool is_matching_closure_point(const Generator &p) const
Returns true if and only if the closure point *this has the same coordinates of the point p...
Definition: Generator.cc:399
static Generator closure_point(const Linear_Expression &e=Linear_Expression::zero(), Coefficient_traits::const_reference d=Coefficient_one(), Representation r=default_representation)
Returns the closure point at e / d.
Definition: Generator.cc:92
void set_is_ray_or_point()
Sets the Generator kind to RAY_OR_POINT_OR_INEQUALITY.
void set_topology(Topology x)
Sets to x the topological kind of *this row.
static Generator line(const Linear_Expression &e, Representation r=default_representation)
Returns the line of direction e.
Definition: Generator.cc:143
A dimension of the vector space.
Kind
The possible kinds of Generator objects.
void set_space_dimension_no_ok(dimension_type space_dim)
The base class for convex polyhedra.
bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
A wrapper for numeric types implementing a given policy.
#define PPL_OUTPUT_DECLARATIONS
Generator(Representation r=default_representation)
Constructs the point at the origin.
static void initialize()
Initializes the class.
Definition: Generator.cc:281
Type type() const
Returns the generator type of *this.
bool OK() const
Checks if all the invariants are satisfied.
Definition: Generator.cc:432
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
A Mixed Integer (linear) Programming problem.
void sign_normalize()
Normalizes the sign of the coefficients so that the first non-zero (homogeneous) coefficient of a lin...
Definition: Generator.cc:264
static void finalize()
Finalizes the class.
Definition: Generator.cc:292
void set_not_necessarily_closed()
Sets to NOT_NECESSARILY_CLOSED the topological kind of *this row.
void mark_as_necessarily_closed()
Marks the epsilon dimension as a standard dimension.
bool is_point() const
Returns true if and only if *this is a point.
int compare(const Linear_Expression &x, const Linear_Expression &y)
bool remove_space_dimensions(const Variables_Set &vars)
Removes all the specified dimensions from the generator.
Definition: Generator.cc:168
static const Generator & zero_dim_closure_point()
Returns, as a closure point, the origin of the zero-dimensional space .
void mark_as_not_necessarily_closed()
Marks the last dimension as the epsilon dimension.
static Generator point(const Linear_Expression &e=Linear_Expression::zero(), Coefficient_traits::const_reference d=Coefficient_one(), Representation r=default_representation)
Returns the point at e / d.
Definition: Generator.cc:57
static const Generator * zero_dim_point_p
Holds (between class initialization and finalization) a pointer to the origin of the zero-dimensional...
bool check_strong_normalized() const
Returns true if and only if the coefficients are strongly normalized.
Definition: Generator.cc:271
void set_space_dimension(dimension_type space_dim)
Generator & operator=(const Generator &g)
Assignment operator.
void set_representation(Representation r)
Converts *this to the specified representation.
void set_is_ray_or_point_or_inequality()
Sets to RAY_OR_POINT_OR_INEQUALITY the kind of *this row.
void strong_normalize()
Strong normalization: ensures that different Generator objects represent different hyperplanes or hyp...
bool is_ray() const
Returns true if and only if *this is a ray.
The entire library is confined to this namespace.
Definition: version.hh:61
void set_epsilon_coefficient(Coefficient_traits::const_reference n)
Sets the epsilon coefficient to n. The generator must be NNC.
void set_is_line()
Sets the Generator kind to LINE_OR_EQUALITY.
bool is_ray_or_point_or_inequality() const
Returns true if and only if *this row represents a ray, a point or an inequality. ...
Topology topology() const
Returns the topological kind of *this.
Coefficient_traits::const_reference epsilon_coefficient() const
Returns the epsilon coefficient. The generator must be NNC.
Coefficient_traits::const_reference coefficient(Variable v) const
Returns the coefficient of v in *this.
Sparse representation: only the nonzero coefficient are stored. If there are many nonzero coefficient...
bool operator==(const Box< ITV > &x, const Box< ITV > &y)
bool is_necessarily_closed() const
Returns true if and only if the topology of *this row is necessarily closed.
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
Coefficient_traits::const_reference divisor() const
If *this is either a point or a closure point, returns its divisor.
static const Linear_Expression & zero()
Returns the (zero-dimension space) constant 0.
void permute_space_dimensions(const std::vector< Variable > &cycle)
Permutes the space dimensions of the generator.
Definition: Generator.cc:192
Coefficient_traits::const_reference Coefficient_one()
Returns a const reference to a Coefficient with value 1.
static const Representation default_representation
The representation used for new Generators.
bool is_line_or_equality() const
Returns true if and only if *this row represents a line or an equality.
bool is_line() const
Returns true if and only if *this is a line.
An adapter for Linear_Expression that maybe hides the last coefficient.
void throw_dimension_incompatible(const char *method, const char *v_name, Variable v) const
Throw a std::invalid_argument exception containing the appropriate error message. ...
Definition: Generator.cc:37
Topology
Kinds of polyhedra domains.
A class implementing various scalar product functions.
void swap_space_dimensions(Variable v1, Variable v2)
Swaps the coefficients of the variables v1 and v2 .
Definition: Generator.cc:158
static dimension_type max_space_dimension()
Returns the maximum space dimension a Generator can handle.
bool is_closure_point() const
Returns true if and only if *this is a closure point.
friend class Parma_Polyhedra_Library::Topology_Adjusted_Scalar_Product_Assign
Topology topology_
The topology of *this.