00001 /* H79_Certificate class implementation 00002 (non-inline member functions). 00003 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it> 00004 Copyright (C) 2010-2011 BUGSENG srl (http://bugseng.com) 00005 00006 This file is part of the Parma Polyhedra Library (PPL). 00007 00008 The PPL is free software; you can redistribute it and/or modify it 00009 under the terms of the GNU General Public License as published by the 00010 Free Software Foundation; either version 3 of the License, or (at your 00011 option) any later version. 00012 00013 The PPL is distributed in the hope that it will be useful, but WITHOUT 00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00015 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00016 for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software Foundation, 00020 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. 00021 00022 For the most up-to-date information see the Parma Polyhedra Library 00023 site: http://www.cs.unipr.it/ppl/ . */ 00024 00025 #include <ppl-config.h> 00026 00027 #include "H79_Certificate.defs.hh" 00028 00029 #include "Polyhedron.defs.hh" 00030 #include "assert.hh" 00031 #include <iostream> 00032 00033 namespace PPL = Parma_Polyhedra_Library; 00034 00035 PPL::H79_Certificate::H79_Certificate(const Polyhedron& ph) 00036 : affine_dim(0), num_constraints(0) { 00037 // The affine dimension of the polyhedron is obtained by subtracting 00038 // the number of equalities from the space dimension. 00039 // When counting constraints, for a correct reasoning, we have 00040 // to disregard the low-level constraints (i.e., the positivity 00041 // constraint and epsilon bounds). 00042 const dimension_type space_dim = ph.space_dimension(); 00043 affine_dim = space_dim; 00044 const Constraint_System& cs = ph.minimized_constraints(); 00045 // It is assumed that `ph' is not an empty polyhedron. 00046 PPL_ASSERT(!ph.marked_empty()); 00047 for (Constraint_System::const_iterator i = cs.begin(), 00048 cs_end = cs.end(); i != cs_end; ++i) { 00049 ++num_constraints; 00050 if (i->is_equality()) 00051 --affine_dim; 00052 } 00053 00054 // TODO: this is an inefficient workaround. 00055 // For NNC polyhedra, generators might be no longer up-to-date 00056 // (and hence, neither minimized) due to the strong minimization 00057 // process applied to constraints when constructing the certificate. 00058 // We have to reinforce the (normal) minimization of the generator 00059 // system. The future, lazy implementation of the strong minimization 00060 // process will solve this problem. 00061 if (!ph.is_necessarily_closed()) 00062 ph.minimize(); 00063 } 00064 00065 int 00066 PPL::H79_Certificate::compare(const H79_Certificate& y) const { 00067 if (affine_dim != y.affine_dim) 00068 return affine_dim > y.affine_dim ? 1 : -1; 00069 if (num_constraints != y.num_constraints) 00070 return num_constraints > y.num_constraints ? 1 : -1; 00071 // All components are equal. 00072 return 0; 00073 } 00074 00075 int 00076 PPL::H79_Certificate::compare(const Polyhedron& ph) const { 00077 // The affine dimension of the polyhedron is obtained by subtracting 00078 // the number of equalities from the space dimension. 00079 // When counting constraints, for a correct reasoning, we have 00080 // to disregard the low-level constraints (i.e., the positivity 00081 // constraint and epsilon bounds). 00082 const dimension_type space_dim = ph.space_dimension(); 00083 dimension_type ph_affine_dim = space_dim; 00084 dimension_type ph_num_constraints = 0; 00085 const Constraint_System& cs = ph.minimized_constraints(); 00086 // It is assumed that `ph' is a polyhedron containing the 00087 // polyhedron described by `*this': hence, it cannot be empty. 00088 PPL_ASSERT(!ph.marked_empty()); 00089 for (Constraint_System::const_iterator i = cs.begin(), 00090 cs_end = cs.end(); i != cs_end; ++i) { 00091 ++ph_num_constraints; 00092 if (i->is_equality()) 00093 --ph_affine_dim; 00094 } 00095 // TODO: this is an inefficient workaround. 00096 // For NNC polyhedra, generators might be no longer up-to-date 00097 // (and hence, neither minimized) due to the strong minimization 00098 // process applied to constraints when constructing the certificate. 00099 // We have to reinforce the (normal) minimization of the generator 00100 // system. The future, lazy implementation of the strong minimization 00101 // process will solve this problem. 00102 if (!ph.is_necessarily_closed()) 00103 ph.minimize(); 00104 00105 // If the affine dimension of `ph' is increasing, the chain is stabilizing. 00106 if (ph_affine_dim > affine_dim) 00107 return 1; 00108 00109 // At this point the two polyhedra must have the same affine dimension. 00110 PPL_ASSERT(ph_affine_dim == affine_dim); 00111 00112 // If the number of constraints of `ph' is decreasing, then the chain 00113 // is stabilizing. If it is increasing, the chain is not stabilizing. 00114 if (ph_num_constraints != num_constraints) 00115 return ph_num_constraints < num_constraints ? 1 : -1; 00116 00117 // All components are equal. 00118 return 0; 00119 } 00120
1.6.3