1 /* Generator_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_Generator_System_inlines_hh
25 #define PPL_Generator_System_inlines_hh 1
26 
27 #include "Generator_defs.hh"
28 
29 namespace Parma_Polyhedra_Library {
30 
31 inline
Generator_System(Representation r)32 Generator_System::Generator_System(Representation r)
33   : sys(NECESSARILY_CLOSED, r) {
34 }
35 
36 inline
Generator_System(const Generator & g,Representation r)37 Generator_System::Generator_System(const Generator& g, Representation r)
38   : sys(g.topology(), r) {
39   sys.insert(g);
40 }
41 
42 inline
Generator_System(const Generator_System & gs)43 Generator_System::Generator_System(const Generator_System& gs)
44   : sys(gs.sys) {
45 }
46 
47 inline
Generator_System(const Generator_System & gs,Representation r)48 Generator_System::Generator_System(const Generator_System& gs,
49                                    Representation r)
50   : sys(gs.sys, r) {
51 }
52 
53 inline
Generator_System(const Topology topol,Representation r)54 Generator_System::Generator_System(const Topology topol, Representation r)
55   : sys(topol, r) {
56 }
57 
58 inline
Generator_System(const Topology topol,const dimension_type space_dim,Representation r)59 Generator_System::Generator_System(const Topology topol,
60                                    const dimension_type space_dim,
61                                    Representation r)
62   : sys(topol, space_dim, r) {
63 }
64 
65 inline
~Generator_System()66 Generator_System::~Generator_System() {
67 }
68 
69 inline Generator_System&
operator =(const Generator_System & y)70 Generator_System::operator=(const Generator_System& y) {
71   Generator_System tmp = y;
72   swap(*this, tmp);
73   return *this;
74 }
75 
76 inline Representation
representation() const77 Generator_System::representation() const {
78   return sys.representation();
79 }
80 
81 inline void
set_representation(Representation r)82 Generator_System::set_representation(Representation r) {
83   sys.set_representation(r);
84 }
85 
86 inline dimension_type
max_space_dimension()87 Generator_System::max_space_dimension() {
88   return Linear_System<Generator>::max_space_dimension();
89 }
90 
91 inline dimension_type
space_dimension() const92 Generator_System::space_dimension() const {
93   return sys.space_dimension();
94 }
95 
96 inline void
set_space_dimension(dimension_type space_dim)97 Generator_System::set_space_dimension(dimension_type space_dim) {
98   const dimension_type old_space_dim = space_dimension();
99   sys.set_space_dimension_no_ok(space_dim);
100 
101   if (space_dim < old_space_dim) {
102     // We may have invalid lines and rays now.
103     remove_invalid_lines_and_rays();
104   }
105 
106 #ifndef NDEBUG
107   for (dimension_type i = 0; i < sys.num_rows(); ++i) {
108     PPL_ASSERT(sys[i].OK());
109   }
110 #endif
111   PPL_ASSERT(sys.OK());
112   PPL_ASSERT(OK());
113 }
114 
115 inline void
clear()116 Generator_System::clear() {
117   sys.clear();
118 }
119 
120 inline const Generator&
operator [](const dimension_type k) const121 Generator_System::operator[](const dimension_type k) const {
122   return sys[k];
123 }
124 
125 inline void
126 Generator_System
remove_space_dimensions(const Variables_Set & vars)127 ::remove_space_dimensions(const Variables_Set& vars) {
128   sys.remove_space_dimensions(vars);
129 }
130 
131 inline void
132 Generator_System
shift_space_dimensions(Variable v,dimension_type n)133 ::shift_space_dimensions(Variable v, dimension_type n) {
134   sys.shift_space_dimensions(v, n);
135 }
136 
137 inline void
138 Generator_System
permute_space_dimensions(const std::vector<Variable> & cycle)139 ::permute_space_dimensions(const std::vector<Variable>& cycle) {
140   sys.permute_space_dimensions(cycle);
141 }
142 
143 inline void
144 Generator_System
swap_space_dimensions(Variable v1,Variable v2)145 ::swap_space_dimensions(Variable v1, Variable v2) {
146   sys.swap_space_dimensions(v1, v2);
147 }
148 
149 inline dimension_type
num_rows() const150 Generator_System::num_rows() const {
151   return sys.num_rows();
152 }
153 
154 inline void
add_universe_rows_and_space_dimensions(dimension_type n)155 Generator_System::add_universe_rows_and_space_dimensions(dimension_type n) {
156   sys.add_universe_rows_and_space_dimensions(n);
157 }
158 
159 inline Topology
topology() const160 Generator_System::topology() const {
161   return sys.topology();
162 }
163 
164 inline dimension_type
first_pending_row() const165 Generator_System::first_pending_row() const {
166   return sys.first_pending_row();
167 }
168 
169 inline void
unset_pending_rows()170 Generator_System::unset_pending_rows() {
171   sys.unset_pending_rows();
172 }
173 
174 inline void
set_sorted(bool b)175 Generator_System::set_sorted(bool b) {
176   sys.set_sorted(b);
177 }
178 
179 inline bool
is_sorted() const180 Generator_System::is_sorted() const {
181   return sys.is_sorted();
182 }
183 
184 inline void
set_index_first_pending_row(dimension_type i)185 Generator_System::set_index_first_pending_row(dimension_type i) {
186   sys.set_index_first_pending_row(i);
187 }
188 
189 inline bool
is_necessarily_closed() const190 Generator_System::is_necessarily_closed() const {
191   return sys.is_necessarily_closed();
192 }
193 
194 inline void
assign_with_pending(const Generator_System & y)195 Generator_System::assign_with_pending(const Generator_System& y) {
196   sys.assign_with_pending(y.sys);
197 }
198 
199 inline dimension_type
num_pending_rows() const200 Generator_System::num_pending_rows() const {
201   return sys.num_pending_rows();
202 }
203 
204 inline void
sort_pending_and_remove_duplicates()205 Generator_System::sort_pending_and_remove_duplicates() {
206   return sys.sort_pending_and_remove_duplicates();
207 }
208 
209 inline void
sort_and_remove_with_sat(Bit_Matrix & sat)210 Generator_System::sort_and_remove_with_sat(Bit_Matrix& sat) {
211   sys.sort_and_remove_with_sat(sat);
212 }
213 
214 inline void
sort_rows()215 Generator_System::sort_rows() {
216   sys.sort_rows();
217 }
218 
219 inline bool
check_sorted() const220 Generator_System::check_sorted() const {
221   return sys.check_sorted();
222 }
223 
224 inline dimension_type
num_lines_or_equalities() const225 Generator_System::num_lines_or_equalities() const {
226   return sys.num_lines_or_equalities();
227 }
228 
229 inline void
remove_row(dimension_type i,bool keep_sorted)230 Generator_System::remove_row(dimension_type i, bool keep_sorted) {
231   sys.remove_row(i, keep_sorted);
232 }
233 
234 inline void
remove_rows(dimension_type first,dimension_type last,bool keep_sorted)235 Generator_System::remove_rows(dimension_type first, dimension_type last,
236                               bool keep_sorted) {
237   sys.remove_rows(first, last, keep_sorted);
238 }
239 
240 inline void
remove_rows(const std::vector<dimension_type> & indexes)241 Generator_System::remove_rows(const std::vector<dimension_type>& indexes) {
242   sys.remove_rows(indexes);
243 }
244 
245 inline void
remove_trailing_rows(dimension_type n)246 Generator_System::remove_trailing_rows(dimension_type n) {
247   sys.remove_trailing_rows(n);
248 }
249 
250 inline dimension_type
gauss(dimension_type n_lines_or_equalities)251 Generator_System::gauss(dimension_type n_lines_or_equalities) {
252   return sys.gauss(n_lines_or_equalities);
253 }
254 
255 inline void
back_substitute(dimension_type n_lines_or_equalities)256 Generator_System::back_substitute(dimension_type n_lines_or_equalities) {
257   sys.back_substitute(n_lines_or_equalities);
258 }
259 
260 inline void
strong_normalize()261 Generator_System::strong_normalize() {
262   sys.strong_normalize();
263 }
264 
265 inline void
merge_rows_assign(const Generator_System & y)266 Generator_System::merge_rows_assign(const Generator_System& y) {
267   sys.merge_rows_assign(y.sys);
268 }
269 
270 inline void
insert(const Generator_System & y)271 Generator_System::insert(const Generator_System& y) {
272   sys.insert(y.sys);
273 }
274 
275 inline void
insert_pending(const Generator_System & r)276 Generator_System::insert_pending(const Generator_System& r) {
277   sys.insert_pending(r.sys);
278 }
279 
280 inline bool
operator ==(const Generator_System & x,const Generator_System & y)281 operator==(const Generator_System& x, const Generator_System& y) {
282   return x.sys == y.sys;
283 }
284 
285 inline bool
operator !=(const Generator_System & x,const Generator_System & y)286 operator!=(const Generator_System& x, const Generator_System& y) {
287   return !(x == y);
288 }
289 
290 inline
Generator_System_const_iterator()291 Generator_System_const_iterator::Generator_System_const_iterator()
292   : i(), gsp(0) {
293 }
294 
295 inline
Generator_System_const_iterator(const Generator_System_const_iterator & y)296 Generator_System_const_iterator::Generator_System_const_iterator(const Generator_System_const_iterator& y)
297   : i(y.i), gsp(y.gsp) {
298 }
299 
300 inline
~Generator_System_const_iterator()301 Generator_System_const_iterator::~Generator_System_const_iterator() {
302 }
303 
304 inline
305 Generator_System_const_iterator&
operator =(const Generator_System_const_iterator & y)306 Generator_System_const_iterator::operator=(const Generator_System_const_iterator& y) {
307   i = y.i;
308   gsp = y.gsp;
309   return *this;
310 }
311 
312 inline const Generator&
operator *() const313 Generator_System_const_iterator::operator*() const {
314   return *i;
315 }
316 
317 inline const Generator*
operator ->() const318 Generator_System_const_iterator::operator->() const {
319   return i.operator->();
320 }
321 
322 inline Generator_System_const_iterator&
operator ++()323 Generator_System_const_iterator::operator++() {
324   ++i;
325   if (!gsp->is_necessarily_closed()) {
326     skip_forward();
327   }
328   return *this;
329 }
330 
331 inline Generator_System_const_iterator
operator ++(int)332 Generator_System_const_iterator::operator++(int) {
333   const Generator_System_const_iterator tmp = *this;
334   operator++();
335   return tmp;
336 }
337 
338 inline bool
operator ==(const Generator_System_const_iterator & y) const339 Generator_System_const_iterator::operator==(const Generator_System_const_iterator& y) const {
340   return i == y.i;
341 }
342 
343 inline bool
operator !=(const Generator_System_const_iterator & y) const344 Generator_System_const_iterator::operator!=(const Generator_System_const_iterator& y) const {
345   return i != y.i;
346 }
347 
348 inline
349 Generator_System_const_iterator::
Generator_System_const_iterator(const Linear_System<Generator>::const_iterator & iter,const Generator_System & gs)350 Generator_System_const_iterator(const Linear_System<Generator>::const_iterator& iter,
351                                 const Generator_System& gs)
352   : i(iter), gsp(&gs.sys) {
353 }
354 
355 inline bool
empty() const356 Generator_System::empty() const {
357   return sys.has_no_rows();
358 }
359 
360 inline bool
has_no_rows() const361 Generator_System::has_no_rows() const {
362   return sys.has_no_rows();
363 }
364 
365 inline Generator_System::const_iterator
begin() const366 Generator_System::begin() const {
367   const_iterator i(sys.begin(), *this);
368   if (!sys.is_necessarily_closed()) {
369     i.skip_forward();
370   }
371   return i;
372 }
373 
374 inline Generator_System::const_iterator
end() const375 Generator_System::end() const {
376   const const_iterator i(sys.end(), *this);
377   return i;
378 }
379 
380 inline const Generator_System&
zero_dim_univ()381 Generator_System::zero_dim_univ() {
382   PPL_ASSERT(zero_dim_univ_p != 0);
383   return *zero_dim_univ_p;
384 }
385 
386 inline void
m_swap(Generator_System & y)387 Generator_System::m_swap(Generator_System& y) {
388   swap(sys, y.sys);
389 }
390 
391 inline memory_size_type
external_memory_in_bytes() const392 Generator_System::external_memory_in_bytes() const {
393   return sys.external_memory_in_bytes();
394 }
395 
396 inline memory_size_type
total_memory_in_bytes() const397 Generator_System::total_memory_in_bytes() const {
398   return external_memory_in_bytes() + sizeof(*this);
399 }
400 
401 inline void
simplify()402 Generator_System::simplify() {
403   sys.simplify();
404   remove_invalid_lines_and_rays();
405 }
406 
407 /*! \relates Generator_System */
408 inline void
swap(Generator_System & x,Generator_System & y)409 swap(Generator_System& x, Generator_System& y) {
410   x.m_swap(y);
411 }
412 
413 } // namespace Parma_Polyhedra_Library
414 
415 #endif // !defined(PPL_Generator_System_inlines_hh)
416