All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
graph_metrics.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_GRAPH_METRICS_HPP
16 #define PAAL_GRAPH_METRICS_HPP
17 
18 #include "basic_metrics.hpp"
19 
20 #include <boost/graph/johnson_all_pairs_shortest.hpp>
21 #include <boost/graph/floyd_warshall_shortest.hpp>
22 #include <boost/graph/adjacency_matrix.hpp>
23 
24 namespace paal {
25 namespace data_structures {
26 
27 namespace graph_type {
28 class sparse_tag;
29 class dense_tag;
30 class large_tag;
31 }
32 
38 template <typename Graph> struct graph_metric_traits {
39  //default graph_type
40  using graph_tag_type = graph_type::sparse_tag;
41 };
42 
43 
45 template <typename graph_tag_type> struct graph_metric_filler_impl;
46 
50 template <> struct graph_metric_filler_impl<graph_type::sparse_tag> {
59  template <typename Graph, typename ResultMatrix>
60  void fill_matrix(const Graph &g, ResultMatrix &rm) {
61  boost::johnson_all_pairs_shortest_paths(g, rm);
62  }
63 };
64 
68 template <> struct graph_metric_filler_impl<graph_type::dense_tag> {
69  template <typename Graph, typename ResultMatrix>
76  void fill_matrix(const Graph &g, ResultMatrix &rm) {
77  boost::floyd_warshall_all_pairs_shortest_paths(g, rm);
78  }
79 };
80 
89 // GENERIC
90 // GraphType could be sparse, dense, large ...
91 template <
92  typename Graph, typename DistanceType,
93  typename GraphType = typename graph_metric_traits<Graph>::graph_tag_type>
94 struct graph_metric : public array_metric<DistanceType>,
96  typename graph_metric_traits<Graph>::graph_tag_type> {
99  typename graph_metric_traits<Graph>::graph_tag_type> GMFBase;
100 
106  graph_metric(const Graph &g) : GMBase(num_vertices(g)) {
107  GMFBase::fill_matrix(g, GMBase::m_matrix);
108  }
109 };
110 
111 // TODO implement
113 template <typename Graph, typename DistanceType>
114 struct graph_metric<Graph, DistanceType, graph_type::large_tag> {
120  graph_metric(const Graph &g) { assert(false); }
121 };
122 
124 template <typename OutEdgeList, typename VertexList, typename Directed,
125  typename VertexProperties, typename EdgeProperties,
126  typename GraphProperties, typename EdgeList>
128  boost::adjacency_list<OutEdgeList, VertexList, Directed, VertexProperties,
129  EdgeProperties, GraphProperties, EdgeList>> {
130  typedef graph_type::sparse_tag graph_tag_type;
131 };
132 
134 template <typename Directed, typename VertexProperty, typename EdgeProperty,
135  typename GraphProperty, typename Allocator>
137  Directed, VertexProperty, EdgeProperty, GraphProperty, Allocator>> {
138  typedef graph_type::dense_tag graph_tag_type;
139 };
140 
141 }
142 }
143 
144 #endif // PAAL_GRAPH_METRICS_HPP
Adopts boost graph as Metric.
void fill_matrix(const Graph &g, ResultMatrix &rm)
fill_matrix function
type of adjacency_matrix, for given metric
graph_metric(const Graph &g)
constructor
this metric is rectangle_array_metric with N == M.
void fill_matrix(const Graph &g, ResultMatrix &rm)
fill_matrixFunction
generic strategies of computing metric