PPL  1.2
Polyhedron_inlines.hh
Go to the documentation of this file.
1 /* Polyhedron class implementation: inline functions.
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_Polyhedron_inlines_hh
25 #define PPL_Polyhedron_inlines_hh 1
26 
27 #include "Generator_defs.hh"
28 #include "compiler.hh"
29 #include <algorithm>
30 #include <deque>
31 
32 namespace Parma_Polyhedra_Library {
33 
34 inline memory_size_type
36  return sizeof(*this) + external_memory_in_bytes();
37 }
38 
39 inline dimension_type
41  return space_dim;
42 }
43 
44 inline int32_t
47 }
48 
49 inline dimension_type
51  using std::min;
52  // One dimension is reserved to have a value of type dimension_type
53  // that does not represent a legal dimension.
54  return min(std::numeric_limits<dimension_type>::max() - 1,
57  )
58  );
59 }
60 
61 inline Topology
63  // We can check either one of the two matrices.
64  // (`con_sys' is slightly better, since it is placed at offset 0.)
65  return con_sys.topology();
66 }
67 
68 inline bool
70  return affine_dimension() == 0;
71 }
72 
73 inline bool
75  // We can check either one of the two matrices.
76  // (`con_sys' is slightly better, since it is placed at offset 0.)
78 }
79 
80 inline void
83 }
84 
85 inline void
88 }
89 
90 inline void
91 Polyhedron::widening_assign(const Polyhedron& y, unsigned* tp) {
92  H79_widening_assign(y, tp);
93 }
94 
95 inline
97 }
98 
99 inline void
101  if (topology() != y.topology()) {
102  throw_topology_incompatible("swap(y)", "y", y);
103  }
104  using std::swap;
105  swap(con_sys, y.con_sys);
106  swap(gen_sys, y.gen_sys);
107  swap(sat_c, y.sat_c);
108  swap(sat_g, y.sat_g);
109  swap(status, y.status);
111 }
112 
114 inline void
116  x.m_swap(y);
117 }
118 
119 inline bool
121  return true;
122 }
123 
124 inline bool
126  return false;
127 }
128 
129 inline bool
131  return status.test_empty();
132 }
133 
134 inline bool
136  return status.test_c_up_to_date();
137 }
138 
139 inline bool
141  return status.test_g_up_to_date();
142 }
143 
144 inline bool
146  return status.test_c_minimized();
147 }
148 
149 inline bool
151  return status.test_g_minimized();
152 }
153 
154 inline bool
156  return status.test_sat_c_up_to_date();
157 }
158 
159 inline bool
161  return status.test_sat_g_up_to_date();
162 }
163 
164 inline bool
166  return status.test_c_pending();
167 }
168 
169 inline bool
171  return status.test_g_pending();
172 }
173 
174 inline bool
177 }
178 
179 inline bool
184 }
185 
186 inline bool
188  if (marked_empty()) {
189  return true;
190  }
191  // Try a fast-fail test: if generators are up-to-date and
192  // there are no pending constraints, then the generator system
193  // (since it is well formed) contains a point.
195  return false;
196  }
197  return !minimize();
198 }
199 
200 inline void
203 }
204 
205 inline void
208 }
209 
210 inline void
214 }
215 
216 inline void
220 }
221 
222 inline void
225 }
226 
227 inline void
230 }
231 
232 inline void
235 }
236 
237 inline void
240 }
241 
242 inline void
245 }
246 
247 inline void
250 }
251 
252 inline void
255 }
256 
257 inline void
260 }
261 
262 inline void
265 }
266 
267 inline void
270  // Can get rid of sat_c here.
271 }
272 
273 inline void
276  // Can get rid of sat_g here.
277 }
278 
279 inline void
286  // Can get rid of con_sys here.
287 }
288 
289 inline void
296  // Can get rid of gen_sys here.
297 }
298 
299 inline bool
301  PPL_ASSERT(space_dim > 0 && !marked_empty());
302  PPL_ASSERT(has_something_pending());
303 
304  if (has_pending_constraints()) {
306  }
307 
308  PPL_ASSERT(has_pending_generators());
310  return true;
311 }
312 
313 inline bool
315  return bounds(expr, true);
316 }
317 
318 inline bool
320  return bounds(expr, false);
321 }
322 
323 inline bool
325  Coefficient& sup_n, Coefficient& sup_d,
326  bool& maximum) const {
327  Generator g(point());
328  return max_min(expr, true, sup_n, sup_d, maximum, g);
329 }
330 
331 inline bool
333  Coefficient& sup_n, Coefficient& sup_d, bool& maximum,
334  Generator& g) const {
335  return max_min(expr, true, sup_n, sup_d, maximum, g);
336 }
337 
338 inline bool
340  Coefficient& inf_n, Coefficient& inf_d,
341  bool& minimum) const {
342  Generator g(point());
343  return max_min(expr, false, inf_n, inf_d, minimum, g);
344 }
345 
346 inline bool
348  Coefficient& inf_n, Coefficient& inf_d, bool& minimum,
349  Generator& g) const {
350  return max_min(expr, false, inf_n, inf_d, minimum, g);
351 }
352 
353 inline Constraint_System
355  PPL_ASSERT(constraints_are_up_to_date());
357  if (cs.num_pending_rows() > 0) {
358  cs.unset_pending_rows();
359  }
361  cs.simplify();
362  }
363  return cs;
364 }
365 
366 inline Congruence_System
369 }
370 
371 inline Congruence_System
374 }
375 
376 inline void
378  add_congruences(cgs);
379 }
380 
381 template <typename FP_Format, typename Interval_Info>
382 inline void
386  const Relation_Symbol relsym) {
387  switch (relsym) {
388  case EQUAL:
389  // TODO: see if we can handle this case more efficiently.
390  refine_with_linear_form_inequality(left, right, false);
391  refine_with_linear_form_inequality(right, left, false);
392  break;
393  case LESS_THAN:
394  refine_with_linear_form_inequality(left, right, true);
395  break;
396  case LESS_OR_EQUAL:
397  refine_with_linear_form_inequality(left, right, false);
398  break;
399  case GREATER_THAN:
400  refine_with_linear_form_inequality(right, left, true);
401  break;
402  case GREATER_OR_EQUAL:
403  refine_with_linear_form_inequality(right, left, false);
404  break;
405  case NOT_EQUAL:
406  break;
407  default:
408  PPL_UNREACHABLE;
409  break;
410  }
411 }
412 
413 template <typename FP_Format, typename Interval_Info>
414 inline void
417  Box< Interval<FP_Format, Interval_Info> >& store) const {
418 
419  // Check that FP_Format is indeed a floating point type.
420  PPL_COMPILE_TIME_CHECK(!std::numeric_limits<FP_Format>::is_exact,
421  "Polyhedron::refine_fp_interval_abstract_store:"
422  " T not a floating point type.");
423 
424  typedef Interval<FP_Format, Interval_Info> FP_Interval_Type;
425  store.intersection_assign(Box<FP_Interval_Type>(*this));
426 
427 }
428 
430 inline bool
431 operator!=(const Polyhedron& x, const Polyhedron& y) {
432  return !(x == y);
433 }
434 
435 inline bool
437  const Polyhedron& x = *this;
438  return x.contains(y) && !y.contains(x);
439 }
440 
441 inline void
443  const Variables_Set* const p_vs = 0;
444  drop_some_non_integer_points(p_vs, complexity);
445 }
446 
447 inline void
449  Complexity_Class complexity) {
450  drop_some_non_integer_points(&vars, complexity);
451 }
452 
453 
454 namespace Interfaces {
455 
456 inline bool
458  return ph.is_necessarily_closed();
459 }
460 
461 } // namespace Interfaces
462 
463 } // namespace Parma_Polyhedra_Library
464 
465 #endif // !defined(PPL_Polyhedron_inlines_hh)
bool has_pending_constraints() const
Returns true if there are pending constraints.
bool constraints_are_minimized() const
Returns true if the system of constraints is minimized.
void drop_some_non_integer_points(Complexity_Class complexity=ANY_COMPLEXITY)
Possibly tightens *this by dropping some points with non-integer coordinates.
void widening_assign(const Polyhedron &y, unsigned *tp=0)
Same as H79_widening_assign(y, tp).
bool marked_empty() const
Returns true if the polyhedron is known to be empty.
int32_t hash_code() const
Returns a 32-bit hash code for *this.
void set_sat_g_up_to_date()
Sets status to express that sat_g is up-to-date.
bool bounds_from_above(const Linear_Expression &expr) const
Returns true if and only if expr is bounded from above in *this.
void swap(CO_Tree &x, CO_Tree &y)
bool minimize() const
Applies (weak) minimization to both the constraints and generators.
void clear_constraints_up_to_date()
Sets status to express that constraints are no longer up-to-date.
size_t dimension_type
An unsigned integral type for representing space dimensions.
bool max_min(const Linear_Expression &expr, bool maximize, Coefficient &ext_n, Coefficient &ext_d, bool &included, Generator &g) const
Maximizes or minimizes expr subject to *this.
An std::set of variables' indexes.
void poly_difference_assign(const Polyhedron &y)
Assigns to *this the poly-difference of *this and y.
Generator_System gen_sys
The system of generators.
A line, ray, point or closure point.
bool generators_are_minimized() const
Returns true if the system of generators is minimized.
bool is_empty() const
Returns true if and only if *this is an empty polyhedron.
void simplify()
Applies Gaussian elimination and back-substitution so as to provide a partial simplification of the s...
void set_generators_up_to_date()
Sets status to express that generators are up-to-date.
Congruence_System minimized_congruences() const
Returns a system of (equality) congruences satisfied by *this, with no redundant congruences and havi...
void set_constraints_pending()
Sets status to express that constraints are pending.
void clear_pending_generators()
Sets status to express that there are no longer pending generators.
bool is_necessarily_closed() const
Returns true if and only if the system topology is NECESSARILY_CLOSED.
void add_congruences(const Congruence_System &cgs)
Adds a copy of the congruences in cgs to *this, if all the congruences can be exactly represented by ...
void generalized_refine_with_linear_form_inequality(const Linear_Form< Interval< FP_Format, Interval_Info > > &left, const Linear_Form< Interval< FP_Format, Interval_Info > > &right, Relation_Symbol relsym)
Refines *this with the constraint expressed by left right, where is the relation symbol specified b...
static bool can_recycle_congruence_systems()
Returns false indicating that this domain cannot recycle congruences.
bool sat_c_is_up_to_date() const
Returns true if the saturation matrix sat_c is up-to-date.
dimension_type num_pending_rows() const
Returns the number of rows that are in the pending part of the system.
void set_constraints_up_to_date()
Sets status to express that constraints are up-to-date.
void swap(Polyhedron &x, Polyhedron &y)
Swaps x with y.
bool sat_g_is_up_to_date() const
Returns true if the saturation matrix sat_g is up-to-date.
bool strictly_contains(const Polyhedron &y) const
Returns true if and only if *this strictly contains y.
Topology topology() const
Returns the system topology.
void H79_widening_assign(const Polyhedron &y, unsigned *tp=0)
Assigns to *this the result of computing the H79_widening between *this and y.
bool bounds_from_below(const Linear_Expression &expr) const
Returns true if and only if expr is bounded from below in *this.
void refine_with_linear_form_inequality(const Linear_Form< Interval< FP_Format, Interval_Info > > &left, const Linear_Form< Interval< FP_Format, Interval_Info > > &right, bool is_strict=false)
Refines *this with the constraint expressed by left right if is_strict is set, with the constraint l...
void add_recycled_congruences(Congruence_System &cgs)
Adds the congruences in cgs to *this, if all the congruences can be exactly represented by a polyhedr...
bool can_have_something_pending() const
Returns true if the polyhedron can have something pending.
Complexity_Class
Complexity pseudo-classes.
The base class for convex polyhedra.
void set_sat_c_up_to_date()
Sets status to express that sat_c is up-to-date.
Constraint_System simplified_constraints() const
If constraints are up-to-date, obtain a simplified copy of them.
Topology topology() const
Returns the topological kind of the polyhedron.
bool generators_are_up_to_date() const
Returns true if the system of generators is up-to-date.
Constraint_System con_sys
The system of constraints.
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
bool process_pending() const
Processes the pending rows of either description of the polyhedron and obtains a minimized polyhedron...
#define PPL_COMPILE_TIME_CHECK(e, msg)
Produces a compilation error if the compile-time constant e does not evaluate to true ...
void clear_pending_constraints()
Sets status to express that there are no longer pending constraints.
Relation_Symbol
Relation symbols.
bool constraints_are_up_to_date() const
Returns true if the system of constraints is up-to-date.
void throw_topology_incompatible(const char *method, const char *ph_name, const Polyhedron &ph) const
A linear form with interval coefficients.
Bit_Matrix sat_g
The saturation matrix having generators on its columns.
void set_generators_minimized()
Sets status to express that generators are minimized.
static dimension_type max_space_dimension()
Returns the maximum space dimension all kinds of Polyhedron can handle.
bool maximize(const Linear_Expression &expr, Coefficient &sup_n, Coefficient &sup_d, bool &maximum) const
Returns true if and only if *this is not empty and expr is bounded from above in *this, in which case the supremum value is computed.
void refine_fp_interval_abstract_store(Box< Interval< FP_Format, Interval_Info > > &store) const
Refines store with the constraints defining *this.
A not necessarily closed, iso-oriented hyperrectangle.
Definition: Box_defs.hh:299
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
int32_t hash_code_from_dimension(dimension_type dim)
Returns the hash code for space dimension dim.
void process_pending_generators() const
Processes the pending generators and obtains a minimized polyhedron.
void clear_empty()
Clears the status flag indicating that the polyhedron is empty.
Status status
The status flags to keep track of the polyhedron's internal state.
bool operator!=(const Polyhedron &x, const Polyhedron &y)
A generic, not necessarily closed, possibly restricted interval.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Constraint_System can handle.
The entire library is confined to this namespace.
Definition: version.hh:61
dimension_type space_dim
The number of dimensions of the enclosing vector space.
void difference_assign(const Polyhedron &y)
Same as poly_difference_assign(y).
bool bounds(const Linear_Expression &expr, bool from_above) const
Checks if and how expr is bounded in *this.
void upper_bound_assign(const Polyhedron &y)
Same as poly_hull_assign(y).
Congruence_System congruences() const
Returns a system of (equality) congruences satisfied by *this.
bool contains(const Polyhedron &y) const
Returns true if and only if *this contains y.
void poly_hull_assign(const Polyhedron &y)
Assigns to *this the poly-hull of *this and y.
bool is_necessarily_closed() const
Returns true if and only if the polyhedron is necessarily closed.
void clear_sat_g_up_to_date()
Sets status to express that sat_g is no longer up-to-date.
void unset_pending_rows()
Sets the index to indicate that the system has no pending rows.
bool process_pending_constraints() const
Processes the pending constraints and obtains a minimized polyhedron.
void clear_constraints_minimized()
Sets status to express that constraints are no longer minimized.
memory_size_type total_memory_in_bytes() const
Returns the total size in bytes of the memory occupied by *this.
bool has_pending_generators() const
Returns true if there are pending generators.
dimension_type affine_dimension() const
Returns , if *this is empty; otherwise, returns the affine dimension of *this.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Generator_System can handle.
void clear_sat_c_up_to_date()
Sets status to express that sat_c is no longer up-to-date.
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
Bit_Matrix sat_c
The saturation matrix having constraints on its columns.
void set_constraints_minimized()
Sets status to express that constraints are minimized.
static bool can_recycle_constraint_systems()
Returns true indicating that this domain has methods that can recycle constraints.
void set_generators_pending()
Sets status to express that generators are pending.
const Constraint_System & minimized_constraints() const
Returns the system of constraints, with no redundant constraint.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
bool is_necessarily_closed_for_interfaces(const Polyhedron &ph)
Returns true if and only if ph.topology() == NECESSARILY_CLOSED.
void m_swap(Polyhedron &y)
Swaps *this with polyhedron y. (*this and y can be dimension-incompatible.)
void clear_generators_up_to_date()
Sets status to express that generators are no longer up-to-date.
bool is_discrete() const
Returns true if and only if *this is discrete.
Topology
Kinds of polyhedra domains.
void clear_generators_minimized()
Sets status to express that generators are no longer minimized.
bool has_something_pending() const
Returns true if there are either pending constraints or pending generators.