00001 /* Grid_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 "Grid_Certificate.defs.hh" 00028 00029 #include "Grid.defs.hh" 00030 #include "assert.hh" 00031 #include <iostream> 00032 00033 namespace PPL = Parma_Polyhedra_Library; 00034 00035 PPL::Grid_Certificate::Grid_Certificate(const Grid& cgr) 00036 : num_equalities(0), num_proper_congruences(0) { 00037 Grid& gr = const_cast<Grid&>(cgr); 00038 // As in Polyhedron assume that gr contains at least one point. 00039 PPL_ASSERT(!gr.marked_empty()); 00040 if (gr.space_dimension() == 0) 00041 return; 00042 // One of the systems must be in minimal form. 00043 if (gr.congruences_are_up_to_date()) 00044 if (gr.congruences_are_minimized()) { 00045 num_proper_congruences = gr.con_sys.num_proper_congruences(); 00046 num_equalities = gr.con_sys.num_equalities(); 00047 } 00048 else 00049 if (gr.generators_are_up_to_date() && gr.generators_are_minimized()) { 00050 // Calculate number of congruences from generators. 00051 num_proper_congruences 00052 = gr.gen_sys.num_parameters() + 1 /* Integrality cg. */; 00053 num_equalities = gr.space_dimension() + 1 - gr.gen_sys.num_rows(); 00054 } 00055 else { 00056 // Minimize gr congruence system. As in Polyhedron assume 00057 // that gr contains at least one point. 00058 #ifndef NDEBUG 00059 Grid::simplify(gr.con_sys, gr.dim_kinds); 00060 #else 00061 bool contains_points = Grid::simplify(gr.con_sys, gr.dim_kinds); 00062 used(contains_points); // Quiet compiler warning. 00063 PPL_ASSERT(contains_points); 00064 #endif 00065 gr.set_congruences_minimized(); 00066 00067 num_proper_congruences = gr.con_sys.num_proper_congruences(); 00068 num_equalities = gr.con_sys.num_equalities(); 00069 } 00070 else { 00071 if (!gr.generators_are_minimized()) { 00072 // Minimize gr generator system. As in Polyhedron assume that 00073 // gr contains at least one point. 00074 Grid::simplify(gr.gen_sys, gr.dim_kinds); 00075 // If gen_sys contained rows before being reduced, it should 00076 // contain at least a single point afterward. 00077 PPL_ASSERT(!gr.gen_sys.empty()); 00078 gr.set_generators_minimized(); 00079 } 00080 // Calculate number of congruences from generators. 00081 num_proper_congruences 00082 = gr.gen_sys.num_parameters() + 1 /* Integrality cg. */; 00083 num_equalities 00084 = gr.space_dimension() + 1 - gr.gen_sys.num_rows(); 00085 } 00086 } 00087 00088 int 00089 PPL::Grid_Certificate::compare(const Grid_Certificate& y) const { 00090 PPL_ASSERT(OK() && y.OK()); 00091 if (num_equalities == y.num_equalities) { 00092 if (num_proper_congruences == y.num_proper_congruences) 00093 return 0; 00094 else 00095 return num_proper_congruences > y.num_proper_congruences ? 1 : -1; 00096 } 00097 return num_equalities > y.num_equalities ? 1 : -1; 00098 } 00099 00100 int 00101 PPL::Grid_Certificate::compare(const Grid& gr) const { 00102 Grid_Certificate gc(gr); 00103 return compare(gc); 00104 } 00105 00106 bool 00107 PPL::Grid_Certificate::OK() const { 00108 #ifndef NDEBUG 00109 using std::endl; 00110 using std::cerr; 00111 #endif 00112 00113 // All tests passed. 00114 return true; 00115 }
1.6.3