PPL  1.2
Parma_Polyhedra_Library::PIP_Decision_Node Class Reference

A tree node representing a decision in the space of solutions. More...

#include <PIP_Tree_defs.hh>

Inheritance diagram for Parma_Polyhedra_Library::PIP_Decision_Node:
Collaboration diagram for Parma_Polyhedra_Library::PIP_Decision_Node:

Public Member Functions

virtual PIP_Tree_Nodeclone () const
 Returns a pointer to a dynamically-allocated copy of *this. More...
 
virtual ~PIP_Decision_Node ()
 Destructor. More...
 
virtual bool OK () const
 Returns true if and only if *this is well formed. More...
 
virtual const PIP_Decision_Nodeas_decision () const
 Returns this. More...
 
virtual const PIP_Solution_Nodeas_solution () const
 Returns 0, since this is not a solution node. More...
 
const PIP_Tree_Nodechild_node (bool b) const
 Returns a const pointer to the b (true or false) branch of *this. More...
 
PIP_Tree_Nodechild_node (bool b)
 Returns a pointer to the b (true or false) branch of *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
 Returns the total size in bytes of the memory occupied by *this. More...
 
virtual memory_size_type external_memory_in_bytes () const
 Returns the size in bytes of the memory managed by *this. More...
 
- Public Member Functions inherited from Parma_Polyhedra_Library::PIP_Tree_Node
virtual ~PIP_Tree_Node ()
 Destructor. 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...
 

Protected Member Functions

 PIP_Decision_Node (const PIP_Decision_Node &y)
 Copy constructor. 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)
 Implements pure virtual method PIP_Tree_Node::update_tableau. 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)
 Implements pure virtual method PIP_Tree_Node::solve. More...
 
virtual void print_tree (std::ostream &s, int indent, const std::vector< bool > &pip_dim_is_param, dimension_type first_art_dim) const
 Prints on s the tree rooted in *this. More...
 
- Protected Member Functions inherited from Parma_Polyhedra_Library::PIP_Tree_Node
 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...
 
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...
 
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...
 

Private Member Functions

 PIP_Decision_Node (const PIP_Problem *owner, PIP_Tree_Node *fcp, PIP_Tree_Node *tcp)
 Builds a decision node having fcp and tcp as child. More...
 
virtual void set_owner (const PIP_Problem *owner)
 Sets the pointer to the PIP_Problem owning object. More...
 
virtual bool check_ownership (const PIP_Problem *owner) const
 Returns true if and only if all the nodes in the subtree rooted in *this is owned by *pip. More...
 

Private Attributes

PIP_Tree_Nodefalse_child
 Pointer to the "false" child of *this. More...
 
PIP_Tree_Nodetrue_child
 Pointer to the "true" child of *this. More...
 

Friends

class PIP_Solution_Node
 
bool PIP_Problem::ascii_load (std::istream &s)
 

Additional Inherited Members

- Public Types inherited from Parma_Polyhedra_Library::PIP_Tree_Node
typedef Sparse_Row Row
 
typedef std::vector< Artificial_ParameterArtificial_Parameter_Sequence
 A type alias for a sequence of Artificial_Parameter's. More...
 
- Protected Types inherited from Parma_Polyhedra_Library::PIP_Tree_Node
typedef std::vector< ConstraintConstraint_Sequence
 A type alias for a sequence of constraints. More...
 
- Static Protected Member Functions inherited from Parma_Polyhedra_Library::PIP_Tree_Node
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 inherited from Parma_Polyhedra_Library::PIP_Tree_Node
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...
 

Detailed Description

A tree node representing a decision in the space of solutions.

Definition at line 707 of file PIP_Tree_defs.hh.

Constructor & Destructor Documentation

Parma_Polyhedra_Library::PIP_Decision_Node::~PIP_Decision_Node ( )
virtual

Destructor.

Definition at line 1114 of file PIP_Tree.cc.

References false_child, and true_child.

1114  {
1115  delete false_child;
1116  delete true_child;
1117 }
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.
Parma_Polyhedra_Library::PIP_Decision_Node::PIP_Decision_Node ( const PIP_Problem owner,
PIP_Tree_Node fcp,
PIP_Tree_Node tcp 
)
explicitprivate

Builds a decision node having fcp and tcp as child.

The decision node will encode the structure "if \c cs then \p tcp else \p fcp", where the system of constraints cs is initially empty.

Parameters
ownerPointer to the owning PIP_Problem object; it may be null if and only if both children are null.
fcpPointer to "false" child; it may be null.
tcpPointer to "true" child; it may be null.
Note
If any of fcp or tcp is not null, then owner is required to be not null and equal to the owner of its non-null children; otherwise the behavior is undefined.

Definition at line 1082 of file PIP_Tree.cc.

References false_child, Parma_Polyhedra_Library::PIP_Tree_Node::set_parent(), and true_child.

1085  : PIP_Tree_Node(owner),
1086  false_child(fcp),
1087  true_child(tcp) {
1088  if (false_child != 0) {
1089  false_child->set_parent(this);
1090  }
1091  if (true_child != 0) {
1092  true_child->set_parent(this);
1093  }
1094 }
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
PIP_Tree_Node(const PIP_Problem *owner)
Constructor: builds a node owned by *owner.
Definition: PIP_Tree.cc:916
void set_parent(const PIP_Decision_Node *p)
Set this node's parent to *p.
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.
Parma_Polyhedra_Library::PIP_Decision_Node::PIP_Decision_Node ( const PIP_Decision_Node y)
protected

Copy constructor.

Definition at line 1096 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Tree_Node::clone(), false_child, Parma_Polyhedra_Library::PIP_Tree_Node::set_parent(), and true_child.

1097  : PIP_Tree_Node(y),
1098  false_child(0),
1099  true_child(0) {
1100  if (y.false_child != 0) {
1101  false_child = y.false_child->clone();
1102  false_child->set_parent(this);
1103  }
1104  // Protect false_child from exception safety issues via std::auto_ptr.
1105  std::auto_ptr<PIP_Tree_Node> wrapped_node(false_child);
1106  if (y.true_child != 0) {
1107  true_child = y.true_child->clone();
1108  true_child->set_parent(this);
1109  }
1110  // It is now safe to release false_child.
1111  wrapped_node.release();
1112 }
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
PIP_Tree_Node(const PIP_Problem *owner)
Constructor: builds a node owned by *owner.
Definition: PIP_Tree.cc:916
virtual PIP_Tree_Node * clone() const =0
Returns a pointer to a dynamically-allocated copy of *this.
void set_parent(const PIP_Decision_Node *p)
Set this node's parent to *p.
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.

Member Function Documentation

const PIP_Decision_Node * Parma_Polyhedra_Library::PIP_Decision_Node::as_decision ( ) const
virtual

Returns this.

Implements Parma_Polyhedra_Library::PIP_Tree_Node.

Definition at line 1148 of file PIP_Tree.cc.

Referenced by Parma_Polyhedra_Library::PIP_Problem::ascii_dump(), and ascii_dump().

1148  {
1149  return this;
1150 }
const PIP_Solution_Node * Parma_Polyhedra_Library::PIP_Decision_Node::as_solution ( ) const
virtual

Returns 0, since this is not a solution node.

Implements Parma_Polyhedra_Library::PIP_Tree_Node.

Definition at line 1158 of file PIP_Tree.cc.

1158  {
1159  return 0;
1160 }
void Parma_Polyhedra_Library::PIP_Decision_Node::ascii_dump ( std::ostream &  s) const

Dumps to s an ASCII representation of *this.

Definition at line 1525 of file PIP_Tree.cc.

References as_decision(), Parma_Polyhedra_Library::PIP_Solution_Node::as_solution(), Parma_Polyhedra_Library::PIP_Tree_Node::ascii_dump(), and Parma_Polyhedra_Library::PIP_Solution_Node::ascii_dump().

1525  {
1526  // Dump base class info.
1528 
1529  // Dump true child (if any).
1530  s << "\ntrue_child: ";
1531  if (true_child == 0) {
1532  // Note: this branch should normally be unreachable code, since a
1533  // well-formed decision node always has a true child. We keep this code
1534  // for debugging purposes (since we want to dump broken nodes).
1535  s << "BOTTOM\n";
1536  }
1537  else if (const PIP_Decision_Node* const dec = true_child->as_decision()) {
1538  s << "DECISION\n";
1539  dec->ascii_dump(s);
1540  }
1541  else {
1542  const PIP_Solution_Node* const sol = true_child->as_solution();
1543  PPL_ASSERT(sol != 0);
1544  s << "SOLUTION\n";
1545  sol->ascii_dump(s);
1546  }
1547 
1548  // Dump false child (if any).
1549  s << "\nfalse_child: ";
1550  if (false_child == 0) {
1551  s << "BOTTOM\n";
1552  }
1553  else if (const PIP_Decision_Node* const dec = false_child->as_decision()) {
1554  // Note: this branch should normally be unreachable code.
1555  // Since a well-formed decision node having a false child should have
1556  // a single context constraint, its false child will have no context
1557  // constraints at all, so that no further branch is possible.
1558  // We keep this code for debugging purposes.
1559  s << "DECISION\n";
1560  dec->ascii_dump(s);
1561  }
1562  else {
1563  const PIP_Solution_Node* const sol = false_child->as_solution();
1564  PPL_ASSERT(sol != 0);
1565  s << "SOLUTION\n";
1566  sol->ascii_dump(s);
1567  }
1568 }
virtual const PIP_Decision_Node * as_decision() const =0
Returns this if *this is a decision node, 0 otherwise.
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
void ascii_dump(std::ostream &s) const
Dumps to s an ASCII representation of *this.
Definition: PIP_Tree.cc:1818
PIP_Decision_Node(const PIP_Problem *owner, PIP_Tree_Node *fcp, PIP_Tree_Node *tcp)
Builds a decision node having fcp and tcp as child.
Definition: PIP_Tree.cc:1082
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.
virtual const PIP_Solution_Node * as_solution() const =0
Returns this if *this is a solution node, 0 otherwise.
bool Parma_Polyhedra_Library::PIP_Decision_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 1571 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Tree_Node::ascii_load(), Parma_Polyhedra_Library::PIP_Solution_Node::ascii_load(), ascii_load(), Parma_Polyhedra_Library::PIP_Solution_Node::OK(), Parma_Polyhedra_Library::PIP_Tree_Node::PIP_Decision_Node, and Parma_Polyhedra_Library::PIP_Solution_Node::PIP_Solution_Node().

Referenced by Parma_Polyhedra_Library::PIP_Problem::ascii_load(), and ascii_load().

1571  {
1572  std::string str;
1573 
1574  // Load base class info.
1575  if (!PIP_Tree_Node::ascii_load(s)) {
1576  return false;
1577  }
1578 
1579  // Release the "true" subtree (if any).
1580  delete true_child;
1581  true_child = 0;
1582 
1583  // Load true child (if any).
1584  if (!(s >> str) || str != "true_child:") {
1585  return false;
1586  }
1587  if (!(s >> str)) {
1588  return false;
1589  }
1590  if (str == "BOTTOM") {
1591  // Note: normally unreachable code (see comment on ascii_dump).
1592  true_child = 0;
1593  }
1594  else if (str == "DECISION") {
1595  PIP_Decision_Node* const dec = new PIP_Decision_Node(0, 0, 0);
1596  true_child = dec;
1597  if (!dec->ascii_load(s)) {
1598  return false;
1599  }
1600  }
1601  else if (str == "SOLUTION") {
1602  PIP_Solution_Node* const sol = new PIP_Solution_Node(0);
1603  true_child = sol;
1604  if (!sol->ascii_load(s)) {
1605  return false;
1606  }
1607  }
1608  else {
1609  // Unknown node kind.
1610  return false;
1611  }
1612 
1613  // Release the "false" subtree (if any).
1614  delete false_child;
1615  false_child = 0;
1616 
1617  // Load false child (if any).
1618  if (!(s >> str) || str != "false_child:") {
1619  return false;
1620  }
1621  if (!(s >> str)) {
1622  return false;
1623  }
1624  if (str == "BOTTOM") {
1625  false_child = 0;
1626  }
1627  else if (str == "DECISION") {
1628  // Note: normally unreachable code (see comment on ascii_dump).
1629  PIP_Decision_Node* const dec = new PIP_Decision_Node(0, 0, 0);
1630  false_child = dec;
1631  if (!dec->ascii_load(s)) {
1632  return false;
1633  }
1634  }
1635  else if (str == "SOLUTION") {
1636  PIP_Solution_Node* const sol = new PIP_Solution_Node(0);
1637  false_child = sol;
1638  if (!sol->ascii_load(s)) {
1639  return false;
1640  }
1641  }
1642  else {
1643  // Unknown node kind.
1644  return false;
1645  }
1646 
1647  // Loaded all info.
1648  PPL_ASSERT(OK());
1649  return true;
1650 }
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
bool ascii_load(std::istream &s)
Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this ...
Definition: PIP_Tree.cc:1830
PIP_Decision_Node(const PIP_Problem *owner, PIP_Tree_Node *fcp, PIP_Tree_Node *tcp)
Builds a decision node having fcp and tcp as child.
Definition: PIP_Tree.cc:1082
virtual bool OK() const
Returns true if and only if *this is well formed.
Definition: PIP_Tree.cc:1335
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.
bool Parma_Polyhedra_Library::PIP_Decision_Node::check_ownership ( const PIP_Problem owner) const
privatevirtual

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

Implements Parma_Polyhedra_Library::PIP_Tree_Node.

Definition at line 1141 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Tree_Node::check_ownership(), false_child, Parma_Polyhedra_Library::PIP_Tree_Node::get_owner(), and true_child.

1141  {
1142  return get_owner() == owner
1143  && (false_child == 0 || false_child->check_ownership(owner))
1144  && (true_child == 0 || true_child->check_ownership(owner));
1145 }
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
const PIP_Problem * get_owner() const
Returns a pointer to the PIP_Problem owning object.
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...
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.
const PIP_Tree_Node * Parma_Polyhedra_Library::PIP_Decision_Node::child_node ( bool  b) const
inline

Returns a const pointer to the b (true or false) branch of *this.

Definition at line 92 of file PIP_Tree_inlines.hh.

92  {
93  return b ? true_child : false_child;
94 }
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.
PIP_Tree_Node * Parma_Polyhedra_Library::PIP_Decision_Node::child_node ( bool  b)
inline

Returns a pointer to the b (true or false) branch of *this.

Definition at line 98 of file PIP_Tree_inlines.hh.

98  {
99  return b ? true_child : false_child;
100 }
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.
PIP_Tree_Node * Parma_Polyhedra_Library::PIP_Decision_Node::clone ( ) const
virtual

Returns a pointer to a dynamically-allocated copy of *this.

Implements Parma_Polyhedra_Library::PIP_Tree_Node.

Definition at line 1868 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Tree_Node::PIP_Decision_Node.

1868  {
1869  return new PIP_Decision_Node(*this);
1870 }
PIP_Decision_Node(const PIP_Problem *owner, PIP_Tree_Node *fcp, PIP_Tree_Node *tcp)
Builds a decision node having fcp and tcp as child.
Definition: PIP_Tree.cc:1082
memory_size_type Parma_Polyhedra_Library::PIP_Decision_Node::external_memory_in_bytes ( ) const
virtual

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

Implements Parma_Polyhedra_Library::PIP_Tree_Node.

Definition at line 3755 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Tree_Node::external_memory_in_bytes().

3755  {
3757  PPL_ASSERT(true_child != 0);
3759  if (false_child != 0) {
3761  }
3762  return n;
3763 }
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
virtual memory_size_type external_memory_in_bytes() const =0
Returns the size in bytes of the memory managed by *this.
Definition: PIP_Tree.cc:3741
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
virtual memory_size_type total_memory_in_bytes() const =0
Returns the total size in bytes of the memory occupied by *this.
bool Parma_Polyhedra_Library::PIP_Decision_Node::OK ( ) const
virtual

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

Implements Parma_Polyhedra_Library::PIP_Tree_Node.

Definition at line 1335 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Tree_Node::constraints_, Parma_Polyhedra_Library::Implementation::num_constraints(), and Parma_Polyhedra_Library::PIP_Tree_Node::OK().

1335  {
1336  // Perform base class well-formedness check on this node.
1337  if (!PIP_Tree_Node::OK()) {
1338  return false;
1339  }
1340 
1341  // Recursively check if child nodes are well-formed.
1342  if (false_child != 0 && !false_child->OK()) {
1343  return false;
1344  }
1345  if (true_child != 0 && !true_child->OK()) {
1346  return false;
1347  }
1348 
1349  // Decision nodes should always have a true child.
1350  if (true_child == 0) {
1351 #ifndef NDEBUG
1352  std::cerr << "PIP_Decision_Node with no 'true' child.\n";
1353 #endif
1354  return false;
1355  }
1356 
1357  // Decision nodes with a false child must have exactly one constraint.
1358  if (false_child != 0) {
1360  if (dist != 1) {
1361 #ifndef NDEBUG
1362  std::cerr << "PIP_Decision_Node with a 'false' child has "
1363  << dist << " parametric constraints (should be 1).\n";
1364 #endif
1365  return false;
1366  }
1367  }
1368 
1369  // All checks passed.
1370  return true;
1371 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
dimension_type num_constraints(const Constraint_System &cs)
Helper returning number of constraints in system.
virtual bool OK() const =0
Returns true if and only if *this is well formed.
Definition: PIP_Tree.cc:1197
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.
Constraint_System constraints_
The local system of parameter constraints.
void Parma_Polyhedra_Library::PIP_Decision_Node::print_tree ( std::ostream &  s,
int  indent,
const std::vector< bool > &  pip_dim_is_param,
dimension_type  first_art_dim 
) const
protectedvirtual

Prints on s the tree rooted in *this.

Implements Parma_Polyhedra_Library::PIP_Tree_Node.

Definition at line 3862 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Tree_Node::art_parameter_count(), Parma_Polyhedra_Library::PIP_Tree_Node::indent_and_print(), and Parma_Polyhedra_Library::PIP_Tree_Node::print_tree().

3864  {
3865  // First print info common to decision and solution nodes.
3866  PIP_Tree_Node::print_tree(s, indent, pip_dim_is_param, first_art_dim);
3867 
3868  // Then print info specific of decision nodes.
3869  const dimension_type child_first_art_dim
3870  = first_art_dim + art_parameter_count();
3871 
3872  PPL_ASSERT(true_child != 0);
3873  true_child->print_tree(s, indent+1, pip_dim_is_param, child_first_art_dim);
3874 
3875  indent_and_print(s, indent, "else\n");
3876 
3877  if (false_child != 0) {
3878  false_child->print_tree(s, indent+1, pip_dim_is_param,
3879  child_first_art_dim);
3880  }
3881  else {
3882  indent_and_print(s, indent+1, "_|_\n");
3883  }
3884 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
dimension_type art_parameter_count() const
Returns the number of local artificial parameters.
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
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.
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
void Parma_Polyhedra_Library::PIP_Decision_Node::set_owner ( const PIP_Problem owner)
privatevirtual

Sets the pointer to the PIP_Problem owning object.

Implements Parma_Polyhedra_Library::PIP_Tree_Node.

Definition at line 1125 of file PIP_Tree.cc.

References false_child, Parma_Polyhedra_Library::PIP_Tree_Node::owner_, Parma_Polyhedra_Library::PIP_Tree_Node::set_owner(), and true_child.

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

1125  {
1126  owner_ = owner;
1127  if (false_child != 0) {
1128  false_child->set_owner(owner);
1129  }
1130  if (true_child != 0) {
1131  true_child->set_owner(owner);
1132  }
1133 }
const PIP_Problem * owner_
A pointer to the PIP_Problem object owning this node.
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
virtual void set_owner(const PIP_Problem *owner)=0
Sets the pointer to the PIP_Problem owning object.
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.
PIP_Tree_Node * Parma_Polyhedra_Library::PIP_Decision_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 
)
protectedvirtual

Implements pure virtual method PIP_Tree_Node::solve.

Implements Parma_Polyhedra_Library::PIP_Tree_Node.

Definition at line 1397 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Tree_Node::artificial_parameters, Parma_Polyhedra_Library::Constraint_System::begin(), Parma_Polyhedra_Library::PIP_Tree_Node::compatibility_check(), Parma_Polyhedra_Library::PIP_Tree_Node::constraints_, Parma_Polyhedra_Library::Constraint_System::empty(), Parma_Polyhedra_Library::Constraint_System::end(), Parma_Polyhedra_Library::PIP_Tree_Node::indent_and_print(), Parma_Polyhedra_Library::Constraint_System::insert(), Parma_Polyhedra_Library::Implementation::num_constraints(), Parma_Polyhedra_Library::Matrix< Row >::num_rows(), Parma_Polyhedra_Library::PIP_Tree_Node::OK(), Parma_Polyhedra_Library::PIP_Solution_Node::OK(), Parma_Polyhedra_Library::PIP_Tree_Node::parent(), Parma_Polyhedra_Library::PIP_Tree_Node::parent_merge(), PPL_USED, Parma_Polyhedra_Library::PIP_Tree_Node::set_parent(), and Parma_Polyhedra_Library::swap().

1402  {
1403  PPL_ASSERT(indent_level >= 0);
1404 #ifdef NOISY_PIP_TREE_STRUCTURE
1405  indent_and_print(std::cerr, indent_level, "=== SOLVING DECISION NODE\n");
1406 #else
1407  PPL_USED(indent_level);
1408 #endif
1409  PPL_ASSERT(true_child != 0);
1410  Matrix<Row> context_true(context);
1411  Variables_Set all_params(params);
1412  const dimension_type num_art_params = artificial_parameters.size();
1413  add_artificial_parameters(context_true, all_params, space_dim,
1414  num_art_params);
1415  merge_assign(context_true, constraints_, all_params);
1416  const bool has_false_child = (false_child != 0);
1417  const bool has_true_child = (true_child != 0);
1418 #ifdef NOISY_PIP_TREE_STRUCTURE
1419  indent_and_print(std::cerr, indent_level,
1420  "=== DECISION: SOLVING THEN CHILD\n");
1421 #endif
1422  true_child = true_child->solve(pip, check_feasible_context,
1423  context_true, all_params, space_dim,
1424  indent_level + 1);
1425 
1426  if (has_false_child) {
1427  // Decision nodes with false child must have exactly one constraint
1429  // NOTE: modify context_true in place, complementing its last constraint.
1430  Matrix<Row>& context_false = context_true;
1431  Row& last = context_false[context_false.num_rows() - 1];
1432  complement_assign(last, last, 1);
1433 #ifdef NOISY_PIP_TREE_STRUCTURE
1434  indent_and_print(std::cerr, indent_level,
1435  "=== DECISION: SOLVING ELSE CHILD\n");
1436 #endif
1437  false_child = false_child->solve(pip, check_feasible_context,
1438  context_false, all_params, space_dim,
1439  indent_level + 1);
1440  }
1441 
1442  if (true_child == 0 && false_child == 0) {
1443  // No children: the whole subtree is unfeasible.
1444 #ifdef NOISY_PIP_TREE_STRUCTURE
1445  indent_and_print(std::cerr, indent_level,
1446  "=== DECISION: BOTH BRANCHES NOW UNFEASIBLE: _|_\n");
1447 #endif
1448  delete this;
1449  return 0;
1450  }
1451 
1452  if (has_false_child && false_child == 0) {
1453  // False child has become unfeasible: merge this node's artificials with
1454  // the true child, while removing the local parameter constraints, which
1455  // are no longer discriminative.
1456 #ifdef NOISY_PIP_TREE_STRUCTURE
1457  indent_and_print(std::cerr, indent_level,
1458  "=== DECISION: ELSE BRANCH NOW UNFEASIBLE\n");
1459  indent_and_print(std::cerr, indent_level,
1460  "==> merge then branch with parent.\n");
1461 #endif
1462  PIP_Tree_Node* const node = true_child;
1463  node->parent_merge();
1464  node->set_parent(parent());
1465  true_child = 0;
1466  delete this;
1467  PPL_ASSERT(node->OK());
1468  return node;
1469  }
1470  else if (has_true_child && true_child == 0) {
1471  // True child has become unfeasible: merge this node's artificials
1472  // with the false child.
1473 #ifdef NOISY_PIP_TREE_STRUCTURE
1474  indent_and_print(std::cerr, indent_level,
1475  "=== DECISION: THEN BRANCH NOW UNFEASIBLE\n");
1476  indent_and_print(std::cerr, indent_level,
1477  "==> merge else branch with parent.\n");
1478 #endif
1479  PIP_Tree_Node* const node = false_child;
1480  node->parent_merge();
1481  node->set_parent(parent());
1482  false_child = 0;
1483  delete this;
1484  PPL_ASSERT(node->OK());
1485  return node;
1486  }
1487  else if (check_feasible_context) {
1488  // Test all constraints for redundancy with the context, and eliminate
1489  // them if not necessary.
1490  Constraint_System cs;
1491  swap(cs, constraints_);
1492  for (Constraint_System::const_iterator ci = cs.begin(),
1493  ci_end = cs.end(); ci != ci_end; ++ci) {
1494  Matrix<Row> ctx_copy(context);
1495  merge_assign(ctx_copy, Constraint_System(*ci), all_params);
1496  Row& last = ctx_copy[ctx_copy.num_rows()-1];
1497  complement_assign(last, last, 1);
1498  if (compatibility_check(ctx_copy)) {
1499  // The constraint is not redundant with the context: keep it.
1500  constraints_.insert(*ci);
1501  }
1502  }
1503  // If the constraints set has become empty, only keep the true child.
1504  if (constraints_.empty()) {
1505 #ifdef NOISY_PIP_TREE_STRUCTURE
1506  indent_and_print(std::cerr, indent_level,
1507  "=== DECISION: NO BRANCHING CONSTRAINTS LEFT\n");
1508  indent_and_print(std::cerr, indent_level,
1509  "==> merge then branch with parent.\n");
1510 #endif
1511  PIP_Tree_Node* const node = true_child;
1512  node->parent_merge();
1513  node->set_parent(parent());
1514  true_child = 0;
1515  delete this;
1516  PPL_ASSERT(node->OK());
1517  return node;
1518  }
1519  }
1520  PPL_ASSERT(OK());
1521  return this;
1522 }
static bool compatibility_check(Matrix< Row > &s)
Checks whether a context matrix is satisfiable.
Definition: PIP_Tree.cc:2195
void swap(CO_Tree &x, CO_Tree &y)
size_t dimension_type
An unsigned integral type for representing space dimensions.
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
const PIP_Decision_Node * parent() const
Returns a pointer to this node's parent.
void insert(const Constraint &c)
Inserts in *this a copy of the constraint c, increasing the number of space dimensions if needed...
dimension_type num_constraints(const Constraint_System &cs)
Helper returning number of constraints in system.
PIP_Tree_Node(const PIP_Problem *owner)
Constructor: builds a node owned by *owner.
Definition: PIP_Tree.cc:916
void parent_merge()
Merges parent's artificial parameters into *this.
Definition: PIP_Tree.cc:1251
bool empty() const
Returns true if and only if *this has no constraints.
virtual bool OK() const
Returns true if and only if *this is well formed.
Definition: PIP_Tree.cc:1335
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.
Artificial_Parameter_Sequence artificial_parameters
The local sequence of expressions for local artificial parameters.
#define PPL_USED(v)
No-op macro that allows to avoid unused variable warnings from the compiler.
Definition: compiler.hh:39
Constraint_System constraints_
The local system of parameter constraints.
virtual 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)=0
Executes a parametric simplex on the tableau, under specified context.
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
memory_size_type Parma_Polyhedra_Library::PIP_Decision_Node::total_memory_in_bytes ( ) const
virtual

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

Implements Parma_Polyhedra_Library::PIP_Tree_Node.

Definition at line 3766 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Solution_Node::external_memory_in_bytes().

3766  {
3767  return sizeof(*this) + external_memory_in_bytes();
3768 }
virtual memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
Definition: PIP_Tree.cc:3755
void Parma_Polyhedra_Library::PIP_Decision_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 
)
protectedvirtual

Implements pure virtual method PIP_Tree_Node::update_tableau.

Implements Parma_Polyhedra_Library::PIP_Tree_Node.

Definition at line 1374 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Solution_Node::OK().

1379  {
1380 
1382  external_space_dim,
1383  first_pending_constraint,
1384  input_cs,
1385  parameters);
1386  if (false_child != 0) {
1388  external_space_dim,
1389  first_pending_constraint,
1390  input_cs,
1391  parameters);
1392  }
1393  PPL_ASSERT(OK());
1394 }
PIP_Tree_Node * false_child
Pointer to the "false" child of *this.
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.
virtual bool OK() const
Returns true if and only if *this is well formed.
Definition: PIP_Tree.cc:1335
PIP_Tree_Node * true_child
Pointer to the "true" child of *this.

Friends And Related Function Documentation

bool PIP_Problem::ascii_load ( std::istream &  s)
friend
friend class PIP_Solution_Node
friend

Definition at line 747 of file PIP_Tree_defs.hh.

Member Data Documentation

PIP_Tree_Node* Parma_Polyhedra_Library::PIP_Decision_Node::false_child
private

Pointer to the "false" child of *this.

Definition at line 753 of file PIP_Tree_defs.hh.

Referenced by check_ownership(), PIP_Decision_Node(), set_owner(), Parma_Polyhedra_Library::PIP_Solution_Node::solve(), and ~PIP_Decision_Node().

PIP_Tree_Node* Parma_Polyhedra_Library::PIP_Decision_Node::true_child
private

Pointer to the "true" child of *this.

Definition at line 756 of file PIP_Tree_defs.hh.

Referenced by check_ownership(), PIP_Decision_Node(), set_owner(), and ~PIP_Decision_Node().


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