PPL  0.12.1
H79_Certificate.cc
Go to the documentation of this file.
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-2012 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://bugseng.com/products/ppl/ . */
00024 
00025 #include "ppl-config.h"
00026 #include "H79_Certificate.defs.hh"
00027 #include "Polyhedron.defs.hh"
00028 #include "assert.hh"
00029 #include <iostream>
00030 
00031 namespace PPL = Parma_Polyhedra_Library;
00032 
00033 PPL::H79_Certificate::H79_Certificate(const Polyhedron& ph)
00034   : affine_dim(0), num_constraints(0) {
00035   // The affine dimension of the polyhedron is obtained by subtracting
00036   // the number of equalities from the space dimension.
00037   // When counting constraints, for a correct reasoning, we have
00038   // to disregard the low-level constraints (i.e., the positivity
00039   // constraint and epsilon bounds).
00040   const dimension_type space_dim = ph.space_dimension();
00041   affine_dim = space_dim;
00042   const Constraint_System& cs = ph.minimized_constraints();
00043   // It is assumed that `ph' is not an empty polyhedron.
00044   PPL_ASSERT(!ph.marked_empty());
00045   for (Constraint_System::const_iterator i = cs.begin(),
00046          cs_end = cs.end(); i != cs_end; ++i) {
00047     ++num_constraints;
00048     if (i->is_equality())
00049       --affine_dim;
00050   }
00051 
00052   // TODO: this is an inefficient workaround.
00053   // For NNC polyhedra, generators might be no longer up-to-date
00054   // (and hence, neither minimized) due to the strong minimization
00055   // process applied to constraints when constructing the certificate.
00056   // We have to reinforce the (normal) minimization of the generator
00057   // system. The future, lazy implementation of the strong minimization
00058   // process will solve this problem.
00059   if (!ph.is_necessarily_closed())
00060     ph.minimize();
00061 }
00062 
00063 int
00064 PPL::H79_Certificate::compare(const H79_Certificate& y) const {
00065   if (affine_dim != y.affine_dim)
00066     return (affine_dim > y.affine_dim) ? 1 : -1;
00067   if (num_constraints != y.num_constraints)
00068     return (num_constraints > y.num_constraints) ? 1 : -1;
00069   // All components are equal.
00070   return 0;
00071 }
00072 
00073 int
00074 PPL::H79_Certificate::compare(const Polyhedron& ph) const {
00075   // The affine dimension of the polyhedron is obtained by subtracting
00076   // the number of equalities from the space dimension.
00077   // When counting constraints, for a correct reasoning, we have
00078   // to disregard the low-level constraints (i.e., the positivity
00079   // constraint and epsilon bounds).
00080   const dimension_type space_dim = ph.space_dimension();
00081   dimension_type ph_affine_dim = space_dim;
00082   dimension_type ph_num_constraints = 0;
00083   const Constraint_System& cs = ph.minimized_constraints();
00084   // It is assumed that `ph' is a polyhedron containing the
00085   // polyhedron described by `*this': hence, it cannot be empty.
00086   PPL_ASSERT(!ph.marked_empty());
00087   for (Constraint_System::const_iterator i = cs.begin(),
00088          cs_end = cs.end(); i != cs_end; ++i) {
00089     ++ph_num_constraints;
00090     if (i->is_equality())
00091       --ph_affine_dim;
00092   }
00093   // TODO: this is an inefficient workaround.
00094   // For NNC polyhedra, generators might be no longer up-to-date
00095   // (and hence, neither minimized) due to the strong minimization
00096   // process applied to constraints when constructing the certificate.
00097   // We have to reinforce the (normal) minimization of the generator
00098   // system. The future, lazy implementation of the strong minimization
00099   // process will solve this problem.
00100   if (!ph.is_necessarily_closed())
00101     ph.minimize();
00102 
00103   // If the affine dimension of `ph' is increasing, the chain is stabilizing.
00104   if (ph_affine_dim > affine_dim)
00105     return 1;
00106 
00107   // At this point the two polyhedra must have the same affine dimension.
00108   PPL_ASSERT(ph_affine_dim == affine_dim);
00109 
00110   // If the number of constraints of `ph' is decreasing, then the chain
00111   // is stabilizing. If it is increasing, the chain is not stabilizing.
00112   if (ph_num_constraints != num_constraints)
00113     return (ph_num_constraints < num_constraints) ? 1 : -1;
00114 
00115   // All components are equal.
00116   return 0;
00117 }
00118