00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <ppl-config.h>
00025
00026 #include "Polyhedron.defs.hh"
00027 #include <iostream>
00028 #include <string>
00029 #include "assert.hh"
00030
00031 namespace PPL = Parma_Polyhedra_Library;
00032
00033 namespace {
00034
00035
00036 const char* zero_dim_univ = "ZE";
00037 const char* empty = "EM";
00038 const char* consys_min = "CM";
00039 const char* gensys_min = "GM";
00040 const char* consys_upd = "CS";
00041 const char* gensys_upd = "GS";
00042 const char* satc_upd = "SC";
00043 const char* satg_upd = "SG";
00044 const char* consys_pending = "CP";
00045 const char* gensys_pending = "GP";
00046
00054 bool
00055 get_field(std::istream& s, const char* keyword, bool& positive) {
00056 std::string str;
00057 if (!(s >> str)
00058 || (str[0] != '+' && str[0] != '-')
00059 || str.substr(1) != keyword)
00060 return false;
00061 positive = (str[0] == '+');
00062 return true;
00063 }
00064
00065 }
00066
00067 void
00068 PPL::Polyhedron::Status::ascii_dump(std::ostream& s) const {
00069 s << (test_zero_dim_univ() ? '+' : '-') << zero_dim_univ << ' '
00070 << (test_empty() ? '+' : '-') << empty << ' '
00071 << ' '
00072 << (test_c_minimized() ? '+' : '-') << consys_min << ' '
00073 << (test_g_minimized() ? '+' : '-') << gensys_min << ' '
00074 << ' '
00075 << (test_c_up_to_date() ? '+' : '-') << consys_upd << ' '
00076 << (test_g_up_to_date() ? '+' : '-') << gensys_upd << ' '
00077 << ' '
00078 << (test_c_pending() ? '+' : '-') << consys_pending << ' '
00079 << (test_g_pending() ? '+' : '-') << gensys_pending << ' '
00080 << ' '
00081 << (test_sat_c_up_to_date() ? '+' : '-') << satc_upd << ' '
00082 << (test_sat_g_up_to_date() ? '+' : '-') << satg_upd << ' ';
00083 }
00084
00085 PPL_OUTPUT_DEFINITIONS_ASCII_ONLY(Polyhedron::Status)
00086
00087 bool
00088 PPL::Polyhedron::Status::ascii_load(std::istream& s) {
00089 PPL_UNINITIALIZED(bool, positive);
00090
00091 if (!get_field(s, zero_dim_univ, positive))
00092 return false;
00093 if (positive)
00094 set_zero_dim_univ();
00095
00096 if (!get_field(s, empty, positive))
00097 return false;
00098 if (positive)
00099 set_empty();
00100
00101 if (!get_field(s, consys_min, positive))
00102 return false;
00103 if (positive)
00104 set_c_minimized();
00105 else
00106 reset_c_minimized();
00107
00108 if (!get_field(s, gensys_min, positive))
00109 return false;
00110 if (positive)
00111 set_g_minimized();
00112 else
00113 reset_g_minimized();
00114
00115 if (!get_field(s, consys_upd, positive))
00116 return false;
00117 if (positive)
00118 set_c_up_to_date();
00119 else
00120 reset_c_up_to_date();
00121
00122 if (!get_field(s, gensys_upd, positive))
00123 return false;
00124 if (positive)
00125 set_g_up_to_date();
00126 else
00127 reset_g_up_to_date();
00128
00129 if (!get_field(s, consys_pending, positive))
00130 return false;
00131 if (positive)
00132 set_c_pending();
00133 else
00134 reset_c_pending();
00135
00136 if (!get_field(s, gensys_pending, positive))
00137 return false;
00138 if (positive)
00139 set_g_pending();
00140 else
00141 reset_g_pending();
00142
00143 if (!get_field(s, satc_upd, positive))
00144 return false;
00145 if (positive)
00146 set_sat_c_up_to_date();
00147 else
00148 reset_sat_c_up_to_date();
00149
00150 if (!get_field(s, satg_upd, positive))
00151 return false;
00152 if (positive)
00153 set_sat_g_up_to_date();
00154 else
00155 reset_sat_g_up_to_date();
00156
00157
00158 PPL_ASSERT(OK());
00159 return true;
00160 }
00161
00162 bool
00163 PPL::Polyhedron::Status::OK() const {
00164 #ifndef NDEBUG
00165 using std::endl;
00166 using std::cerr;
00167 #endif
00168
00169 if (test_zero_dim_univ())
00170
00171 return true;
00172
00173 if (test_empty()) {
00174 Status copy = *this;
00175 copy.reset_empty();
00176 if (copy.test_zero_dim_univ())
00177 return true;
00178 else {
00179 #ifndef NDEBUG
00180 cerr << "The empty flag is incompatible with any other one."
00181 << endl;
00182 #endif
00183 return false;
00184 }
00185 }
00186
00187 if ((test_sat_c_up_to_date() || test_sat_g_up_to_date())
00188 && !(test_c_up_to_date() && test_g_up_to_date())) {
00189 #ifndef NDEBUG
00190 cerr <<
00191 "If a saturation matrix is up-to-date, constraints and\n"
00192 "generators have to be both up-to-date."
00193 << endl;
00194 #endif
00195 return false;
00196 }
00197
00198 if (test_c_minimized() && !test_c_up_to_date()) {
00199 #ifndef NDEBUG
00200 cerr << "If constraints are minimized they must be up-to-date."
00201 << endl;
00202 #endif
00203 return false;
00204 }
00205
00206 if (test_g_minimized() && !test_g_up_to_date()) {
00207 #ifndef NDEBUG
00208 cerr << "If generators are minimized they must be up-to-date."
00209 << endl;
00210 #endif
00211 return false;
00212 }
00213
00214 if (test_c_pending() && test_g_pending()) {
00215 #ifndef NDEBUG
00216 cerr << "There cannot be both pending constraints and pending generators."
00217 << endl;
00218 #endif
00219 return false;
00220 }
00221
00222 if (test_c_pending() || test_g_pending()) {
00223 if (!test_c_minimized() || !test_g_minimized()) {
00224 #ifndef NDEBUG
00225 cerr <<
00226 "If there are pending constraints or generators, constraints\n"
00227 "and generators must be minimized."
00228 << endl;
00229 #endif
00230 return false;
00231 }
00232
00233 if (!test_sat_c_up_to_date() && !test_sat_g_up_to_date()) {
00234 #ifndef NDEBUG
00235 cerr <<
00236 "If there are pending constraints or generators, there must\n"
00237 "be at least a saturation matrix up-to-date."
00238 << endl;
00239 #endif
00240 return false;
00241 }
00242 }
00243
00244
00245 return true;
00246 }