~ubuntu-branches/ubuntu/saucy/abyss/saucy

« back to all changes in this revision

Viewing changes to Graph/GraphUtil.h

  • Committer: Package Import Robot
  • Author(s): Shaun Jackman
  • Date: 2011-09-11 10:00:13 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110911100013-oa4m5fi036mjuwc8
Tags: 1.3.0-1
* New upstream release.
* Add libboost-graph-dev to Build-Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#include <iomanip>
6
6
#include <ostream>
7
7
 
 
8
/** Return the number of vertices that have been marked as removed. */
 
9
template <typename Graph>
 
10
typename graph_traits<Graph>::vertices_size_type
 
11
num_vertices_removed(const Graph& g)
 
12
{
 
13
        typedef graph_traits<Graph> GTraits;
 
14
        typedef typename GTraits::vertices_size_type vertices_size_type;
 
15
        typedef typename GTraits::vertex_iterator vertex_iterator;
 
16
        vertices_size_type n = 0;
 
17
        std::pair<vertex_iterator, vertex_iterator> vit = vertices(g);
 
18
        for (vertex_iterator u = vit.first; u != vit.second; ++u)
 
19
                if (get(vertex_removed, g, *u))
 
20
                        n++;
 
21
        return n;
 
22
}
 
23
 
 
24
/** Print statistics of the number of vertices and edges. */
8
25
template <typename Graph>
9
26
std::ostream& printGraphStats(std::ostream& out, const Graph& g)
10
27
{
 
28
        using std::setprecision;
11
29
        typedef typename graph_traits<Graph>::vertex_iterator
12
30
                vertex_iterator;
13
31
 
14
 
        unsigned v = num_vertices(g);
 
32
        unsigned v = num_vertices(g) - num_vertices_removed(g);
15
33
        unsigned e = num_edges(g);
16
34
        out << "V=" << v << " E=" << e
17
 
                << " E/V=" << (float)e / v << std::endl;
 
35
                << " E/V=" << setprecision(3) << (float)e / v << std::endl;
18
36
 
19
37
        // Print a histogram of the degree.
20
38
        Histogram h;
21
39
        std::pair<vertex_iterator, vertex_iterator> vit = vertices(g);
22
 
        for (vertex_iterator u = vit.first; u != vit.second; ++u)
 
40
        for (vertex_iterator u = vit.first; u != vit.second; ++u) {
 
41
                if (get(vertex_removed, g, *u))
 
42
                        continue;
23
43
                h.insert(out_degree(*u, g));
 
44
        }
24
45
        unsigned n = h.size();
25
46
        unsigned n0 = h.count(0), n1 = h.count(1), n234 = h.count(2, 4);
26
47
        unsigned n5 = n - (n0 + n1 + n234);
27
 
        using std::setprecision;
28
48
        return out <<
29
49
                "Degree: " << h.barplot(h.maximum() + 1) << "\n"
30
50
                "        01234\n"