graph_clustering.cc 2.19 KB
Newer Older
Tiago Peixoto's avatar
Tiago Peixoto committed
1
2
// graph-tool -- a general graph modification and manipulation thingy
//
Tiago Peixoto's avatar
Tiago Peixoto committed
3
// Copyright (C) 2007-2012 Tiago de Paula Peixoto <tiago@skewed.de>
Tiago Peixoto's avatar
Tiago Peixoto committed
4
5
6
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
Tiago Peixoto's avatar
Tiago Peixoto committed
7
// as published by the Free Software Foundation; either version 3
Tiago Peixoto's avatar
Tiago Peixoto committed
8
9
10
11
12
13
14
15
// 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
16
17
// along with this program. If not, see <http://www.gnu.org/licenses/>.

18
#include "graph_filtering.hh"
Tiago Peixoto's avatar
Tiago Peixoto committed
19
20
21
22
23

#include "graph.hh"
#include "graph_selectors.hh"
#include "graph_properties.hh"

24
25
#include "graph_clustering.hh"

26
27
#include "random.hh"

28
29
#include <boost/python.hpp>

Tiago Peixoto's avatar
Tiago Peixoto committed
30
31
32
33
using namespace std;
using namespace boost;
using namespace graph_tool;

34
python::tuple global_clustering(GraphInterface& g)
Tiago Peixoto's avatar
Tiago Peixoto committed
35
{
36
    double c, c_err;
37
38
39
    bool directed = g.GetDirected();
    g.SetDirected(false);
    run_action<graph_tool::detail::never_directed>()
40
        (g, bind<void>(get_global_clustering(), _1, ref(c), ref(c_err)))();
41
42
    g.SetDirected(directed);
    return python::make_tuple(c, c_err);
Tiago Peixoto's avatar
Tiago Peixoto committed
43
44
}

45
void local_clustering(GraphInterface& g, boost::any prop)
Tiago Peixoto's avatar
Tiago Peixoto committed
46
{
47
48
49
    bool directed = g.GetDirected();
    g.SetDirected(false);
    run_action<graph_tool::detail::never_directed>()
50
        (g, bind<void>(set_clustering_to_property(), _1, _2),
51
52
53
         writable_vertex_scalar_properties())(prop);
    g.SetDirected(directed);
}
Tiago Peixoto's avatar
Tiago Peixoto committed
54

55
using namespace boost::python;
56

57
void extended_clustering(GraphInterface& g, python::list props);
58
59
void get_motifs(GraphInterface& g, size_t k, python::list subgraph_list,
                python::list hist, python::list p, bool comp_iso,
60
                bool fill_list, rng_t& rng);
61
62
63
64
65
66

BOOST_PYTHON_MODULE(libgraph_tool_clustering)
{
    def("global_clustering", &global_clustering);
    def("local_clustering", &local_clustering);
    def("extended_clustering", &extended_clustering);
67
    def("get_motifs", &get_motifs);
Tiago Peixoto's avatar
Tiago Peixoto committed
68
}