1 /* Constraint_System 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_Constraint_System_inlines_hh
25 #define PPL_Constraint_System_inlines_hh 1
26 
27 #include "Constraint_defs.hh"
28 
29 namespace Parma_Polyhedra_Library {
30 
31 inline
Constraint_System(Representation r)32 Constraint_System::Constraint_System(Representation r)
33   : sys(NECESSARILY_CLOSED, r) {
34 }
35 
36 inline
Constraint_System(const Constraint & c,Representation r)37 Constraint_System::Constraint_System(const Constraint& c, Representation r)
38   : sys(c.topology(), r) {
39   sys.insert(c);
40 }
41 
42 inline
Constraint_System(const Constraint_System & cs)43 Constraint_System::Constraint_System(const Constraint_System& cs)
44   : sys(cs.sys) {
45 }
46 
47 inline
Constraint_System(const Constraint_System & cs,Representation r)48 Constraint_System::Constraint_System(const Constraint_System& cs,
49                                      Representation r)
50   : sys(cs.sys, r) {
51 }
52 
53 inline
Constraint_System(const Topology topol,Representation r)54 Constraint_System::Constraint_System(const Topology topol, Representation r)
55   : sys(topol, r) {
56 }
57 
58 inline
Constraint_System(const Topology topol,const dimension_type space_dim,Representation r)59 Constraint_System::Constraint_System(const Topology topol,
60                                      const dimension_type space_dim,
61                                      Representation r)
62   : sys(topol, space_dim, r) {
63 }
64 
65 inline
~Constraint_System()66 Constraint_System::~Constraint_System() {
67 }
68 
69 inline Constraint_System&
operator =(const Constraint_System & y)70 Constraint_System::operator=(const Constraint_System& y) {
71   Constraint_System tmp = y;
72   swap(*this, tmp);
73   return *this;
74 }
75 
76 inline const Constraint&
operator [](const dimension_type k) const77 Constraint_System::operator[](const dimension_type k) const {
78   return sys[k];
79 }
80 
81 inline Representation
representation() const82 Constraint_System::representation() const {
83   return sys.representation();
84 }
85 
86 inline void
set_representation(Representation r)87 Constraint_System::set_representation(Representation r) {
88   sys.set_representation(r);
89 }
90 
91 inline dimension_type
max_space_dimension()92 Constraint_System::max_space_dimension() {
93   return Linear_System<Constraint>::max_space_dimension();
94 }
95 
96 inline dimension_type
space_dimension() const97 Constraint_System::space_dimension() const {
98   return sys.space_dimension();
99 }
100 
101 inline void
set_space_dimension(dimension_type space_dim)102 Constraint_System::set_space_dimension(dimension_type space_dim) {
103   return sys.set_space_dimension(space_dim);
104 }
105 
106 inline void
clear()107 Constraint_System::clear() {
108   sys.clear();
109 }
110 
111 inline const Constraint_System&
zero_dim_empty()112 Constraint_System::zero_dim_empty() {
113   PPL_ASSERT(zero_dim_empty_p != 0);
114   return *zero_dim_empty_p;
115 }
116 
117 inline
Constraint_System_const_iterator()118 Constraint_System_const_iterator::Constraint_System_const_iterator()
119   : i(), csp(0) {
120 }
121 
122 inline
Constraint_System_const_iterator(const Constraint_System_const_iterator & y)123 Constraint_System_const_iterator::Constraint_System_const_iterator(const Constraint_System_const_iterator& y)
124   : i(y.i), csp(y.csp) {
125 }
126 
127 inline
~Constraint_System_const_iterator()128 Constraint_System_const_iterator::~Constraint_System_const_iterator() {
129 }
130 
131 inline Constraint_System_const_iterator&
operator =(const Constraint_System_const_iterator & y)132 Constraint_System_const_iterator::operator=(const Constraint_System_const_iterator& y) {
133   i = y.i;
134   csp = y.csp;
135   return *this;
136 }
137 
138 inline const Constraint&
operator *() const139 Constraint_System_const_iterator::operator*() const {
140   return *i;
141 }
142 
143 inline const Constraint*
operator ->() const144 Constraint_System_const_iterator::operator->() const {
145   return i.operator->();
146 }
147 
148 inline Constraint_System_const_iterator&
operator ++()149 Constraint_System_const_iterator::operator++() {
150   ++i;
151   skip_forward();
152   return *this;
153 }
154 
155 inline Constraint_System_const_iterator
operator ++(int)156 Constraint_System_const_iterator::operator++(int) {
157   const Constraint_System_const_iterator tmp = *this;
158   operator++();
159   return tmp;
160 }
161 
162 inline bool
operator ==(const Constraint_System_const_iterator & y) const163 Constraint_System_const_iterator::operator==(const Constraint_System_const_iterator& y) const {
164   return i == y.i;
165 }
166 
167 inline bool
operator !=(const Constraint_System_const_iterator & y) const168 Constraint_System_const_iterator::operator!=(const Constraint_System_const_iterator& y) const {
169   return i != y.i;
170 }
171 
172 inline
173 Constraint_System_const_iterator::
Constraint_System_const_iterator(const Linear_System<Constraint>::const_iterator & iter,const Constraint_System & cs)174 Constraint_System_const_iterator(const Linear_System<Constraint>::const_iterator& iter,
175                const Constraint_System& cs)
176   : i(iter), csp(&cs.sys) {
177 }
178 
179 inline Constraint_System_const_iterator
begin() const180 Constraint_System::begin() const {
181   const_iterator i(sys.begin(), *this);
182   i.skip_forward();
183   return i;
184 }
185 
186 inline Constraint_System_const_iterator
end() const187 Constraint_System::end() const {
188   const Constraint_System_const_iterator i(sys.end(), *this);
189   return i;
190 }
191 
192 inline bool
empty() const193 Constraint_System::empty() const {
194   return begin() == end();
195 }
196 
197 inline void
add_low_level_constraints()198 Constraint_System::add_low_level_constraints() {
199   if (sys.is_necessarily_closed()) {
200     // The positivity constraint.
201     insert(Constraint::zero_dim_positivity());
202   }
203   else {
204     // Add the epsilon constraints.
205     insert(Constraint::epsilon_leq_one());
206     insert(Constraint::epsilon_geq_zero());
207   }
208 }
209 
210 inline void
m_swap(Constraint_System & y)211 Constraint_System::m_swap(Constraint_System& y) {
212   swap(sys, y.sys);
213 }
214 
215 inline memory_size_type
external_memory_in_bytes() const216 Constraint_System::external_memory_in_bytes() const {
217   return sys.external_memory_in_bytes();
218 }
219 
220 inline memory_size_type
total_memory_in_bytes() const221 Constraint_System::total_memory_in_bytes() const {
222   return external_memory_in_bytes() + sizeof(*this);
223 }
224 
225 inline void
simplify()226 Constraint_System::simplify() {
227   sys.simplify();
228 }
229 
230 inline Topology
topology() const231 Constraint_System::topology() const {
232   return sys.topology();
233 }
234 
235 inline dimension_type
num_rows() const236 Constraint_System::num_rows() const {
237   return sys.num_rows();
238 }
239 
240 inline bool
is_necessarily_closed() const241 Constraint_System::is_necessarily_closed() const {
242   return sys.is_necessarily_closed();
243 }
244 
245 inline dimension_type
num_pending_rows() const246 Constraint_System::num_pending_rows() const {
247   return sys.num_pending_rows();
248 }
249 
250 inline dimension_type
first_pending_row() const251 Constraint_System::first_pending_row() const {
252   return sys.first_pending_row();
253 }
254 
255 inline bool
is_sorted() const256 Constraint_System::is_sorted() const {
257   return sys.is_sorted();
258 }
259 
260 inline void
unset_pending_rows()261 Constraint_System::unset_pending_rows() {
262   sys.unset_pending_rows();
263 }
264 
265 inline void
set_index_first_pending_row(dimension_type i)266 Constraint_System::set_index_first_pending_row(dimension_type i) {
267   sys.set_index_first_pending_row(i);
268 }
269 
270 inline void
set_sorted(bool b)271 Constraint_System::set_sorted(bool b) {
272   sys.set_sorted(b);
273 }
274 
275 inline void
remove_row(dimension_type i,bool keep_sorted)276 Constraint_System::remove_row(dimension_type i, bool keep_sorted) {
277   sys.remove_row(i, keep_sorted);
278 }
279 
280 inline void
remove_rows(dimension_type first,dimension_type last,bool keep_sorted)281 Constraint_System::remove_rows(dimension_type first, dimension_type last,
282                                bool keep_sorted) {
283   sys.remove_rows(first, last, keep_sorted);
284 }
285 
286 inline void
remove_rows(const std::vector<dimension_type> & indexes)287 Constraint_System::remove_rows(const std::vector<dimension_type>& indexes) {
288   sys.remove_rows(indexes);
289 }
290 
291 inline void
remove_trailing_rows(dimension_type n)292 Constraint_System::remove_trailing_rows(dimension_type n) {
293   sys.remove_trailing_rows(n);
294 }
295 
296 inline void
297 Constraint_System
remove_space_dimensions(const Variables_Set & vars)298 ::remove_space_dimensions(const Variables_Set& vars) {
299   sys.remove_space_dimensions(vars);
300 }
301 
302 inline void
303 Constraint_System
shift_space_dimensions(Variable v,dimension_type n)304 ::shift_space_dimensions(Variable v, dimension_type n) {
305   sys.shift_space_dimensions(v, n);
306 }
307 
308 inline void
309 Constraint_System
permute_space_dimensions(const std::vector<Variable> & cycle)310 ::permute_space_dimensions(const std::vector<Variable>& cycle) {
311   sys.permute_space_dimensions(cycle);
312 }
313 
314 inline void
315 Constraint_System
swap_space_dimensions(Variable v1,Variable v2)316 ::swap_space_dimensions(Variable v1, Variable v2) {
317   sys.swap_space_dimensions(v1, v2);
318 }
319 
320 inline bool
has_no_rows() const321 Constraint_System::has_no_rows() const {
322   return sys.has_no_rows();
323 }
324 
325 inline void
strong_normalize()326 Constraint_System::strong_normalize() {
327   sys.strong_normalize();
328 }
329 
330 inline void
sort_rows()331 Constraint_System::sort_rows() {
332   sys.sort_rows();
333 }
334 
335 inline void
insert_pending(Constraint_System & r,Recycle_Input)336 Constraint_System::insert_pending(Constraint_System& r, Recycle_Input) {
337   sys.insert_pending(r.sys, Recycle_Input());
338 }
339 
340 inline void
insert(Constraint_System & r,Recycle_Input)341 Constraint_System::insert(Constraint_System& r, Recycle_Input) {
342   sys.insert(r.sys, Recycle_Input());
343 }
344 
345 inline void
insert_pending(const Constraint_System & r)346 Constraint_System::insert_pending(const Constraint_System& r) {
347   sys.insert_pending(r.sys);
348 }
349 
350 inline void
merge_rows_assign(const Constraint_System & y)351 Constraint_System::merge_rows_assign(const Constraint_System& y) {
352   sys.merge_rows_assign(y.sys);
353 }
354 
355 inline void
insert(const Constraint_System & y)356 Constraint_System::insert(const Constraint_System& y) {
357   sys.insert(y.sys);
358 }
359 
360 inline void
mark_as_necessarily_closed()361 Constraint_System::mark_as_necessarily_closed() {
362   sys.mark_as_necessarily_closed();
363 }
364 
365 inline void
mark_as_not_necessarily_closed()366 Constraint_System::mark_as_not_necessarily_closed() {
367   sys.mark_as_not_necessarily_closed();
368 }
369 
370 inline dimension_type
gauss(dimension_type n_lines_or_equalities)371 Constraint_System::gauss(dimension_type n_lines_or_equalities) {
372   return sys.gauss(n_lines_or_equalities);
373 }
374 
375 inline void
back_substitute(dimension_type n_lines_or_equalities)376 Constraint_System::back_substitute(dimension_type n_lines_or_equalities) {
377   sys.back_substitute(n_lines_or_equalities);
378 }
379 
380 inline void
assign_with_pending(const Constraint_System & y)381 Constraint_System::assign_with_pending(const Constraint_System& y) {
382   sys.assign_with_pending(y.sys);
383 }
384 
385 inline void
sort_pending_and_remove_duplicates()386 Constraint_System::sort_pending_and_remove_duplicates() {
387   sys.sort_pending_and_remove_duplicates();
388 }
389 
390 inline void
sort_and_remove_with_sat(Bit_Matrix & sat)391 Constraint_System::sort_and_remove_with_sat(Bit_Matrix& sat) {
392   sys.sort_and_remove_with_sat(sat);
393 }
394 
395 inline bool
check_sorted() const396 Constraint_System::check_sorted() const {
397   return sys.check_sorted();
398 }
399 
400 inline dimension_type
num_lines_or_equalities() const401 Constraint_System::num_lines_or_equalities() const {
402   return sys.num_lines_or_equalities();
403 }
404 
405 inline void
add_universe_rows_and_space_dimensions(dimension_type n)406 Constraint_System::add_universe_rows_and_space_dimensions(dimension_type n) {
407   sys.add_universe_rows_and_space_dimensions(n);
408 }
409 
410 inline bool
operator ==(const Constraint_System & x,const Constraint_System & y)411 operator==(const Constraint_System& x, const Constraint_System& y) {
412   return x.sys == y.sys;
413 }
414 
415 inline bool
operator !=(const Constraint_System & x,const Constraint_System & y)416 operator!=(const Constraint_System& x, const Constraint_System& y) {
417   return !(x == y);
418 }
419 
420 /*! \relates Constraint_System */
421 inline void
swap(Constraint_System & x,Constraint_System & y)422 swap(Constraint_System& x, Constraint_System& y) {
423   x.m_swap(y);
424 }
425 
426 namespace Implementation {
427 
428 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
429 /*! \relates Parma_Polyhedra_Library::Constraint_System */
430 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
431 inline dimension_type
num_constraints(const Constraint_System & cs)432 num_constraints(const Constraint_System& cs) {
433   return static_cast<dimension_type>(std::distance(cs.begin(), cs.end()));
434 }
435 
436 } // namespace Implementation
437 
438 } // namespace Parma_Polyhedra_Library
439 
440 #endif // !defined(PPL_Constraint_System_inlines_hh)
441