PPL  1.2
Parma_Polyhedra_Library::PIP_Tree_Node Class Referenceabstract

A node of the PIP solution tree. More...

#include <PIP_Tree_defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::PIP_Tree_Node:
Collaboration diagram for Parma_Polyhedra_Library::PIP_Tree_Node:

Classes

class  Artificial_Parameter
 Artificial parameters in PIP solution trees. More...
 

Public Types

typedef Sparse_Row Row
 
typedef std::vector< Artificial_ParameterArtificial_Parameter_Sequence
 A type alias for a sequence of Artificial_Parameter's. More...
 

Public Member Functions

virtual PIP_Tree_Nodeclone () const =0
 Returns a pointer to a dynamically-allocated copy of *this. More...
 
virtual ~PIP_Tree_Node ()
 Destructor. More...
 
virtual bool OK () const =0
 Returns true if and only if *this is well formed. More...
 
virtual const PIP_Solution_Nodeas_solution () const =0
 Returns this if *this is a solution node, 0 otherwise. More...
 
virtual const PIP_Decision_Nodeas_decision () const =0
 Returns this if *this is a decision node, 0 otherwise. More...
 
const Constraint_Systemconstraints () const
 Returns the system of parameter constraints controlling *this. More...
 
Artificial_Parameter_Sequence::const_iterator art_parameter_begin () const
 Returns a const_iterator to the beginning of local artificial parameters. More...
 
Artificial_Parameter_Sequence::const_iterator art_parameter_end () const
 Returns a const_iterator to the end of local artificial parameters. More...
 
dimension_type art_parameter_count () const
 Returns the number of local artificial parameters. More...
 
void print (std::ostream &s, int indent=0) const
 Prints on s the tree rooted in *this. More...
 
void ascii_dump (std::ostream &s) const
 Dumps to s an ASCII representation of *this. More...
 
bool ascii_load (std::istream &s)
 Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this accordingly. Returns true if successful, false otherwise. More...
 
virtual memory_size_type total_memory_in_bytes () const =0
 Returns the total size in bytes of the memory occupied by *this. More...
 
virtual memory_size_type external_memory_in_bytes () const =0
 Returns the size in bytes of the memory managed by *this. More...
 

Protected Types

typedef std::vector< ConstraintConstraint_Sequence
 A type alias for a sequence of constraints. More...
 

Protected Member Functions

 PIP_Tree_Node (const PIP_Problem *owner)
 Constructor: builds a node owned by *owner. More...
 
 PIP_Tree_Node (const PIP_Tree_Node &y)
 Copy constructor. More...
 
const PIP_Problemget_owner () const
 Returns a pointer to the PIP_Problem owning object. More...
 
virtual void set_owner (const PIP_Problem *owner)=0
 Sets the pointer to the PIP_Problem owning object. More...
 
virtual bool check_ownership (const PIP_Problem *owner) const =0
 Returns true if and only if all the nodes in the subtree rooted in *this are owned by *owner. More...
 
const PIP_Decision_Nodeparent () const
 Returns a pointer to this node's parent. More...
 
void set_parent (const PIP_Decision_Node *p)
 Set this node's parent to *p. More...
 
virtual void update_tableau (const PIP_Problem &pip, dimension_type external_space_dim, dimension_type first_pending_constraint, const Constraint_Sequence &input_cs, const Variables_Set &parameters)=0
 Populates the parametric simplex tableau using external data. More...
 
virtual PIP_Tree_Nodesolve (const PIP_Problem &pip, bool check_feasible_context, const Matrix< Row > &context, const Variables_Set &params, dimension_type space_dim, int indent_level)=0
 Executes a parametric simplex on the tableau, under specified context. More...
 
void add_constraint (const Row &row, const Variables_Set &parameters)
 Inserts a new parametric constraint in internal row format. More...
 
void parent_merge ()
 Merges parent's artificial parameters into *this. More...
 
virtual void print_tree (std::ostream &s, int indent, const std::vector< bool > &pip_dim_is_param, dimension_type first_art_dim) const =0
 Prints on s the tree rooted in *this. More...
 

Static Protected Member Functions

static void indent_and_print (std::ostream &s, int indent, const char *str)
 A helper function used when printing PIP trees. More...
 
static bool compatibility_check (Matrix< Row > &s)
 Checks whether a context matrix is satisfiable. More...
 
static bool compatibility_check (const Matrix< Row > &context, const Row &row)
 Helper method: checks for satisfiability of the restricted context obtained by adding row to context. More...
 

Protected Attributes

const PIP_Problemowner_
 A pointer to the PIP_Problem object owning this node. More...
 
const PIP_Decision_Nodeparent_
 A pointer to the parent of *this, null if *this is the root. More...
 
Constraint_System constraints_
 The local system of parameter constraints. More...
 
Artificial_Parameter_Sequence artificial_parameters
 The local sequence of expressions for local artificial parameters. More...
 

Friends

class PIP_Problem
 
class PIP_Decision_Node
 
class PIP_Solution_Node
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, const PIP_Tree_Node &x)
 Output operator: prints the solution tree rooted in x. More...
 

Detailed Description

A node of the PIP solution tree.

This is the base class for the nodes of the binary trees representing the solutions of PIP problems. From this one, two classes are derived:

Definition at line 50 of file PIP_Tree_defs.hh.

Member Typedef Documentation

A type alias for a sequence of Artificial_Parameter's.

Definition at line 101 of file PIP_Tree_defs.hh.

A type alias for a sequence of constraints.

Definition at line 142 of file PIP_Tree_defs.hh.

Constructor & Destructor Documentation

Parma_Polyhedra_Library::PIP_Tree_Node::PIP_Tree_Node ( const PIP_Problem owner)
explicitprotected

Constructor: builds a node owned by *owner.

Definition at line 916 of file PIP_Tree.cc.

917  : owner_(owner),
918  parent_(0),
919  constraints_(),
921 }
const PIP_Problem * owner_
A pointer to the PIP_Problem object owning this node.
const PIP_Decision_Node * parent_
A pointer to the parent of *this, null if *this is the root.
Artificial_Parameter_Sequence artificial_parameters
The local sequence of expressions for local artificial parameters.
Constraint_System constraints_
The local system of parameter constraints.
Parma_Polyhedra_Library::PIP_Tree_Node::PIP_Tree_Node ( const PIP_Tree_Node y)
protected

Copy constructor.

Definition at line 923 of file PIP_Tree.cc.

924  : owner_(y.owner_),
925  parent_(0), // NOTE: parent is not copied.
926  constraints_(y.constraints_),
927  artificial_parameters(y.artificial_parameters) {
928 }
const PIP_Problem * owner_
A pointer to the PIP_Problem object owning this node.
const PIP_Decision_Node * parent_
A pointer to the parent of *this, null if *this is the root.
Artificial_Parameter_Sequence artificial_parameters
The local sequence of expressions for local artificial parameters.
Constraint_System constraints_
The local system of parameter constraints.
Parma_Polyhedra_Library::PIP_Tree_Node::~PIP_Tree_Node ( )
virtual

Destructor.

Definition at line 930 of file PIP_Tree.cc.

930  {
931 }

Member Function Documentation

void Parma_Polyhedra_Library::PIP_Tree_Node::add_constraint ( const Row row,
const Variables_Set parameters 
)
protected

Inserts a new parametric constraint in internal row format.

Definition at line 1222 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::add_mul_assign(), Parma_Polyhedra_Library::Sparse_Row::begin(), constraints_, Parma_Polyhedra_Library::Sparse_Row::end(), Parma_Polyhedra_Library::Sparse_Row::get(), Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), Parma_Polyhedra_Library::Constraint_System::insert(), WEIGHT_ADD, and WEIGHT_BEGIN.

Referenced by Parma_Polyhedra_Library::PIP_Solution_Node::solve().

1222  {
1223  // Compute the expression for the parameter constraint.
1224  Linear_Expression expr = Linear_Expression(row.get(0));
1225  Variables_Set::const_iterator j = parameters.begin();
1226  if (!parameters.empty()) {
1227  // Needed to avoid reallocations in expr when iterating upward.
1228  add_mul_assign(expr, 0, Variable(*(parameters.rbegin())));
1229  // The number of increments of j plus one.
1230  dimension_type j_index = 1;
1231  Row::const_iterator i = row.begin();
1232  Row::const_iterator i_end = row.end();
1233  if (i != i_end && i.index() == 0) {
1234  ++i;
1235  }
1236  // NOTE: iterating in [1..num_params].
1237  WEIGHT_BEGIN();
1238  for ( ; i != i_end; ++i) {
1239  PPL_ASSERT(i.index() <= parameters.size());
1240  std::advance(j, i.index() - j_index);
1241  j_index = i.index();
1242  WEIGHT_ADD(74);
1243  add_mul_assign(expr, *i, Variable(*j));
1244  }
1245  }
1246  // Add the parameter constraint.
1247  constraints_.insert(expr >= 0);
1248 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
void add_mul_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
void insert(const Constraint &c)
Inserts in *this a copy of the constraint c, increasing the number of space dimensions if needed...
#define WEIGHT_ADD(delta)
Definition: globals_defs.hh:83
#define WEIGHT_BEGIN()
Definition: globals_defs.hh:81
Constraint_System constraints_
The local system of parameter constraints.
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
PIP_Tree_Node::Artificial_Parameter_Sequence::const_iterator Parma_Polyhedra_Library::PIP_Tree_Node::art_parameter_begin ( ) const
inline

Returns a const_iterator to the beginning of local artificial parameters.

Definition at line 76 of file PIP_Tree_inlines.hh.

References artificial_parameters.

Referenced by external_memory_in_bytes(), parent_merge(), and print_tree().

76  {
77  return artificial_parameters.begin();
78 }
Artificial_Parameter_Sequence artificial_parameters
The local sequence of expressions for local artificial parameters.
dimension_type Parma_Polyhedra_Library::PIP_Tree_Node::art_parameter_count ( ) const
inline

Returns the number of local artificial parameters.

Definition at line 86 of file PIP_Tree_inlines.hh.

References artificial_parameters.

Referenced by Parma_Polyhedra_Library::PIP_Decision_Node::print_tree().

86  {
87  return artificial_parameters.size();
88 }
Artificial_Parameter_Sequence artificial_parameters
The local sequence of expressions for local artificial parameters.
PIP_Tree_Node::Artificial_Parameter_Sequence::const_iterator Parma_Polyhedra_Library::PIP_Tree_Node::art_parameter_end ( ) const
inline

Returns a const_iterator to the end of local artificial parameters.

Definition at line 81 of file PIP_Tree_inlines.hh.

References artificial_parameters.

Referenced by external_memory_in_bytes(), parent_merge(), and print_tree().

81  {
82  return artificial_parameters.end();
83 }
Artificial_Parameter_Sequence artificial_parameters
The local sequence of expressions for local artificial parameters.
virtual const PIP_Decision_Node* Parma_Polyhedra_Library::PIP_Tree_Node::as_decision ( ) const
pure virtual

Returns this if *this is a decision node, 0 otherwise.

Implemented in Parma_Polyhedra_Library::PIP_Decision_Node, and Parma_Polyhedra_Library::PIP_Solution_Node.

virtual const PIP_Solution_Node* Parma_Polyhedra_Library::PIP_Tree_Node::as_solution ( ) const
pure virtual

Returns this if *this is a solution node, 0 otherwise.

Implemented in Parma_Polyhedra_Library::PIP_Decision_Node, and Parma_Polyhedra_Library::PIP_Solution_Node.

void Parma_Polyhedra_Library::PIP_Tree_Node::ascii_dump ( std::ostream &  s) const

Dumps to s an ASCII representation of *this.

Definition at line 1818 of file PIP_Tree.cc.

References artificial_parameters, Parma_Polyhedra_Library::Constraint_System::ascii_dump(), and constraints_.

Referenced by Parma_Polyhedra_Library::PIP_Solution_Node::ascii_dump(), and Parma_Polyhedra_Library::PIP_Decision_Node::ascii_dump().

1818  {
1819  s << "constraints_\n";
1821  const dimension_type artificial_parameters_size
1822  = artificial_parameters.size();
1823  s << "\nartificial_parameters( " << artificial_parameters_size << " )\n";
1824  for (dimension_type i = 0; i < artificial_parameters_size; ++i) {
1825  artificial_parameters[i].ascii_dump(s);
1826  }
1827 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
void ascii_dump() const
Writes to std::cerr an ASCII representation of *this.
Artificial_Parameter_Sequence artificial_parameters
The local sequence of expressions for local artificial parameters.
Constraint_System constraints_
The local system of parameter constraints.
bool Parma_Polyhedra_Library::PIP_Tree_Node::ascii_load ( std::istream &  s)

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

Definition at line 1830 of file PIP_Tree.cc.

References artificial_parameters, Parma_Polyhedra_Library::Constraint_System::ascii_load(), Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::ascii_load(), and constraints_.

Referenced by Parma_Polyhedra_Library::PIP_Solution_Node::ascii_load(), and Parma_Polyhedra_Library::PIP_Decision_Node::ascii_load().

1830  {
1831  std::string str;
1832  if (!(s >> str) || str != "constraints_") {
1833  return false;
1834  }
1836 
1837  if (!(s >> str) || str != "artificial_parameters(") {
1838  return false;
1839  }
1840 
1841  dimension_type artificial_parameters_size;
1842  if (!(s >> artificial_parameters_size)) {
1843  return false;
1844  }
1845 
1846  if (!(s >> str) || str != ")") {
1847  return false;
1848  }
1849  Artificial_Parameter ap;
1850  for (dimension_type i = 0; i < artificial_parameters_size; ++i) {
1851  if (!ap.ascii_load(s)) {
1852  return false;
1853  }
1854  artificial_parameters.push_back(ap);
1855  }
1856 
1857  // Note: do not assert OK() here.
1858  // The node invariants should be checked on derived nodes.
1859  return true;
1860 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
Artificial_Parameter_Sequence artificial_parameters
The local sequence of expressions for local artificial parameters.
Constraint_System constraints_
The local system of parameter constraints.
virtual bool Parma_Polyhedra_Library::PIP_Tree_Node::check_ownership ( const PIP_Problem owner) const
protectedpure virtual

Returns true if and only if all the nodes in the subtree rooted in *this are owned by *owner.

Implemented in Parma_Polyhedra_Library::PIP_Decision_Node, and Parma_Polyhedra_Library::PIP_Solution_Node.

Referenced by Parma_Polyhedra_Library::PIP_Decision_Node::check_ownership().

virtual PIP_Tree_Node* Parma_Polyhedra_Library::PIP_Tree_Node::clone ( ) const
pure virtual
bool Parma_Polyhedra_Library::PIP_Tree_Node::compatibility_check ( Matrix< Row > &  s)
staticprotected

Checks whether a context matrix is satisfiable.

The satisfiability check is implemented by the revised dual simplex algorithm on the context matrix. The algorithm ensures the feasible solution is integer by applying a cut generation method when intermediate non-integer solutions are found.

Definition at line 2195 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::Matrix< Row >::add_zero_rows(), Parma_Polyhedra_Library::PIP_Solution_Node::basis, Parma_Polyhedra_Library::Sparse_Row::begin(), Parma_Polyhedra_Library::Sparse_Row::end(), Parma_Polyhedra_Library::exact_div_assign(), Parma_Polyhedra_Library::gcd_assign(), Parma_Polyhedra_Library::Sparse_Row::get(), Parma_Polyhedra_Library::PIP_Solution_Node::mapping, Parma_Polyhedra_Library::maybe_abandon(), Parma_Polyhedra_Library::not_a_dimension(), Parma_Polyhedra_Library::Matrix< Row >::num_columns(), Parma_Polyhedra_Library::Matrix< Row >::num_rows(), Parma_Polyhedra_Library::Matrix< Row >::OK(), PPL_DIRTY_TEMP_COEFFICIENT, Parma_Polyhedra_Library::Matrix< Row >::remove_trailing_rows(), Parma_Polyhedra_Library::swap(), Parma_Polyhedra_Library::PIP_Solution_Node::var_column, Parma_Polyhedra_Library::PIP_Solution_Node::var_row, WEIGHT_ADD, and WEIGHT_BEGIN.

Referenced by compatibility_check(), Parma_Polyhedra_Library::PIP_Problem::solve(), Parma_Polyhedra_Library::PIP_Solution_Node::solve(), and Parma_Polyhedra_Library::PIP_Decision_Node::solve().

2195  {
2196  PPL_ASSERT(s.OK());
2197  // Note: num_rows may increase.
2198  dimension_type num_rows = s.num_rows();
2199  const dimension_type num_columns = s.num_columns();
2200  const dimension_type num_vars = num_columns - 1;
2201 
2202  std::vector<Coefficient> scaling(num_rows, 1);
2203  std::vector<bool> basis;
2204  basis.reserve(num_vars + num_rows);
2205  std::vector<dimension_type> mapping;
2206  mapping.reserve(num_vars + num_rows);
2207  std::vector<dimension_type> var_row;
2208  var_row.reserve(num_rows);
2209  std::vector<dimension_type> var_column;
2210  var_column.reserve(num_columns);
2211 
2212  // Column 0 is the constant term, not a variable
2213  var_column.push_back(not_a_dimension());
2214  for (dimension_type j = 1; j <= num_vars; ++j) {
2215  basis.push_back(true);
2216  mapping.push_back(j);
2217  var_column.push_back(j - 1);
2218  }
2219  for (dimension_type i = 0; i < num_rows; ++i) {
2220  basis.push_back(false);
2221  mapping.push_back(i);
2222  var_row.push_back(i + num_vars);
2223  }
2224 
2225  // Scaling factor (i.e., denominator) for pivot coefficients.
2226  PPL_DIRTY_TEMP_COEFFICIENT(pivot_denom);
2227  // Allocate once and for all: short life temporaries.
2228  PPL_DIRTY_TEMP_COEFFICIENT(product);
2230  PPL_DIRTY_TEMP_COEFFICIENT(scale_factor);
2231 
2232  // Perform simplex pivots on the context
2233  // until we find an empty solution or an optimum.
2234  while (true) {
2235  // Check if the client has requested abandoning all expensive
2236  // computations. If so, the exception specified by the client
2237  // is thrown now.
2238  maybe_abandon();
2239 
2240  // pi is the pivot's row index.
2241  dimension_type pi = num_rows;
2242  // pj is the pivot's column index.
2243  dimension_type pj = 0;
2244 
2245  const bool found_positive_pivot_candidate
2246  = compatibility_check_find_pivot(s, mapping, basis, pi, pj);
2247 
2248  if (!found_positive_pivot_candidate) {
2249  return false;
2250  }
2251 
2252  if (pj == 0) {
2253  // No negative RHS: fractional optimum found.
2254  // If it is integer, then the test is successful.
2255  // Otherwise, generate a new cut.
2256  bool all_integer_vars = true;
2257  // NOTE: iterating downwards would be correct, but it would change
2258  // the ordering of cut generation.
2259  WEIGHT_BEGIN();
2260  for (dimension_type i = 0; i < num_vars; ++i) {
2261  if (basis[i]) {
2262  // Basic variable = 0, hence integer.
2263  continue;
2264  }
2265  // Not a basic variable.
2266  WEIGHT_ADD(70);
2267  const dimension_type mi = mapping[i];
2268  Coefficient_traits::const_reference denom = scaling[mi];
2269  if (s[mi].get(0) % denom == 0) {
2270  continue;
2271  }
2272  // Here constant term is not integer.
2273  all_integer_vars = false;
2274  // Generate a new cut.
2275  var_row.push_back(mapping.size());
2276  basis.push_back(false);
2277  mapping.push_back(num_rows);
2278  s.add_zero_rows(1);
2279  Row& cut = s[num_rows];
2280  ++num_rows;
2281  const Row& s_mi = s[mi];
2282  cut = s_mi;
2283  for (Row::iterator
2284  j = cut.begin(), j_end = cut.end(); j != j_end; ++j) {
2285  WEIGHT_ADD(32);
2286  pos_rem_assign(*j, *j, denom);
2287  }
2288  cut[0] -= denom;
2289  scaling.push_back(denom);
2290  }
2291  // Check if an integer solution was found.
2292  if (all_integer_vars) {
2293  return true;
2294  }
2295  else {
2296  continue;
2297  }
2298  }
2299 
2300  // Here we have a positive s[pi][pj] pivot.
2301 
2302  // Normalize the tableau before pivoting.
2303  for (dimension_type i = num_rows; i-- > 0; ) {
2304  row_normalize(s[i], scaling[i]);
2305  }
2306 
2307  // Update basis.
2308  {
2309  const dimension_type var_pi = var_row[pi];
2310  const dimension_type var_pj = var_column[pj];
2311  var_row[pi] = var_pj;
2312  var_column[pj] = var_pi;
2313  basis[var_pi] = true;
2314  basis[var_pj] = false;
2315  mapping[var_pi] = pj;
2316  mapping[var_pj] = pi;
2317  }
2318 
2319  // Create an identity row corresponding to basic variable pj.
2320  s.add_zero_rows(1);
2321  Row& pivot = s[num_rows];
2322  pivot[pj] = 1;
2323 
2324  // Swap identity row with the pivot row previously found.
2325  using std::swap;
2326  swap(pivot, s[pi]);
2327  // Save original pivot scaling factor in a temporary,
2328  // then reset scaling factor for identity row.
2329  pivot_denom = scaling[pi];
2330  scaling[pi] = 1;
2331 
2332  // Perform a pivot operation on the matrix.
2333  Coefficient_traits::const_reference pivot_pj = pivot.get(pj);
2334  {
2335  for (Row::const_iterator
2336  j = pivot.begin(), j_end = pivot.end(); j != j_end; ++j) {
2337  if (j.index() == pj) {
2338  continue;
2339  }
2340  Coefficient_traits::const_reference pivot_j = *j;
2341  // Do nothing if the j-th pivot element is zero.
2342  if (pivot_j == 0) {
2343  continue;
2344  }
2345 
2346  WEIGHT_BEGIN();
2347  for (dimension_type i = num_rows; i-- > 0; ) {
2348  Row& s_i = s[i];
2349  product = s_i.get(pj) * pivot_j;
2350  if (product % pivot_pj != 0) {
2351  WEIGHT_ADD(103);
2352  // Must scale row s_i to stay in integer case.
2353  gcd_assign(gcd, product, pivot_pj);
2354  exact_div_assign(scale_factor, pivot_pj, gcd);
2355  for (Row::iterator
2356  k = s_i.begin(), k_end = s_i.end(); k != k_end; ++k) {
2357  WEIGHT_ADD(30);
2358  *k *= scale_factor;
2359  }
2360  product *= scale_factor;
2361  scaling[i] *= scale_factor;
2362  }
2363  PPL_ASSERT(product % pivot_pj == 0);
2364  exact_div_assign(product, product, pivot_pj);
2365  s_i[j.index()] -= product;
2366  WEIGHT_ADD(134);
2367  }
2368  }
2369  }
2370  // Update column only if pivot coordinate != 1.
2371  if (pivot_pj != pivot_denom) {
2372  WEIGHT_BEGIN();
2373  for (dimension_type i = num_rows; i-- > 0; ) {
2374  Row& s_i = s[i];
2375  Coefficient& s_i_pj = s_i[pj];
2376  product = s_i_pj * pivot_denom;
2377  if (product % pivot_pj != 0) {
2378  WEIGHT_ADD(98);
2379  // As above, perform row scaling.
2380  gcd_assign(gcd, product, pivot_pj);
2381  exact_div_assign(scale_factor, pivot_pj, gcd);
2382  for (Row::iterator
2383  k = s_i.begin(), k_end = s_i.end(); k != k_end; ++k) {
2384  WEIGHT_ADD(26);
2385  *k *= scale_factor;
2386  }
2387  product *= scale_factor;
2388  scaling[i] *= scale_factor;
2389  }
2390  PPL_ASSERT(product % pivot_pj == 0);
2391  exact_div_assign(s_i_pj, product, pivot_pj);
2392  WEIGHT_ADD(97);
2393  }
2394  }
2395  // Drop pivot to restore proper matrix size.
2396  s.remove_trailing_rows(1);
2397  }
2398 
2399  // This point should be unreachable.
2400  PPL_UNREACHABLE;
2401  return false;
2402 }
void swap(CO_Tree &x, CO_Tree &y)
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...
dimension_type not_a_dimension()
Returns a value that does not designate a valid dimension.
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
void gcd_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
Coefficient_traits::const_reference get(dimension_type i) const
Gets the i-th element in the sequence.
bool Parma_Polyhedra_Library::PIP_Tree_Node::compatibility_check ( const Matrix< Row > &  context,
const Row row 
)
staticprotected

Helper method: checks for satisfiability of the restricted context obtained by adding row to context.

Definition at line 2187 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::Matrix< Row >::add_row(), and compatibility_check().

2187  {
2188  // CHECKME: do `context' and `row' have compatible (row) capacity?
2189  Matrix<Row> s(context);
2190  s.add_row(row);
2191  return compatibility_check(s);
2192 }
static bool compatibility_check(Matrix< Row > &s)
Checks whether a context matrix is satisfiable.
Definition: PIP_Tree.cc:2195
const Constraint_System & Parma_Polyhedra_Library::PIP_Tree_Node::constraints ( ) const
inline

Returns the system of parameter constraints controlling *this.

The indices in the constraints are the same as the original variables and parameters. Coefficients in indices corresponding to variables always are zero.

Definition at line 71 of file PIP_Tree_inlines.hh.

References constraints_.

71  {
72  return constraints_;
73 }
Constraint_System constraints_
The local system of parameter constraints.
memory_size_type Parma_Polyhedra_Library::PIP_Tree_Node::external_memory_in_bytes ( ) const
pure virtual

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

Implemented in Parma_Polyhedra_Library::PIP_Decision_Node, and Parma_Polyhedra_Library::PIP_Solution_Node.

Definition at line 3741 of file PIP_Tree.cc.

References art_parameter_begin(), art_parameter_end(), artificial_parameters, constraints_, and Parma_Polyhedra_Library::Constraint_System::external_memory_in_bytes().

Referenced by Parma_Polyhedra_Library::PIP_Solution_Node::external_memory_in_bytes(), and Parma_Polyhedra_Library::PIP_Decision_Node::external_memory_in_bytes().

3741  {
3743  // Adding the external memory for `artificial_parameters'.
3744  n += artificial_parameters.capacity() * sizeof(Artificial_Parameter);
3745  for (Artificial_Parameter_Sequence::const_iterator
3746  ap = art_parameter_begin(),
3747  ap_end = art_parameter_end(); ap != ap_end; ++ap) {
3748  n += (ap->external_memory_in_bytes());
3749  }
3750 
3751  return n;
3752 }
Artificial_Parameter_Sequence::const_iterator art_parameter_begin() const
Returns a const_iterator to the beginning of local artificial parameters.
Artificial_Parameter_Sequence::const_iterator art_parameter_end() const
Returns a const_iterator to the end of local artificial parameters.
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
Artificial_Parameter_Sequence artificial_parameters
The local sequence of expressions for local artificial parameters.
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
Constraint_System constraints_
The local system of parameter constraints.
const PIP_Problem * Parma_Polyhedra_Library::PIP_Tree_Node::get_owner ( ) const
inlineprotected
void Parma_Polyhedra_Library::PIP_Tree_Node::indent_and_print ( std::ostream &  s,
int  indent,
const char *  str 
)
staticprotected

A helper function used when printing PIP trees.

Definition at line 3803 of file PIP_Tree.cc.

Referenced by Parma_Polyhedra_Library::PIP_Problem::print_solution(), print_tree(), Parma_Polyhedra_Library::PIP_Solution_Node::print_tree(), Parma_Polyhedra_Library::PIP_Decision_Node::print_tree(), Parma_Polyhedra_Library::PIP_Solution_Node::solve(), and Parma_Polyhedra_Library::PIP_Decision_Node::solve().

3805  {
3806  PPL_ASSERT(indent >= 0);
3807  s << std::setw(2 * indent) << "" << str;
3808 }
bool Parma_Polyhedra_Library::PIP_Tree_Node::OK ( ) const
pure virtual

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

Implemented in Parma_Polyhedra_Library::PIP_Decision_Node, and Parma_Polyhedra_Library::PIP_Solution_Node.

Definition at line 1197 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Solution_Node::ascii_dump(), Parma_Polyhedra_Library::Constraint_System::begin(), constraints_, and Parma_Polyhedra_Library::Constraint_System::end().

Referenced by Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::ascii_load(), Parma_Polyhedra_Library::PIP_Solution_Node::OK(), Parma_Polyhedra_Library::PIP_Decision_Node::OK(), and Parma_Polyhedra_Library::PIP_Decision_Node::solve().

1197  {
1198 #ifndef NDEBUG
1199  using std::endl;
1200  using std::cerr;
1201 #endif
1202 
1203  // Parameter constraint system should contain no strict inequalities.
1205  i = constraints_.begin(), i_end = constraints_.end(); i != i_end; ++i) {
1206  if (i->is_strict_inequality()) {
1207 #ifndef NDEBUG
1208  cerr << "The feasible region of the PIP_Problem parameter context"
1209  << "is defined by a constraint system containing strict "
1210  << "inequalities."
1211  << endl;
1212  ascii_dump(cerr);
1213 #endif
1214  return false;
1215  }
1216  }
1217  return true;
1218 }
const_iterator begin() const
Returns the const_iterator pointing to the first constraint, if *this is not empty; otherwise...
void ascii_dump(std::ostream &s) const
Dumps to s an ASCII representation of *this.
Definition: PIP_Tree.cc:1818
const_iterator end() const
Returns the past-the-end const_iterator.
Constraint_System constraints_
The local system of parameter constraints.
Constraint_System_const_iterator const_iterator
const PIP_Decision_Node * Parma_Polyhedra_Library::PIP_Tree_Node::parent ( ) const
inlineprotected

Returns a pointer to this node's parent.

Definition at line 61 of file PIP_Tree_inlines.hh.

References parent_.

Referenced by Parma_Polyhedra_Library::PIP_Solution_Node::generate_cut(), parent_merge(), print(), Parma_Polyhedra_Library::PIP_Solution_Node::solve(), and Parma_Polyhedra_Library::PIP_Decision_Node::solve().

61  {
62  return parent_;
63 }
const PIP_Decision_Node * parent_
A pointer to the parent of *this, null if *this is the root.
void Parma_Polyhedra_Library::PIP_Tree_Node::parent_merge ( )
protected

Merges parent's artificial parameters into *this.

Definition at line 1251 of file PIP_Tree.cc.

References art_parameter_begin(), art_parameter_end(), artificial_parameters, Parma_Polyhedra_Library::PIP_Solution_Node::OK(), parent(), and parent_.

Referenced by Parma_Polyhedra_Library::PIP_Decision_Node::solve().

1251  {
1252  const PIP_Decision_Node& parent = *parent_;
1253 
1254  // Merge the parent's artificial parameters.
1256  parent.art_parameter_begin(),
1257  parent.art_parameter_end());
1258 
1259  PPL_ASSERT(OK());
1260 }
const PIP_Decision_Node * parent() const
Returns a pointer to this node's parent.
virtual bool OK() const =0
Returns true if and only if *this is well formed.
Definition: PIP_Tree.cc:1197
const PIP_Decision_Node * parent_
A pointer to the parent of *this, null if *this is the root.
Artificial_Parameter_Sequence artificial_parameters
The local sequence of expressions for local artificial parameters.
void Parma_Polyhedra_Library::PIP_Tree_Node::print ( std::ostream &  s,
int  indent = 0 
) const

Prints on s the tree rooted in *this.

Parameters
sThe output stream.
indentThe amount of indentation.

Definition at line 3811 of file PIP_Tree.cc.

References get_owner(), Parma_Polyhedra_Library::PIP_Problem::parameter_space_dimensions(), parent(), Parma_Polyhedra_Library::PIP_Solution_Node::print_tree(), and Parma_Polyhedra_Library::PIP_Problem::space_dimension().

Referenced by Parma_Polyhedra_Library::IO_Operators::operator<<().

3811  {
3812  const dimension_type pip_space_dim = get_owner()->space_dimension();
3813  const Variables_Set& pip_params = get_owner()->parameter_space_dimensions();
3814 
3815  std::vector<bool> pip_dim_is_param(pip_space_dim);
3816  for (Variables_Set::const_iterator p = pip_params.begin(),
3817  p_end = pip_params.end(); p != p_end; ++p) {
3818  pip_dim_is_param[*p] = true;
3819  }
3820 
3821  dimension_type first_art_dim = pip_space_dim;
3822  for (const PIP_Tree_Node* node = parent();
3823  node != 0; node = node->parent()) {
3824  first_art_dim += node->art_parameter_count();
3825  }
3826 
3827  print_tree(s, indent, pip_dim_is_param, first_art_dim);
3828 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
const PIP_Decision_Node * parent() const
Returns a pointer to this node's parent.
const PIP_Problem * get_owner() const
Returns a pointer to the PIP_Problem owning object.
PIP_Tree_Node(const PIP_Problem *owner)
Constructor: builds a node owned by *owner.
Definition: PIP_Tree.cc:916
dimension_type space_dimension() const
Returns the space dimension of the PIP problem.
const Variables_Set & parameter_space_dimensions() const
Returns a set containing all the variables' indexes representing the parameters of the PIP problem...
virtual void print_tree(std::ostream &s, int indent, const std::vector< bool > &pip_dim_is_param, dimension_type first_art_dim) const =0
Prints on s the tree rooted in *this.
Definition: PIP_Tree.cc:3831
void Parma_Polyhedra_Library::PIP_Tree_Node::print_tree ( std::ostream &  s,
int  indent,
const std::vector< bool > &  pip_dim_is_param,
dimension_type  first_art_dim 
) const
protectedpure virtual

Prints on s the tree rooted in *this.

Parameters
sThe output stream.
indentThe amount of indentation.
pip_dim_is_paramA vector of Boolean flags telling which PIP problem dimensions are problem parameters. The size of the vector is equal to the PIP problem internal space dimension (i.e., no artificial parameters).
first_art_dimThe first space dimension corresponding to an artificial parameter that was created in this node (if any).

Implemented in Parma_Polyhedra_Library::PIP_Decision_Node, and Parma_Polyhedra_Library::PIP_Solution_Node.

Definition at line 3831 of file PIP_Tree.cc.

References art_parameter_begin(), art_parameter_end(), Parma_Polyhedra_Library::Constraint_System::begin(), constraints_, Parma_Polyhedra_Library::Constraint_System::empty(), Parma_Polyhedra_Library::Constraint_System::end(), and indent_and_print().

Referenced by Parma_Polyhedra_Library::PIP_Solution_Node::print_tree(), and Parma_Polyhedra_Library::PIP_Decision_Node::print_tree().

3833  {
3834  using namespace IO_Operators;
3835 
3836  // Print artificial parameters.
3837  for (Artificial_Parameter_Sequence::const_iterator
3838  api = art_parameter_begin(),
3839  api_end = art_parameter_end(); api != api_end; ++api) {
3840  indent_and_print(s, indent, "Parameter ");
3841  s << Variable(first_art_dim) << " = " << *api << "\n";
3842  ++first_art_dim;
3843  }
3844 
3845  // Print constraints, if any.
3846  if (!constraints_.empty()) {
3847  indent_and_print(s, indent, "if ");
3848 
3851  PPL_ASSERT(ci != ci_end);
3852  s << *ci;
3853  for (++ci; ci != ci_end; ++ci) {
3854  s << " and " << *ci;
3855  }
3856 
3857  s << " then\n";
3858  }
3859 }
Artificial_Parameter_Sequence::const_iterator art_parameter_begin() const
Returns a const_iterator to the beginning of local artificial parameters.
const_iterator begin() const
Returns the const_iterator pointing to the first constraint, if *this is not empty; otherwise...
Artificial_Parameter_Sequence::const_iterator art_parameter_end() const
Returns a const_iterator to the end of local artificial parameters.
bool empty() const
Returns true if and only if *this has no constraints.
const_iterator end() const
Returns the past-the-end const_iterator.
Constraint_System constraints_
The local system of parameter constraints.
static void indent_and_print(std::ostream &s, int indent, const char *str)
A helper function used when printing PIP trees.
Definition: PIP_Tree.cc:3803
Constraint_System_const_iterator const_iterator
virtual void Parma_Polyhedra_Library::PIP_Tree_Node::set_owner ( const PIP_Problem owner)
protectedpure virtual
void Parma_Polyhedra_Library::PIP_Tree_Node::set_parent ( const PIP_Decision_Node p)
inlineprotected

Set this node's parent to *p.

Definition at line 56 of file PIP_Tree_inlines.hh.

References parent_.

Referenced by Parma_Polyhedra_Library::PIP_Decision_Node::PIP_Decision_Node(), and Parma_Polyhedra_Library::PIP_Decision_Node::solve().

56  {
57  parent_ = p;
58 }
const PIP_Decision_Node * parent_
A pointer to the parent of *this, null if *this is the root.
virtual PIP_Tree_Node* Parma_Polyhedra_Library::PIP_Tree_Node::solve ( const PIP_Problem pip,
bool  check_feasible_context,
const Matrix< Row > &  context,
const Variables_Set params,
dimension_type  space_dim,
int  indent_level 
)
protectedpure virtual

Executes a parametric simplex on the tableau, under specified context.

Returns
The root of the PIP tree solution, or 0 if unfeasible.
Parameters
pipThe PIP_Problem object containing this node.
check_feasible_contextWhether the resolution process should (re-)check feasibility of context (since the initial context may have been modified).
contextThe context, being a set of constraints on the parameters.
paramsThe local parameter set, including parent's artificial parameters.
space_dimThe space dimension of parent, including artificial parameters.
indent_levelThe indentation level (for debugging output only).

Implemented in Parma_Polyhedra_Library::PIP_Decision_Node, and Parma_Polyhedra_Library::PIP_Solution_Node.

Referenced by Parma_Polyhedra_Library::PIP_Problem::solve(), and Parma_Polyhedra_Library::PIP_Solution_Node::solve().

virtual memory_size_type Parma_Polyhedra_Library::PIP_Tree_Node::total_memory_in_bytes ( ) const
pure virtual

Returns the total size in bytes of the memory occupied by *this.

Implemented in Parma_Polyhedra_Library::PIP_Decision_Node, and Parma_Polyhedra_Library::PIP_Solution_Node.

virtual void Parma_Polyhedra_Library::PIP_Tree_Node::update_tableau ( const PIP_Problem pip,
dimension_type  external_space_dim,
dimension_type  first_pending_constraint,
const Constraint_Sequence input_cs,
const Variables_Set parameters 
)
protectedpure virtual

Populates the parametric simplex tableau using external data.

Parameters
pipThe PIP_Problem object containing this node.
external_space_dimThe number of all problem variables and problem parameters (excluding artificial parameters).
first_pending_constraintThe first element in input_cs to be added to the tableau, which already contains the previous elements.
input_csAll the constraints of the PIP problem.
parametersThe set of indices of the problem parameters.

Implemented in Parma_Polyhedra_Library::PIP_Decision_Node, and Parma_Polyhedra_Library::PIP_Solution_Node.

Referenced by Parma_Polyhedra_Library::PIP_Problem::solve().

Friends And Related Function Documentation

std::ostream & operator<< ( std::ostream &  os,
const PIP_Tree_Node x 
)
related

Output operator: prints the solution tree rooted in x.

Definition at line 902 of file PIP_Tree.cc.

902  {
903  x.print(os);
904  return os;
905 }
friend class PIP_Problem
friend

Definition at line 146 of file PIP_Tree_defs.hh.

friend class PIP_Solution_Node
friend

Definition at line 148 of file PIP_Tree_defs.hh.

Member Data Documentation

const PIP_Problem* Parma_Polyhedra_Library::PIP_Tree_Node::owner_
protected
const PIP_Decision_Node* Parma_Polyhedra_Library::PIP_Tree_Node::parent_
protected

A pointer to the parent of *this, null if *this is the root.

Definition at line 154 of file PIP_Tree_defs.hh.

Referenced by parent(), parent_merge(), and set_parent().


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