[PPL-devel] [GIT] ppl/ppl(master): Added operator<<() for class PIP_Tree_Node, printing the subtree.

Enea Zaffanella zaffanella at cs.unipr.it
Fri Feb 26 17:43:56 CET 2010


Module: ppl/ppl
Branch: master
Commit: a7fc5572e9b727d60580e0168a908457b59dc425
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=a7fc5572e9b727d60580e0168a908457b59dc425

Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date:   Fri Feb 26 17:27:40 2010 +0100

Added operator<<() for class PIP_Tree_Node, printing the subtree.

The output operator is based on public (non-virtual) method print(),
which calls the protected (virtual) method print_tree() after properly
setting up the needed arguments.

---

 src/PIP_Problem.cc   |   16 +----------
 src/PIP_Tree.cc      |   23 ++++++++++++++++
 src/PIP_Tree.defs.hh |   69 +++++++++++++++++++++++++++++++-------------------
 3 files changed, 68 insertions(+), 40 deletions(-)

diff --git a/src/PIP_Problem.cc b/src/PIP_Problem.cc
index 8df7d1b..a75270d 100644
--- a/src/PIP_Problem.cc
+++ b/src/PIP_Problem.cc
@@ -715,20 +715,8 @@ PPL::PIP_Problem::print_solution(std::ostream& s, unsigned indent) const {
     break;
 
   case OPTIMIZED:
-    {
-      PPL_ASSERT(current_solution);
-      PPL_ASSERT(internal_space_dim == external_space_dim);
-      // For convenience, map pip problem vars and params on a vector.
-      std::vector<bool> pip_dim_is_param(internal_space_dim);
-      for (Variables_Set::const_iterator p = parameters.begin(),
-             p_end = parameters.end(); p != p_end; ++p)
-        pip_dim_is_param[*p] = true;
-
-      current_solution->print_tree(s, indent,
-                                   pip_dim_is_param,
-                                   // NOTE: first_art_dim == space_dim.
-                                   internal_space_dim);
-    }
+    PPL_ASSERT(current_solution != 0);
+    current_solution->print(s, indent);
     break;
 
   case PARTIALLY_SATISFIABLE:
diff --git a/src/PIP_Tree.cc b/src/PIP_Tree.cc
index 4c6de77..6d35a82 100644
--- a/src/PIP_Tree.cc
+++ b/src/PIP_Tree.cc
@@ -276,6 +276,12 @@ row_normalize(Row& x, Coefficient& den) {
 namespace IO_Operators {
 
 std::ostream&
+operator<<(std::ostream& os, const PIP_Tree_Node& x) {
+  x.print(os);
+  return os;
+}
+
+std::ostream&
 operator<<(std::ostream& os, const PIP_Tree_Node::Artificial_Parameter& x) {
   const Linear_Expression& expr = static_cast<const Linear_Expression&>(x);
   os << "(" << expr << ") div " << x.denominator();
@@ -2458,6 +2464,23 @@ PIP_Tree_Node::indent_and_print(std::ostream& s,
 }
 
 void
+PIP_Tree_Node::print(std::ostream& s, unsigned indent) const {
+  const dimension_type pip_space_dim = get_owner()->space_dimension();
+  const Variables_Set& pip_params = get_owner()->parameter_space_dimensions();
+
+  std::vector<bool> pip_dim_is_param(pip_space_dim);
+  for (Variables_Set::const_iterator p = pip_params.begin(),
+         p_end = pip_params.end(); p != p_end; ++p)
+    pip_dim_is_param[*p] = true;
+
+  dimension_type first_art_dim = pip_space_dim;
+  for (const PIP_Tree_Node* node = parent(); node != 0; node = node->parent())
+    first_art_dim += node->art_parameter_count();
+
+  print_tree(s, indent, pip_dim_is_param, first_art_dim);
+}
+
+void
 PIP_Tree_Node::print_tree(std::ostream& s, unsigned indent,
                           const std::vector<bool>& pip_dim_is_param,
                           dimension_type first_art_dim) const {
diff --git a/src/PIP_Tree.defs.hh b/src/PIP_Tree.defs.hh
index 87d4663..e0a733c 100644
--- a/src/PIP_Tree.defs.hh
+++ b/src/PIP_Tree.defs.hh
@@ -109,20 +109,8 @@ public:
 
     \param indent
     The amount of indentation.
-
-    \param pip_dim_is_param
-    A 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).
-
-    \param first_art_dim
-    The first space dimension corresponding to an artificial parameter
-    that was created in this node (if any).
   */
-  virtual void print_tree(std::ostream& s,
-                          unsigned indent,
-                          const std::vector<bool>& pip_dim_is_param,
-                          dimension_type first_art_dim) const;
+  void print(std::ostream& s, unsigned indent = 0) const;
 
   //! Dumps to \p s an ASCII representation of \p *this.
   void ascii_dump(std::ostream& s) const;
@@ -218,6 +206,28 @@ protected:
   //! Inserts a new parametric constraint in internal Row format
   void add_constraint(const Row& x, const Variables_Set& parameters);
 
+  //! Prints on \p s the tree rooted in \p *this.
+  /*!
+    \param s
+    The output stream.
+
+    \param indent
+    The amount of indentation.
+
+    \param pip_dim_is_param
+    A 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).
+
+    \param first_art_dim
+    The first space dimension corresponding to an artificial parameter
+    that was created in this node (if any).
+  */
+  virtual void print_tree(std::ostream& s,
+                          unsigned indent,
+                          const std::vector<bool>& pip_dim_is_param,
+                          dimension_type first_art_dim) const;
+
   //! A helper function used when printing PIP trees.
   static void
   indent_and_print(std::ostream& s, unsigned indent, const char* str);
@@ -318,12 +328,6 @@ public:
   //! Returns \p this.
   virtual const PIP_Solution_Node* as_solution() const;
 
-  //! Prints on \p s the tree rooted in \p *this.
-  virtual void print_tree(std::ostream& s,
-                          unsigned indent,
-                          const std::vector<bool>& pip_dim_is_param,
-                          dimension_type first_art_dim) const;
-
   /*! \brief
     Returns a parametric expression for the values of problem variable \p var.
 
@@ -691,6 +695,12 @@ protected:
                     Matrix& context,
                     dimension_type& space_dimension);
 
+  //! Prints on \p s the tree rooted in \p *this.
+  virtual void print_tree(std::ostream& s,
+                          unsigned indent,
+                          const std::vector<bool>& pip_dim_is_param,
+                          dimension_type first_art_dim) const;
+
 }; // class PIP_Solution_Node
 
 
@@ -715,12 +725,6 @@ public:
   //! Returns a pointer to the \p b (true or false) branch of \p *this.
   PIP_Tree_Node* child_node(bool b);
 
-  //! Prints on \p s the tree rooted in \p *this.
-  virtual void print_tree(std::ostream& s,
-                          unsigned indent,
-                          const std::vector<bool>& pip_dim_is_param,
-                          dimension_type first_art_dim) const;
-
   //! Dumps to \p s an ASCII representation of \p *this.
   void ascii_dump(std::ostream& s) const;
 
@@ -836,10 +840,23 @@ protected:
                                const Matrix& context,
                                const Variables_Set& params,
                                dimension_type space_dimension);
-};
+
+  //! Prints on \p s the tree rooted in \p *this.
+  virtual void print_tree(std::ostream& s,
+                          unsigned indent,
+                          const std::vector<bool>& pip_dim_is_param,
+                          dimension_type first_art_dim) const;
+
+}; // class PIP_Decision_Node
 
 namespace IO_Operators {
 
+//! Output operator: prints the solution tree rooted in \p x.
+/*! \relates Parma_Polyhedra_Library::PIP_Tree_Node */
+std::ostream& operator<<(std::ostream& os, const PIP_Tree_Node& x);
+
+//! Output operator.
+/*! \relates Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter */
 std::ostream& operator<<(std::ostream& os,
                          const PIP_Tree_Node::Artificial_Parameter& x);
 




More information about the PPL-devel mailing list