1 /* C_Polyhedron class implementation (non-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 #include "ppl-config.h"
25 #include "C_Polyhedron_defs.hh"
26 #include "NNC_Polyhedron_defs.hh"
27 #include "Grid_defs.hh"
28 #include "algorithms.hh"
29 
30 namespace PPL = Parma_Polyhedra_Library;
31 
C_Polyhedron(const NNC_Polyhedron & y,Complexity_Class)32 PPL::C_Polyhedron::C_Polyhedron(const NNC_Polyhedron& y, Complexity_Class)
33   : Polyhedron(NECESSARILY_CLOSED, y.space_dimension(), UNIVERSE) {
34   const Constraint_System& cs = y.constraints();
35   for (Constraint_System::const_iterator i = cs.begin(),
36          cs_end = cs.end(); i != cs_end; ++i) {
37     const Constraint& c = *i;
38     if (c.is_strict_inequality()) {
39       const Linear_Expression expr(c.expression());
40       add_constraint(expr >= 0);
41     }
42     else {
43       add_constraint(c);
44     }
45   }
46   PPL_ASSERT_HEAVY(OK());
47 }
48 
C_Polyhedron(const Congruence_System & cgs)49 PPL::C_Polyhedron::C_Polyhedron(const Congruence_System& cgs)
50   : Polyhedron(NECESSARILY_CLOSED,
51                check_space_dimension_overflow(cgs.space_dimension(),
52                                               NECESSARILY_CLOSED,
53                                               "C_Polyhedron(cgs)",
54                                               "the space dimension of cgs "
55                                               "exceeds the maximum allowed "
56                                               "space dimension"),
57                UNIVERSE) {
58   add_congruences(cgs);
59 }
60 
C_Polyhedron(Congruence_System & cgs,Recycle_Input)61 PPL::C_Polyhedron::C_Polyhedron(Congruence_System& cgs, Recycle_Input)
62   : Polyhedron(NECESSARILY_CLOSED,
63                check_space_dimension_overflow(cgs.space_dimension(),
64                                               NECESSARILY_CLOSED,
65                                               "C_Polyhedron(cgs, recycle)",
66                                               "the space dimension of cgs "
67                                               "exceeds the maximum allowed "
68                                               "space dimension"),
69                UNIVERSE) {
70   add_congruences(cgs);
71 }
72 
C_Polyhedron(const Grid & grid,Complexity_Class)73 PPL::C_Polyhedron::C_Polyhedron(const Grid& grid, Complexity_Class)
74   : Polyhedron(NECESSARILY_CLOSED,
75                check_space_dimension_overflow(grid.space_dimension(),
76                                               NECESSARILY_CLOSED,
77                                               "C_Polyhedron(grid)",
78                                               "the space dimension of grid "
79                                               "exceeds the maximum allowed "
80                                               "space dimension"),
81                UNIVERSE) {
82   add_constraints(grid.constraints());
83 }
84 
85 bool
poly_hull_assign_if_exact(const C_Polyhedron & y)86 PPL::C_Polyhedron::poly_hull_assign_if_exact(const C_Polyhedron& y) {
87   // Dimension-compatibility check.
88   if (space_dimension() != y.space_dimension()) {
89     throw_dimension_incompatible("poly_hull_assign_if_exact(y)", "y", y);
90   }
91 #define USE_BHZ09 0
92 #define USE_BFT00 1
93 #if USE_BHZ09 // [BagnaraHZ09]
94   return BHZ09_poly_hull_assign_if_exact(y);
95 #elif USE_BFT00 // [BemporadFT00TR].
96   return BFT00_poly_hull_assign_if_exact(y);
97 #else // Old implementation.
98   return PPL::poly_hull_assign_if_exact(*this, y);
99 #endif
100 #undef USE_BHZ09
101 #undef USE_BFT00
102 }
103 
104 
105 void
positive_time_elapse_assign(const Polyhedron & y)106 PPL::C_Polyhedron::positive_time_elapse_assign(const Polyhedron& y) {
107   NNC_Polyhedron nnc_this(*this);
108   nnc_this.positive_time_elapse_assign(y);
109   *this = nnc_this;
110 }
111 
112