00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <config.h>
00024 #include "BD_Shape.defs.hh"
00025
00026 namespace PPL = Parma_Polyhedra_Library;
00027
00028 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00029
00030 #endif // PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00031 bool
00032 PPL::extract_bounded_difference(const Constraint& c,
00033 const dimension_type c_space_dim,
00034 dimension_type& c_num_vars,
00035 dimension_type& c_first_var,
00036 dimension_type& c_second_var,
00037 Coefficient& c_coeff) {
00038
00039 assert(c.space_dimension() == c_space_dim);
00040 assert(c_num_vars == 0 && c_first_var == 0 && c_second_var == 0);
00041
00042 dimension_type non_zero_index[2] = { 0, 0 };
00043
00044 for (dimension_type i = c_space_dim; i-- > 0; )
00045 if (c.coefficient(Variable(i)) != 0)
00046 if (c_num_vars <= 1)
00047 non_zero_index[c_num_vars++] = i + 1;
00048 else
00049
00050 return false;
00051
00052
00053
00054
00055
00056
00057 switch (c_num_vars) {
00058 case 2:
00059 {
00060 const Coefficient& c0 = c.coefficient(Variable(non_zero_index[0]-1));
00061 const Coefficient& c1 = c.coefficient(Variable(non_zero_index[1]-1));
00062 if (sgn(c0) == sgn(c1) || c0 != -c1)
00063
00064 return false;
00065 c_coeff = c1;
00066 }
00067 c_first_var = non_zero_index[0];
00068 c_second_var = non_zero_index[1];
00069 break;
00070 case 1:
00071 c_coeff = -c.coefficient(Variable(non_zero_index[0]-1));
00072 c_first_var = non_zero_index[0];
00073 break;
00074 default:
00075 assert(c_num_vars == 0);
00076 break;
00077 }
00078 return true;
00079 }
00080
00081 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00082
00083 #endif // PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00084 void
00085 PPL::compute_leader_indices(const std::vector<dimension_type>& predecessor,
00086 std::vector<dimension_type>& indices) {
00087
00088
00089
00090 assert(indices.size() == 0);
00091 assert(0 == predecessor[0]);
00092 indices.push_back(0);
00093 for (dimension_type i = 1, iend = predecessor.size(); i != iend; ++i)
00094 if (i == predecessor[i])
00095 indices.push_back(i);
00096 }