PPL  1.2
Grid_inlines.hh
Go to the documentation of this file.
1 /* Grid 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_Grid_inlines_hh
25 #define PPL_Grid_inlines_hh 1
26 
27 #include "Grid_Generator_defs.hh"
30 #include <algorithm>
31 
32 namespace Parma_Polyhedra_Library {
33 
34 inline bool
36  return status.test_empty();
37 }
38 
39 inline bool
41  return status.test_c_up_to_date();
42 }
43 
44 inline bool
46  return status.test_g_up_to_date();
47 }
48 
49 inline bool
51  return status.test_c_minimized();
52 }
53 
54 inline bool
56  return status.test_g_minimized();
57 }
58 
59 inline void
62 }
63 
64 inline void
67 }
68 
69 inline void
73 }
74 
75 inline void
79 }
80 
81 inline void
84 }
85 
86 inline void
89 }
90 
91 inline void
94 }
95 
96 inline void
100  // Can get rid of con_sys here.
101 }
102 
103 inline void
107  // Can get rid of gen_sys here.
108 }
109 
110 inline dimension_type
112  // One dimension is reserved to have a value of type dimension_type
113  // that does not represent a legal dimension.
114  return std::min(std::numeric_limits<dimension_type>::max() - 1,
117  )
118  );
119 }
120 
121 inline
122 Grid::Grid(dimension_type num_dimensions,
123  const Degenerate_Element kind)
124  : con_sys(),
125  gen_sys(check_space_dimension_overflow(num_dimensions,
127  "PPL::Grid::",
128  "Grid(n, k)",
129  "n exceeds the maximum "
130  "allowed space dimension")) {
131  construct(num_dimensions, kind);
132  PPL_ASSERT(OK());
133 }
134 
135 inline
137  : con_sys(check_space_dimension_overflow(cgs.space_dimension(),
139  "PPL::Grid::",
140  "Grid(cgs)",
141  "the space dimension of cgs "
142  "exceeds the maximum allowed "
143  "space dimension")),
144  gen_sys(cgs.space_dimension()) {
145  Congruence_System cgs_copy(cgs);
146  construct(cgs_copy);
147 }
148 
149 inline
151  : con_sys(check_space_dimension_overflow(cgs.space_dimension(),
153  "PPL::Grid::",
154  "Grid(cgs, recycle)",
155  "the space dimension of cgs "
156  "exceeds the maximum allowed "
157  "space dimension")),
158  gen_sys(cgs.space_dimension()) {
159  construct(cgs);
160 }
161 
162 inline
164  : con_sys(check_space_dimension_overflow(ggs.space_dimension(),
166  "PPL::Grid::",
167  "Grid(ggs)",
168  "the space dimension of ggs "
169  "exceeds the maximum allowed "
170  "space dimension")),
171  gen_sys(ggs.space_dimension()) {
172  Grid_Generator_System ggs_copy(ggs);
173  construct(ggs_copy);
174 }
175 
176 inline
178  : con_sys(check_space_dimension_overflow(ggs.space_dimension(),
180  "PPL::Grid::",
181  "Grid(ggs, recycle)",
182  "the space dimension of ggs "
183  "exceeds the maximum allowed "
184  "space dimension")),
185  gen_sys(ggs.space_dimension()) {
186  construct(ggs);
187 }
188 
189 template <typename U>
190 inline
192  : con_sys(check_space_dimension_overflow(bd.space_dimension(),
194  "PPL::Grid::",
195  "Grid(bd)",
196  "the space dimension of bd "
197  "exceeds the maximum allowed "
198  "space dimension")),
199  gen_sys(bd.space_dimension()) {
200  Congruence_System cgs = bd.congruences();
201  construct(cgs);
202 }
203 
204 template <typename U>
205 inline
207  : con_sys(check_space_dimension_overflow(os.space_dimension(),
209  "PPL::Grid::",
210  "Grid(os)",
211  "the space dimension of os "
212  "exceeds the maximum allowed "
213  "space dimension")),
214  gen_sys(os.space_dimension()) {
215  Congruence_System cgs = os.congruences();
216  construct(cgs);
217 }
218 
219 inline
221 }
222 
223 inline dimension_type
225  return space_dim;
226 }
227 
228 inline memory_size_type
230  return sizeof(*this) + external_memory_in_bytes();
231 }
232 
233 inline int32_t
236 }
237 
238 inline Constraint_System
240  return Constraint_System(congruences());
241 }
242 
243 inline Constraint_System
246 }
247 
248 inline void
250  using std::swap;
251  swap(con_sys, y.con_sys);
252  swap(gen_sys, y.gen_sys);
253  swap(status, y.status);
256 }
257 
258 inline void
260  // Dimension-compatibility check.
261  if (space_dim < cg.space_dimension()) {
262  throw_dimension_incompatible("add_congruence(cg)", "cg", cg);
263  }
264 
265  if (!marked_empty()) {
267  }
268 }
269 
270 inline void
272  // TODO: this is just an executable specification.
273  // Space dimension compatibility check.
274  if (space_dim < cgs.space_dimension()) {
275  throw_dimension_incompatible("add_congruences(cgs)", "cgs", cgs);
276  }
277 
278  if (!marked_empty()) {
279  Congruence_System cgs_copy = cgs;
280  add_recycled_congruences(cgs_copy);
281  }
282 }
283 
284 inline void
286  add_congruence(cg);
287 }
288 
289 inline void
291  add_congruences(cgs);
292 }
293 
294 inline bool
296  return true;
297 }
298 
299 inline bool
301  return true;
302 }
303 
304 inline void
306  // Space dimension compatibility check.
307  if (space_dim < c.space_dimension()) {
308  throw_dimension_incompatible("add_constraint(c)", "c", c);
309  }
310  if (!marked_empty()) {
312  }
313 }
314 
315 inline void
317  // TODO: really recycle the constraints.
318  add_constraints(cs);
319 }
320 
321 inline bool
323  return bounds(expr, "bounds_from_above(e)");
324 }
325 
326 inline bool
328  return bounds(expr, "bounds_from_below(e)");
329 }
330 
331 inline bool
333  Coefficient& sup_n, Coefficient& sup_d, bool& maximum) const {
334  return max_min(expr, "maximize(e, ...)", sup_n, sup_d, maximum);
335 }
336 
337 inline bool
339  Coefficient& sup_n, Coefficient& sup_d, bool& maximum,
340  Generator& point) const {
341  return max_min(expr, "maximize(e, ...)", sup_n, sup_d, maximum, &point);
342 }
343 
344 inline bool
346  Coefficient& inf_n, Coefficient& inf_d, bool& minimum) const {
347  return max_min(expr, "minimize(e, ...)", inf_n, inf_d, minimum);
348 }
349 
350 inline bool
352  Coefficient& inf_n, Coefficient& inf_d, bool& minimum,
353  Generator& point) const {
354  return max_min(expr, "minimize(e, ...)", inf_n, inf_d, minimum, &point);
355 }
356 
357 inline void
360  divisor = 1;
361  normalize_divisors(sys, divisor);
362 }
363 
365 inline bool
366 operator!=(const Grid& x, const Grid& y) {
367  return !(x == y);
368 }
369 
370 inline bool
371 Grid::strictly_contains(const Grid& y) const {
372  const Grid& x = *this;
373  return x.contains(y) && !y.contains(x);
374 }
375 
376 inline void
378 }
379 
381 inline void
382 swap(Grid& x, Grid& y) {
383  x.m_swap(y);
384 }
385 
386 } // namespace Parma_Polyhedra_Library
387 
388 #endif // !defined(PPL_Grid_inlines_hh)
Grid_Generator_System gen_sys
The system of generators.
Definition: Grid_defs.hh:1973
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
dimension_type max_space_dimension()
Returns the maximum space dimension this library can handle.
Status status
The status flags to keep track of the grid's internal state.
Definition: Grid_defs.hh:1980
void clear_congruences_minimized()
Sets status to express that congruences are no longer minimized.
Definition: Grid_inlines.hh:87
A linear equality or inequality.
void swap(CO_Tree &x, CO_Tree &y)
void clear_generators_up_to_date()
Sets status to express that generators are out of date.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
Grid(dimension_type num_dimensions=0, Degenerate_Element kind=UNIVERSE)
Builds a grid having the specified properties.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Congruence_System can handle.
void add_constraints(const Constraint_System &cs)
Adds to *this congruences equivalent to the constraints in cs.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Congruence_System congruences() const
Returns a system of (equality) congruences satisfied by *this.
Congruence_System con_sys
The system of congruences.
Definition: Grid_defs.hh:1970
const Congruence_System & congruences() const
Returns the system of congruences.
Definition: Grid_public.cc:300
A line, ray, point or closure point.
void clear_generators_minimized()
Sets status to express that generators are no longer minimized.
Definition: Grid_inlines.hh:92
void add_congruence_no_check(const Congruence &cg)
Adds the congruence cg to *this.
memory_size_type total_memory_in_bytes() const
Returns the total size in bytes of the memory occupied by *this.
Constraint_System minimized_constraints() const
Returns a minimal system of equality constraints satisfied by *this with the same affine dimension as...
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
bool bounds_from_above(const Linear_Expression &expr) const
Returns true if and only if expr is bounded in *this.
static bool can_recycle_constraint_systems()
Returns true indicating that this domain has methods that can recycle constraints.
int32_t hash_code() const
Returns a 32-bit hash code for *this.
void add_constraint_no_check(const Constraint &c)
Uses the constraint c to refine *this.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
void add_congruences(const Congruence_System &cgs)
Adds a copy of each congruence in cgs to *this.
bool congruences_are_up_to_date() const
Returns true if the system of congruences is up-to-date.
Definition: Grid_inlines.hh:40
bool strictly_contains(const Grid &y) const
Returns true if and only if *this strictly contains y.
void clear_congruences_up_to_date()
Sets status to express that congruences are out of date.
Definition: Grid_inlines.hh:97
static void normalize_divisors(Grid_Generator_System &sys, Coefficient &divisor, const Grid_Generator *first_point=NULL)
Normalizes the divisors in sys.
void refine_with_congruence(const Congruence &cg)
Uses a copy of the congruence cg to refine *this.
static dimension_type max_space_dimension()
Returns the maximum space dimension a Grid_Generator_System can handle.
void set_generators_minimized()
Sets status to express that generators are minimized.
Definition: Grid_inlines.hh:76
void throw_dimension_incompatible(const char *method, const char *other_name, dimension_type other_dim) const
Complexity_Class
Complexity pseudo-classes.
bool max_min(const Linear_Expression &expr, const char *method_call, Coefficient &ext_n, Coefficient &ext_d, bool &included, Generator *point=NULL) const
Maximizes or minimizes expr subject to *this.
bool OK(bool check_not_empty=false) const
Checks if all the invariants are satisfied.
Definition: Grid_public.cc:958
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
bool operator!=(const Grid &x, const Grid &y)
bool bounds(const Linear_Expression &expr, const char *method_call) const
Checks if and how expr is bounded in *this.
Degenerate_Element
Kinds of degenerate abstract elements.
static bool can_recycle_congruence_systems()
Returns true indicating that this domain has methods that can recycle congruences.
dimension_type check_space_dimension_overflow(const dimension_type dim, const dimension_type max, const char *domain, const char *method, const char *reason)
Definition: globals.cc:48
const Congruence_System & minimized_congruences() const
Returns the system of congruences in minimal form.
Definition: Grid_public.cc:319
void set_generators_up_to_date()
Sets status to express that generators are up-to-date.
Definition: Grid_inlines.hh:60
void refine_with_congruences(const Congruence_System &cgs)
Uses a copy of the congruences in cgs to refine *this.
void swap(Grid &x, Grid &y)
Swaps x with y.
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.
bool contains(const Grid &y) const
Returns true if and only if *this contains y.
dimension_type space_dimension() const
Returns the dimension of the vector space enclosing *this.
bool generators_are_up_to_date() const
Returns true if the system of generators is up-to-date.
Definition: Grid_inlines.hh:45
dimension_type space_dim
The number of dimensions of the enclosing vector space.
Definition: Grid_defs.hh:1983
Constraint_System constraints() const
Returns a system of equality constraints satisfied by *this with the same affine dimension as *this...
The entire library is confined to this namespace.
Definition: version.hh:61
bool marked_empty() const
Returns true if the grid is known to be empty.
Definition: Grid_inlines.hh:35
bool congruences_are_minimized() const
Returns true if the system of congruences is minimized.
Definition: Grid_inlines.hh:50
A bounded difference shape.
void add_congruence(const Congruence &cg)
Adds a copy of congruence cg to *this.
void clear_empty()
Clears the status flag indicating that the grid is empty.
Definition: Grid_inlines.hh:82
void add_constraint(const Constraint &c)
Adds to *this a congruence equivalent to constraint c.
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 add_recycled_constraints(Constraint_System &cs)
Adds to *this congruences equivalent to the constraints in cs.
static dimension_type max_space_dimension()
Returns the maximum space dimension all kinds of Grid can handle.
Congruence_System congruences() const
Returns a system of (equality) congruences satisfied by *this.
bool bounds_from_below(const Linear_Expression &expr) const
Returns true if and only if expr is bounded in *this.
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
Coefficient c
Definition: PIP_Tree.cc:64
void set_congruences_up_to_date()
Sets status to express that congruences are up-to-date.
Definition: Grid_inlines.hh:65
void m_swap(Grid &y)
Swaps *this with grid y. (*this and y can be dimension-incompatible.)
bool generators_are_minimized() const
Returns true if the system of generators is minimized.
Definition: Grid_inlines.hh:55
void add_recycled_congruences(Congruence_System &cgs)
Adds the congruences in cgs to *this.
void construct(dimension_type num_dimensions, Degenerate_Element kind)
Builds a grid universe or empty grid.
void set_congruences_minimized()
Sets status to express that congruences are minimized.
Definition: Grid_inlines.hh:70
void topological_closure_assign()
Assigns to *this its topological closure.
bool minimize() const
Minimizes both the congruences and the generators.