graph_histograms.cc 2.14 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Copyright (C) 2008  Tiago de Paula Peixoto <tiago@forked.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "graph.hh"
#include "graph_filtering.hh"
#include "graph_properties.hh"

#include "graph_histograms.hh"

#include <boost/python.hpp>

using namespace std;
using namespace boost;
using namespace graph_tool;

// this will return the vertex histogram of degrees or scalar properties
python::object
get_vertex_histogram(const GraphInterface& gi, GraphInterface::deg_t deg,
                     const vector<long double>& bins)
{
    python::object hist;
    python::object ret_bins;

    run_action<>()(gi, get_histogram<VertexHistogramFiller>(hist, bins,
                                                            ret_bins),
38
                   all_selectors())(degree_selector(deg));
39
40
41
42
43
    return python::make_tuple(hist, ret_bins);
}

// this will return the vertex histogram of degrees or scalar properties
python::object
44
get_edge_histogram(GraphInterface& gi, boost::any prop,
45
46
47
48
49
50
                   const vector<long double>& bins)
{
    python::object hist;
    python::object ret_bins;

    bool directed = gi.GetDirected();
51
    gi.SetDirected(true);
52
53
    run_action<graph_tool::detail::always_directed>()
        (gi, get_histogram<EdgeHistogramFiller>(hist, bins, ret_bins),
54
         edge_scalar_properties())(prop);
55
56
57
58
59
60
61
62
63
64
65
66
    gi.SetDirected(directed);

    return python::make_tuple(hist, ret_bins);
}

using namespace boost::python;

void export_histograms()
{
    def("get_vertex_histogram", &get_vertex_histogram);
    def("get_edge_histogram", &get_edge_histogram);
}