PPL  1.2
Parma_Polyhedra_Library::PIP_Solution_Node::Tableau Struct Reference

The type for parametric simplex tableau. More...

Public Member Functions

 Tableau ()
 Default constructor. More...
 
 Tableau (const Tableau &y)
 Copy constructor. More...
 
 ~Tableau ()
 Destructor. More...
 
bool is_integer () const
 Tests whether the matrix is integer, i.e., the denominator is 1. More...
 
void scale (Coefficient_traits::const_reference ratio)
 Multiplies all coefficients and denominator with ratio. More...
 
void normalize ()
 Normalizes the modulo of coefficients so that they are mutually prime. More...
 
bool is_better_pivot (const std::vector< dimension_type > &mapping, const std::vector< bool > &basis, const dimension_type row_0, const dimension_type col_0, const dimension_type row_1, const dimension_type col_1) const
 Compares two pivot row and column pairs before pivoting. More...
 
Coefficient_traits::const_reference denominator () const
 Returns the value of the denominator. More...
 
void ascii_dump (std::ostream &os) const
 Dumps to os an ASCII representation of *this. More...
 
bool ascii_load (std::istream &is)
 Loads from is an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this accordingly. Returns true if successful, false otherwise. More...
 
memory_size_type external_memory_in_bytes () const
 Returns the size in bytes of the memory managed by *this. More...
 
bool OK () const
 Returns true if and only if *this is well formed. More...
 

Public Attributes

Matrix< Rows
 The matrix of simplex coefficients. More...
 
Matrix< Rowt
 The matrix of parameter coefficients. More...
 
Coefficient denom
 A common denominator for all matrix elements. More...
 

Detailed Description

The type for parametric simplex tableau.

Definition at line 413 of file PIP_Tree_defs.hh.

Constructor & Destructor Documentation

Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::Tableau ( )
inline

Default constructor.

Definition at line 30 of file PIP_Tree_inlines.hh.

References OK().

31  : s(), t(), denom(1) {
32  PPL_ASSERT(OK());
33 }
bool OK() const
Returns true if and only if *this is well formed.
Definition: PIP_Tree.cc:1168
Matrix< Row > t
The matrix of parameter coefficients.
Coefficient denom
A common denominator for all matrix elements.
Matrix< Row > s
The matrix of simplex coefficients.
Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::Tableau ( const Tableau y)
inline

Copy constructor.

Definition at line 36 of file PIP_Tree_inlines.hh.

References OK().

37  : s(y.s), t(y.t), denom(y.denom) {
38  PPL_ASSERT(OK());
39 }
bool OK() const
Returns true if and only if *this is well formed.
Definition: PIP_Tree.cc:1168
Matrix< Row > t
The matrix of parameter coefficients.
Coefficient denom
A common denominator for all matrix elements.
Matrix< Row > s
The matrix of simplex coefficients.
Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::~Tableau ( )
inline

Destructor.

Definition at line 42 of file PIP_Tree_inlines.hh.

42  {
43 }

Member Function Documentation

void Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::ascii_dump ( std::ostream &  os) const

Dumps to os an ASCII representation of *this.

Definition at line 1873 of file PIP_Tree.cc.

1873  {
1874  os << "denominator " << denom << "\n";
1875  os << "variables ";
1876  s.ascii_dump(os);
1877  os << "parameters ";
1878  t.ascii_dump(os);
1879 }
Matrix< Row > t
The matrix of parameter coefficients.
Coefficient denom
A common denominator for all matrix elements.
Matrix< Row > s
The matrix of simplex coefficients.
bool Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::ascii_load ( std::istream &  is)

Loads from is an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this accordingly. Returns true if successful, false otherwise.

Definition at line 1882 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Solution_Node::OK().

1882  {
1883  std::string str;
1884  if (!(is >> str) || str != "denominator") {
1885  return false;
1886  }
1887  Coefficient d;
1888  if (!(is >> d)) {
1889  return false;
1890  }
1891  denom = d;
1892  if (!(is >> str) || str != "variables") {
1893  return false;
1894  }
1895  if (!s.ascii_load(is)) {
1896  return false;
1897  }
1898  if (!(is >> str) || str != "parameters") {
1899  return false;
1900  }
1901  if (!t.ascii_load(is)) {
1902  return false;
1903  }
1904  PPL_ASSERT(OK());
1905  return true;
1906 }
bool OK() const
Returns true if and only if *this is well formed.
Definition: PIP_Tree.cc:1168
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
Matrix< Row > t
The matrix of parameter coefficients.
Coefficient denom
A common denominator for all matrix elements.
Matrix< Row > s
The matrix of simplex coefficients.
Coefficient_traits::const_reference Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::denominator ( ) const
inline

Returns the value of the denominator.

Definition at line 51 of file PIP_Tree_inlines.hh.

51  {
52  return denom;
53 }
Coefficient denom
A common denominator for all matrix elements.
memory_size_type Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::external_memory_in_bytes ( ) const

Returns the size in bytes of the memory managed by *this.

Note
No need for a total_memory_in_bytes() method, since class Tableau is a private inner class of PIP_Solution_Node.

Definition at line 3771 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::external_memory_in_bytes().

3771  {
3773  + s.external_memory_in_bytes()
3774  + t.external_memory_in_bytes();
3775 }
Enable_If< Is_Native< T >::value, memory_size_type >::type external_memory_in_bytes(const T &)
For native types, returns the size in bytes of the memory managed by the type of the (unused) paramet...
Matrix< Row > t
The matrix of parameter coefficients.
Coefficient denom
A common denominator for all matrix elements.
Matrix< Row > s
The matrix of simplex coefficients.
bool Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::is_better_pivot ( const std::vector< dimension_type > &  mapping,
const std::vector< bool > &  basis,
const dimension_type  row_0,
const dimension_type  col_0,
const dimension_type  row_1,
const dimension_type  col_1 
) const

Compares two pivot row and column pairs before pivoting.

The algorithm searches the first (ie, leftmost) column $k$ in parameter matrix for which the $c=s_{*j}\frac{t_{ik}}{s_{ij}}$ and $c'=s_{*j'}\frac{t_{i'k}}{s_{i'j'}}$ columns are different, where $s_{*j}$ denotes the $j$th column from the $s$ matrix and $s_{*j'}$ is the $j'$th column of $s$.

$c$ is the computed column that would be subtracted to column $k$ in parameter matrix if pivoting is done using the $(i,j)$ row and column pair. $c'$ is the computed column that would be subtracted to column $k$ in parameter matrix if pivoting is done using the $(i',j')$ row and column pair.

The test is true if the computed $-c$ column is lexicographically bigger than the $-c'$ column. Due to the column ordering in the parameter matrix of the tableau, leftmost search will enforce solution increase with respect to the following priority order:

  • the constant term
  • the coefficients for the original parameters
  • the coefficients for the oldest artificial parameters.
Returns
true if pivot row and column pair $(i,j)$ is more suitable for pivoting than the $(i',j')$ pair
Parameters
mappingThe PIP_Solution_Node::mapping vector for the tableau.
basisThe PIP_Solution_Node::basis vector for the tableau.
row_0The row number for the first pivot row and column pair to be compared.
col_0The column number for the first pivot row and column pair to be compared.
row_1The row number for the second pivot row and column pair to be compared.
col_1The column number for the second pivot row and column pair to be compared.

Definition at line 1733 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::Sparse_Row::begin(), Parma_Polyhedra_Library::Sparse_Row::end(), Parma_Polyhedra_Library::Sparse_Row::get(), Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), PPL_DIRTY_TEMP_COEFFICIENT, WEIGHT_ADD, and WEIGHT_BEGIN.

1738  {
1739  const dimension_type num_params = t.num_columns();
1740  const dimension_type num_rows = s.num_rows();
1741  const Row& s_0 = s[row_0];
1742  const Row& s_1 = s[row_1];
1743  Coefficient_traits::const_reference s_0_0 = s_0.get(col_0);
1744  Coefficient_traits::const_reference s_1_1 = s_1.get(col_1);
1745  const Row& t_0 = t[row_0];
1746  const Row& t_1 = t[row_1];
1747  PPL_DIRTY_TEMP_COEFFICIENT(product_0);
1748  PPL_DIRTY_TEMP_COEFFICIENT(product_1);
1749  WEIGHT_BEGIN();
1750  // On exit from the loop, if j_mismatch == num_params then
1751  // no column mismatch was found.
1752  dimension_type j_mismatch = num_params;
1753  Row::const_iterator j0 = t_0.end();
1754  Row::const_iterator j0_end = t_0.end();
1755  Row::const_iterator j1 = t_1.end();
1756  Row::const_iterator j1_end = t_1.end();
1757  for (dimension_type i = 0; i < num_rows; ++i) {
1758  const Row& s_i = s[i];
1759  Coefficient_traits::const_reference s_i_col_0 = s_i.get(col_0);
1760  Coefficient_traits::const_reference s_i_col_1 = s_i.get(col_1);
1761  j0 = t_0.begin();
1762  j1 = t_1.begin();
1763  while (j0 != j0_end && j1 != j1_end) {
1764  if (j0.index() == j1.index()) {
1765  WEIGHT_ADD(1361);
1766  product_0 = (*j0) * s_1_1 * s_i_col_0;
1767  product_1 = (*j1) * s_0_0 * s_i_col_1;
1768  if (product_0 != product_1) {
1769  // Mismatch found: exit from both loops.
1770  j_mismatch = j0.index();
1771  goto end_loop;
1772  }
1773  ++j0;
1774  ++j1;
1775  }
1776  else
1777  if (j0.index() < j1.index()) {
1778  if (*j0 != 0 && s_1_1 != 0 && s_i_col_0 != 0) {
1779  // Mismatch found: exit from both loops.
1780  j_mismatch = j0.index();
1781  goto end_loop;
1782  }
1783  ++j0;
1784  }
1785  else {
1786  PPL_ASSERT(j0.index() > j1.index());
1787  if (*j1 != 0 && s_0_0 != 0 && s_i_col_1 != 0) {
1788  // Mismatch found: exit from both loops.
1789  j_mismatch = j1.index();
1790  goto end_loop;
1791  }
1792  ++j1;
1793  }
1794  }
1795  while (j0 != j0_end) {
1796  if (*j0 != 0 && s_1_1 != 0 && s_i_col_0 != 0) {
1797  // Mismatch found: exit from both loops.
1798  j_mismatch = j0.index();
1799  goto end_loop;
1800  }
1801  ++j0;
1802  }
1803  while (j1 != j1_end) {
1804  if (*j1 != 0 && s_0_0 != 0 && s_i_col_1 != 0) {
1805  // Mismatch found: exit from both loops.
1806  j_mismatch = j1.index();
1807  goto end_loop;
1808  }
1809  }
1810  }
1811 
1812  end_loop:
1813  return (j_mismatch != num_params)
1814  && column_lower(s, mapping, basis, s_0, col_0, s_1, col_1, *j0, *j1);
1815 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
#define WEIGHT_ADD(delta)
Definition: globals_defs.hh:83
std::vector< dimension_type > mapping
A mapping between the tableau rows/columns and the original variables.
#define WEIGHT_BEGIN()
Definition: globals_defs.hh:81
std::vector< bool > basis
A boolean vector for identifying the basic variables.
Matrix< Row > t
The matrix of parameter coefficients.
Matrix< Row > s
The matrix of simplex coefficients.
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
bool Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::is_integer ( ) const
inline

Tests whether the matrix is integer, i.e., the denominator is 1.

Definition at line 46 of file PIP_Tree_inlines.hh.

46  {
47  return denom == 1;
48 }
Coefficient denom
A common denominator for all matrix elements.
void Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::normalize ( )

Normalizes the modulo of coefficients so that they are mutually prime.

Computes the Greatest Common Divisor (GCD) among the elements of the matrices and normalizes them and the denominator by the GCD itself.

Definition at line 1654 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::Sparse_Row::begin(), Parma_Polyhedra_Library::Sparse_Row::end(), Parma_Polyhedra_Library::exact_div_assign(), Parma_Polyhedra_Library::gcd_assign(), PPL_DIRTY_TEMP_COEFFICIENT, WEIGHT_ADD, and WEIGHT_BEGIN.

1654  {
1655  if (denom == 1) {
1656  return;
1657  }
1658 
1659  const dimension_type num_rows = s.num_rows();
1660 
1661  // Compute global gcd.
1663  gcd = denom;
1664  for (dimension_type i = num_rows; i-- > 0; ) {
1665  WEIGHT_BEGIN();
1666  const Row& s_i = s[i];
1667  for (Row::const_iterator
1668  j = s_i.begin(), j_end = s_i.end(); j != j_end; ++j) {
1669  Coefficient_traits::const_reference s_ij = *j;
1670  if (s_ij != 0) {
1671  WEIGHT_ADD(30);
1672  gcd_assign(gcd, s_ij, gcd);
1673  if (gcd == 1) {
1674  return;
1675  }
1676  }
1677  }
1678  WEIGHT_BEGIN();
1679  const Row& t_i = t[i];
1680  for (Row::const_iterator
1681  j = t_i.begin(), j_end = t_i.end(); j != j_end; ++j) {
1682  Coefficient_traits::const_reference t_ij = *j;
1683  if (t_ij != 0) {
1684  WEIGHT_ADD(14);
1685  gcd_assign(gcd, t_ij, gcd);
1686  if (gcd == 1) {
1687  return;
1688  }
1689  }
1690  }
1691  }
1692  PPL_ASSERT(gcd > 1);
1693  // Normalize all coefficients.
1694  WEIGHT_BEGIN();
1695  for (dimension_type i = num_rows; i-- > 0; ) {
1696  Row& s_i = s[i];
1697  for (Row::iterator j = s_i.begin(), j_end = s_i.end(); j != j_end; ++j) {
1698  Coefficient& s_ij = *j;
1699  WEIGHT_ADD(19);
1700  exact_div_assign(s_ij, s_ij, gcd);
1701  }
1702  Row& t_i = t[i];
1703  for (Row::iterator j = t_i.begin(), j_end = t_i.end(); j != j_end; ++j) {
1704  Coefficient& t_ij = *j;
1705  WEIGHT_ADD(27);
1706  exact_div_assign(t_ij, t_ij, gcd);
1707  }
1708  }
1709  // Normalize denominator.
1710  exact_div_assign(denom, denom, gcd);
1711 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
CO_Tree::iterator iterator
An iterator on the row elements.
#define WEIGHT_ADD(delta)
Definition: globals_defs.hh:83
void exact_div_assign(Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z)
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
#define WEIGHT_BEGIN()
Definition: globals_defs.hh:81
Matrix< Row > t
The matrix of parameter coefficients.
void gcd_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
Coefficient denom
A common denominator for all matrix elements.
Matrix< Row > s
The matrix of simplex coefficients.
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
bool Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::OK ( ) const

Returns true if and only if *this is well formed.

Definition at line 1168 of file PIP_Tree.cc.

References t.

Referenced by Tableau().

1168  {
1169  if (s.num_rows() != t.num_rows()) {
1170 #ifndef NDEBUG
1171  std::cerr << "PIP_Solution_Node::Tableau matrices "
1172  << "have a different number of rows.\n";
1173 #endif
1174  return false;
1175  }
1176 
1177  if (!s.OK() || !t.OK()) {
1178 #ifndef NDEBUG
1179  std::cerr << "A PIP_Solution_Node::Tableau matrix is broken.\n";
1180 #endif
1181  return false;
1182  }
1183 
1184  if (denom <= 0) {
1185 #ifndef NDEBUG
1186  std::cerr << "PIP_Solution_Node::Tableau with non-positive "
1187  << "denominator.\n";
1188 #endif
1189  return false;
1190  }
1191 
1192  // All tests passed.
1193  return true;
1194 }
Matrix< Row > t
The matrix of parameter coefficients.
Coefficient denom
A common denominator for all matrix elements.
Matrix< Row > s
The matrix of simplex coefficients.
void Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::scale ( Coefficient_traits::const_reference  ratio)

Multiplies all coefficients and denominator with ratio.

Definition at line 1714 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::Sparse_Row::begin(), Parma_Polyhedra_Library::Sparse_Row::end(), WEIGHT_ADD, and WEIGHT_BEGIN.

1714  {
1715  WEIGHT_BEGIN();
1716  for (dimension_type i = s.num_rows(); i-- > 0; ) {
1717  Row& s_i = s[i];
1718  for (Row::iterator j = s_i.begin(), j_end = s_i.end(); j != j_end; ++j) {
1719  WEIGHT_ADD(19);
1720  *j *= ratio;
1721  }
1722  Row& t_i = t[i];
1723  for (Row::iterator j = t_i.begin(), j_end = t_i.end(); j != j_end; ++j) {
1724  WEIGHT_ADD(25);
1725  *j *= ratio;
1726  }
1727  }
1728  denom *= ratio;
1729 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
CO_Tree::iterator iterator
An iterator on the row elements.
#define WEIGHT_ADD(delta)
Definition: globals_defs.hh:83
#define WEIGHT_BEGIN()
Definition: globals_defs.hh:81
Matrix< Row > t
The matrix of parameter coefficients.
Coefficient denom
A common denominator for all matrix elements.
Matrix< Row > s
The matrix of simplex coefficients.

Member Data Documentation

Coefficient Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::denom

A common denominator for all matrix elements.

Definition at line 419 of file PIP_Tree_defs.hh.

Matrix<Row> Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::s

The matrix of simplex coefficients.

Definition at line 415 of file PIP_Tree_defs.hh.

Matrix<Row> Parma_Polyhedra_Library::PIP_Solution_Node::Tableau::t

The matrix of parameter coefficients.

Definition at line 417 of file PIP_Tree_defs.hh.

Referenced by OK().


The documentation for this struct was generated from the following files: