Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54843 - in sandbox/SOC/2009/function_graph: boost/function_graph libs/test
From: mlopez7_at_[hidden]
Date: 2009-07-09 17:50:09


Author: lopezeant
Date: 2009-07-09 17:50:08 EDT (Thu, 09 Jul 2009)
New Revision: 54843
URL: http://svn.boost.org/trac/boost/changeset/54843

Log:
In and out edges are finished. test3.cpp tests the functions and iterators associated with in and out edge concepts and is also completed.
Text files modified:
   sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp | 91 ++++++++++++++++++++-------------------
   sandbox/SOC/2009/function_graph/libs/test/test3.cpp | 77 ++++++++++++++++++++++++++++-----
   2 files changed, 110 insertions(+), 58 deletions(-)

Modified: sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp
==============================================================================
--- sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp (original)
+++ sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp 2009-07-09 17:50:08 EDT (Thu, 09 Jul 2009)
@@ -22,10 +22,11 @@
 #include <boost/range/iterator.hpp>
 #include <iterator>
 
+
 namespace boost {
 
 template<typename Graph> struct function_graph_in_edge_iterator;
-//template<typename Graph> struct function_graph_out_edge_iterator;
+template<typename Graph> struct function_graph_out_edge_iterator;
 
 /** @name Domain Tags
  * @description Traits that identify the function_graph as either having a
@@ -201,11 +202,7 @@
     typedef typename range_iterator<vertex_iterator_range>::type
                          vertex_iterator;
     typedef function_graph_in_edge_iterator<This> in_edge_iterator;
- /*typedef function_graph_out_edge_iterator<
- result_type,
- vertex_descriptor,
- vertex_iterator_range
- > out_edge_iterator;*/
+ typedef function_graph_out_edge_iterator<This> out_edge_iterator;
     typedef finite_domain_tag domain_category;
 
     /** Constructor: takes a functor and range */
@@ -401,7 +398,7 @@
 
     vertex_iterator vertex_begin = begin(g.range_);
     vertex_iterator vertex_end = end(g.range_);
- while((vertex_begin != vertex_end) || !edge(*vertex_begin, v, g).second)
+ while((vertex_begin != vertex_end) && !edge(*vertex_begin, v, g).second)
     { ++vertex_begin; }
     in_edge_iterator in_edge_begin(g, v, vertex_begin, vertex_end);
     in_edge_iterator in_edge_end(g, v, vertex_end, vertex_end);
@@ -416,17 +413,17 @@
>
 out_edges(typename FUNC_GRAPH::vertex_descriptor const& u, FUNC_GRAPH const& g)
 {
- typedef FUNC_GRAPH Graph;
+ typedef function_graph<function<Result(Vertex, Vertex)>, Range> Graph;
     typedef typename Graph::out_edge_iterator out_edge_iterator;
     typedef typename Graph::vertex_iterator vertex_iterator;
     typedef std::pair<out_edge_iterator, out_edge_iterator> iter_range;
 
- vertex_iterator first_vertex_pair = begin(g.range_);
+ vertex_iterator vertex_begin = begin(g.range_);
     vertex_iterator vertex_end = end(g.range_);
- while((first_vertex_pair != vertex_end) || !g.edge_(first_vertex_pair, u))
- { ++first_vertex_pair; }
- out_edge_iterator out_edge_begin(first_vertex_pair, u);
- out_edge_iterator out_edge_end(vertex_end, u);
+ while((vertex_begin != vertex_end) && !edge(u, *vertex_begin, g).second)
+ { ++vertex_begin; }
+ out_edge_iterator out_edge_begin(g, u, vertex_begin, vertex_end);
+ out_edge_iterator out_edge_end(g, u, vertex_end, vertex_end);
 
     return std::make_pair(out_edge_begin, out_edge_end);
 }
@@ -495,16 +492,6 @@
     edge_descriptor operator*()
     { return edge_descriptor(edge(*vertex_begin_, vertex_, g_).first); }
 
- /*bool operator==(This const& rhs)
- {
- return g_ == true//rhs.g_ && vertex_ == rhs.vertex_ &&
- vertex_begin_ == rhs.vertex_begin_ &&
- vertex_end_ == rhs.vertex_end_*/;
- /*}
- bool operator!=(This const& rhs)
- { return !(*this == rhs); }*/
-
-
     graph_type const& g_;
     vertex_descriptor vertex_;
     vertex_iterator vertex_begin_;
@@ -535,17 +522,17 @@
  * @description Iterates through the in edges of a vertex.
  */
 
-template<typename Function, typename Edge, typename Range>
+template<typename Graph>
 struct function_graph_out_edge_iterator {
 private:
- typedef function_graph_out_edge_iterator<Function, Edge, Range> This;
+ typedef function_graph_out_edge_iterator<Graph> This;
 
 public:
- typedef Range vertex_iterator_range;
- typedef typename range_iterator<vertex_iterator_range>::type
- vertex_iterator;
- typedef Edge edge_descriptor;
- typedef Function function_type;
+ typedef Graph graph_type;
+ typedef typename graph_type::vertex_iterator vertex_iterator;
+ typedef typename graph_type::edge_descriptor edge_descriptor;
+ typedef typename graph_type::vertex_descriptor vertex_descriptor;
+ typedef typename graph_type::function_type function_type;
 
     /** Iterator traits */
     typedef std::input_iterator_tag iterator_category;
@@ -556,11 +543,12 @@
 
     /** @internal Constructors */
     //@{
- function_graph_out_edge_iterator(function_type const& f,
- vertex_iterator const& v,
- vertex_iterator const& v_begin,
- vertex_iterator const& v_end)
- : edge_(f),
+
+ function_graph_out_edge_iterator(graph_type const& g,
+ vertex_descriptor const& v,
+ vertex_iterator const& v_begin,
+ vertex_iterator const& v_end)
+ : g_(g),
           vertex_(v),
           vertex_begin_(v_begin),
           vertex_end_(v_end)
@@ -568,7 +556,7 @@
 
     // Copy constructor
     function_graph_out_edge_iterator(This const& cp)
- : edge_(cp.edge_),
+ : g_(cp.g_),
           vertex_(cp.vertex_),
           vertex_begin_(cp.vertex_begin_),
           vertex_end_(cp.vertex_end_)
@@ -576,31 +564,44 @@
     //@}
 
     /** Input Iterator operator overloads */
- function_graph_out_edge_iterator& operator++()
+ This& operator++()
     {
         // Cycle through the range until an edge is found,
         // or the end of the list is found
         do {
             ++vertex_begin_;
         } while((vertex_begin_ != vertex_end_) &&
- !edge_(*vertex_, *vertex_begin_));
+ !edge(vertex_, *vertex_begin_, g_).second);
 
         return *this;
     }
 
     edge_descriptor operator*()
- {
- return edge_descriptor(edge_(vertex_, *vertex_begin_),
- *vertex_begin_,
- *vertex_);
- }
+ { return edge_descriptor(edge(vertex_, *vertex_begin_, g_).first); }
 
- function_type edge_;
- vertex_iterator vertex_;
+ graph_type const& g_;
+ vertex_descriptor vertex_;
     vertex_iterator vertex_begin_;
     vertex_iterator vertex_end_;
 };
 
+template<typename Graph>
+bool operator==(function_graph_out_edge_iterator<Graph> const& lhs,
+ function_graph_out_edge_iterator<Graph> const& rhs)
+{
+ return lhs.vertex_ == rhs.vertex_ &&
+ lhs.vertex_begin_ == rhs.vertex_begin_ &&
+ lhs.vertex_end_ == rhs.vertex_end_;
+}
+
+template<typename Graph>
+bool operator!=(function_graph_out_edge_iterator<Graph> const& lhs,
+ function_graph_out_edge_iterator<Graph> const& rhs)
+{
+ return !(lhs.vertex_ == rhs.vertex_ &&
+ lhs.vertex_begin_ == rhs.vertex_begin_ &&
+ lhs.vertex_end_ == rhs.vertex_end_);
+}
 
 
 } // boost namespace

Modified: sandbox/SOC/2009/function_graph/libs/test/test3.cpp
==============================================================================
--- sandbox/SOC/2009/function_graph/libs/test/test3.cpp (original)
+++ sandbox/SOC/2009/function_graph/libs/test/test3.cpp 2009-07-09 17:50:08 EDT (Thu, 09 Jul 2009)
@@ -13,13 +13,15 @@
 #include <boost/range.hpp>
 #include <cassert>
 
+namespace test3 {
 // print an edge
-template<typename Result, typename Vertex>
-void print_edge(boost::detail::func_graph_edge<Result, Vertex> const& e)
+template<typename Graph>
+void print_edge(typename Graph::edge_descriptor const& e, Graph const& g)
 {
     std::cout << "\nEdge:\n" << " Source: " << e.source_ << "\n";
     std::cout << " Target: " << e.target_ << "\n";
 }
+} // namespace
 
 int main()
 {
@@ -41,7 +43,19 @@
     typedef std::pair<
                 boolean_graph::in_edge_iterator,
                 boolean_graph::in_edge_iterator
- > in_edge_range;
+ > in_edge_bool_range;
+ typedef std::pair<
+ weighted_graph::in_edge_iterator,
+ weighted_graph::in_edge_iterator
+ > in_edge_wght_range;
+ typedef std::pair<
+ boolean_graph::out_edge_iterator,
+ boolean_graph::out_edge_iterator
+ > out_edge_bool_range;
+ typedef std::pair<
+ weighted_graph::out_edge_iterator,
+ weighted_graph::out_edge_iterator
+ > out_edge_wght_range;
 
     ////////
     // Create function graphs
@@ -50,36 +64,73 @@
     weighted_graph weightedGraph(std::minus<long>(),
                                 std::make_pair(numbers.begin(), numbers.end()));
 
- ////////
- // Check graph boolean operators
- assert(booleanGraph == booleanGraph);
- assert(weightedGraph == weightedGraph);
+
 
     ////////
     // Check vertices(g)
     iterator_range correctRange = std::make_pair(numbers.begin(),
- numbers.end());
+ numbers.end());
     assert(vertices(booleanGraph) == correctRange);
     assert(vertices(weightedGraph) == correctRange);
 
+
+
     ////////
     // Check num_vertices
     std::vector<long>::size_type numVertices = numbers.size();
     assert(num_vertices(booleanGraph) == numVertices);
     assert(num_vertices(weightedGraph) == numVertices);
 
+
+
     ////////
     // Check in edges
     std::vector<long>::iterator aVertex = ++numbers.begin(); // aVector = 572
- in_edge_range in_edges_bool = in_edges(*aVertex, booleanGraph);
- // print all in_edges
+ in_edge_bool_range in_edges_bool = boost::in_edges(*aVertex, booleanGraph);
+ // Print all in_edges from booleanGraph to 572
+ // In other words, print pairs of numbers that are less than 572
     while(in_edges_bool.first != in_edges_bool.second)
     {
+ test3::print_edge(*in_edges_bool.first, booleanGraph);
         ++in_edges_bool.first;
     }
- //iterator_range in_edges_wght = in_edges(*aVertex, weightedGraph);
-
- std::cerr << "\nCompiled - What? It worked?\n\n";
+
+ in_edge_wght_range in_edges_wght = boost::in_edges(*aVertex, weightedGraph);
+ // Print all in_edges from weightedGraph to 572
+ // By the function, this prints in_edge - 572
+ while(in_edges_wght.first != in_edges_wght.second)
+ {
+ std::cout << boost::source(*in_edges_wght.first, weightedGraph)
+ << " - 572 = " << (*in_edges_wght.first).result_
+ << "\n";
+ ++in_edges_wght.first;
+ }
+
+
+ ////////
+ // Check out edges
+ ++ ++ ++aVertex; // aVertex now holds -2
+ out_edge_bool_range out_edges_bool = boost::out_edges(*aVertex, booleanGraph);
+ // Print all out_edges from booleanGraph to -2
+ // In other words, print pairs of numbers that are not less than -2
+ while(out_edges_bool.first != out_edges_bool.second)
+ {
+ test3::print_edge(*out_edges_bool.first, booleanGraph);
+ ++out_edges_bool.first;
+ }
+
+ out_edge_wght_range out_edges_wght = boost::out_edges(*aVertex, weightedGraph);
+ // Print all in_edges from weightedGraph to 572
+ // By the function, this prints in_edge - 572
+ while(out_edges_wght.first != out_edges_wght.second)
+ {
+ std::cout << "-2 - "
+ << boost::target(*out_edges_wght.first, weightedGraph)
+ << " = "
+ << (*out_edges_wght.first).result_
+ << "\n";
+ ++out_edges_wght.first;
+ }
 
     return 0;
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk