Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53776 - in sandbox/SOC/2009/function_graph: boost/function_graph libs/test
From: mlopez7_at_[hidden]
Date: 2009-06-09 12:43:19


Author: lopezeant
Date: 2009-06-09 12:43:19 EDT (Tue, 09 Jun 2009)
New Revision: 53776
URL: http://svn.boost.org/trac/boost/changeset/53776

Log:
added source, target, and edge functions and passed the newly added assertion test
Text files modified:
   sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp | 84 ++++++++++++++++++++--------------------
   sandbox/SOC/2009/function_graph/libs/test/test1.cpp | 25 +++++------
   2 files changed, 54 insertions(+), 55 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-06-09 12:43:19 EDT (Tue, 09 Jun 2009)
@@ -23,8 +23,8 @@
 /** Edge type */
 template <typename Result, typename Vertex>
 struct func_graph_edge {
- typedef typename Result result_type;
- typedef typename Vertex vertex_descriptor;
+ typedef Result result_type;
+ typedef Vertex vertex_descriptor;
 
     func_graph_edge(result_type rslt,
                     vertex_descriptor src,
@@ -32,16 +32,10 @@
         : result(rslt), source(src), target(trg)
     { }
 
- vertex_descriptor source() const
- { return source; }
-
- vertex_descriptor target() const
- { return target; }
-
     result_type result;
     vertex_descriptor source;
     vertex_descriptor target;
-}
+};
 
 } // detail namespace
 
@@ -55,8 +49,9 @@
 
     typedef Func function_type;
     typedef typename function_type::first_argument_type vertex_type;
- typedef typename func_graph_edge<function_type::result_type,
- vertex_type> edge_type;
+ typedef typename function_type::result_type result_type;
+ typedef typename detail::func_graph_edge<result_type,
+ vertex_type> edge_type;
 
     /** Constructor - Default */
     function_graph_base()
@@ -68,7 +63,7 @@
     { }
 
     // Allow access to the function edge_ holds, not edge_ itself.
- edge_type edge (vertex_type v1, vertex_type v2) const
+ result_type edge (vertex_type v1, vertex_type v2) const
     { return edge_(v1, v2); }
 
     function_type edge_;
@@ -91,16 +86,17 @@
  * set_edge is part of the interface. Paired with it is the default constructor.
  */
 template <typename Result, typename Vertex>
-struct function_graph <function <Result(Vertex, Vertex)> >
- : public function_graph_base <function <Result(Vertex, Vertex)> >
+struct function_graph<function<Result(Vertex, Vertex)> >
+ : public function_graph_base<function<Result(Vertex, Vertex)> >
 {
- friend
- typedef function_graph_base <function <Result(Vertex, Vertex)> > Base;
+ typedef function_graph_base<function<Result(Vertex, Vertex)> > Base;
+ typedef function_graph<function<Result(Vertex, Vertex)> > This;
 public:
 
     typedef typename Base::function_type function_type;
     typedef typename Base::vertex_type vertex_descriptor;
     typedef typename Base::edge_type edge_descriptor;
+ typedef typename Base::result_type result_type;
     typedef directed_tag directed_category;
     typedef disallow_parallel_edge_tag edge_parallel_category;
     typedef adjacency_matrix_tag traversal_category;
@@ -134,10 +130,22 @@
 
 
 /**
- * source is part of the incedence graph concept. It returns the
+ * source(e, g) and target(e, g) are part of the incedence graph concept.
  */
 
+template <typename Result, typename Vertex>
+Vertex source(detail::func_graph_edge<Result, Vertex> const& e,
+ function_graph<function<Result(Vertex, Vertex)> > const& g)
+{
+ return e.source;
+}
 
+template <typename Result, typename Vertex>
+Vertex target(detail::func_graph_edge<Result, Vertex> const& e,
+ function_graph<function<Result(Vertex, Vertex)> > const& g)
+{
+ return e.target;
+}
 
 
 
@@ -150,37 +158,29 @@
 // Method of dealing with the different types of edge returns.
 namespace detail {
 
-// Defaults to a function that always returns a value (ie, a complete graph)
-//template <typename Edge>
-//std::pair<Edge, bool> get_edge_pair(Edge const& edge)
-//{ return std::make_pair(edge, true); }
+// Defaults to a function that always returns an object (ie, a complete graph)
+template <typename Result>
+bool edge_exists(Result const& result)
+{ return true; }
 // Functions returning a boolean result are redundant
-//template<>
-//std::pair<bool, bool> get_edge_pair<bool>(bool const& edge)
-//{ return std::make_pair(edge, edge); }
-// optional is being considered
-/*
 template<>
-std::pair<Edge, bool> get_edge_pair<optional<?> >(optional<?> edge);*/
-
-
+bool edge_exists<bool>(bool const& result)
+{ return result; }
 
 } // detail namespace
 
-template <typename Edge, typename Vertex>
-std::pair<typename function_graph<function<Edge(Vertex, Vertex)> >
- ::edge_descriptor,
- bool>
-edge(typename function_graph<function<Edge(Vertex, Vertex)> >
- ::vertex_descriptor u,
- typename function_graph<function<Edge(Vertex, Vertex)> >
- ::vertex_descriptor v,
- function_graph<function<Edge(Vertex, Vertex)> > const& g)
+#define FUNC_GRAPH function_graph<function<Result(Vertex, Vertex)> >
+
+template <typename Result, typename Vertex>
+std::pair<typename FUNC_GRAPH::edge_descriptor, bool>
+edge(typename FUNC_GRAPH::vertex_descriptor u,
+ typename FUNC_GRAPH::vertex_descriptor v,
+ FUNC_GRAPH const& g)
 {
- typedef typename function_graph<function<Edge(Vertex, Vertex)> > graph;
- typedef typename graph::edge_descriptor;
- edge_descriptor e = graph.edge(u, v);
- return detail::get_edge_pair<edge_descriptor>(e);
+ typedef FUNC_GRAPH graph_type;
+ typedef typename FUNC_GRAPH::edge_descriptor edge_descriptor;
+ edge_descriptor e(g.edge(u, v), u, v);
+ return std::make_pair(e, detail::edge_exists(e.result));
 }
 
 } // boost namespace

Modified: sandbox/SOC/2009/function_graph/libs/test/test1.cpp
==============================================================================
--- sandbox/SOC/2009/function_graph/libs/test/test1.cpp (original)
+++ sandbox/SOC/2009/function_graph/libs/test/test1.cpp 2009-06-09 12:43:19 EDT (Tue, 09 Jun 2009)
@@ -9,10 +9,11 @@
 #include <vector>
 #include <utility>
 #include "function_graph.hpp"
+#include <cassert>
 
 template <typename T>
 struct less_than {
- bool operator()(T a, T b) { return a < b; }
+ bool operator() (T a, T b) { return a < b; }
 };
 
 int main()
@@ -23,23 +24,21 @@
     typedef boost::function_graph<function_type> graph;
     typedef graph::edge_descriptor edge_descriptor;
     function_type f = less_than<int>();
- function_type g = less_than<int>();
     graph funcGraph(f);
-
- ////////
- // Set a new function to the graph.
- funcGraph.set_function(g);
-
+ graph::vertex_descriptor x = 1;
+ graph::vertex_descriptor y = 2;
+
     ////////
- // Check the edge output.
- std::cout << "2 < 1 check ";
- if(funcGraph.edge(2,1)) std::cout << "fails." << "\n";
- else std::cout << "passes." << "\n";
+ // Assert an edge taken from
+ // Note that edge().first is the edge object
+ graph::edge_descriptor e = edge(x, y, funcGraph).first;
+ assert(source(e,funcGraph) == x);
+ assert(target(e,funcGraph) == y);
 
     ////////
     // Check the adjacency matrix edge
- std::pair<edge_descriptor, bool> edge_pair = boost::edge(1, 2, funcGraph);
- std::cout << edge_pair.first << "\n";
+ /*std::pair<edge_descriptor, bool> edge_pair = boost::edge(1, 2, funcGraph);
+ std::cout << edge_pair.first << "\n";*/
 
     
     


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