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) 2006-2016 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;

Tiago Peixoto's avatar
Tiago Peixoto committed
34
boost::python::tuple global_clustering(GraphInterface& g)
Tiago Peixoto's avatar
Tiago Peixoto committed
35
{
36
    double c, c_err;
37
    run_action<graph_tool::detail::never_directed>()
Tiago Peixoto's avatar
Tiago Peixoto committed
38
39
40
        (g, std::bind(get_global_clustering(), std::placeholders::_1,
                      std::ref(c), std::ref(c_err)))();
    return boost::python::make_tuple(c, c_err);
Tiago Peixoto's avatar
Tiago Peixoto committed
41
42
}

43
void local_clustering(GraphInterface& g, boost::any prop)
Tiago Peixoto's avatar
Tiago Peixoto committed
44
{
45
    run_action<>()
Tiago Peixoto's avatar
Tiago Peixoto committed
46
47
48
        (g, std::bind(set_clustering_to_property(),
                      std::placeholders::_1,
                      std::placeholders::_2),
49
50
         writable_vertex_scalar_properties())(prop);
}
Tiago Peixoto's avatar
Tiago Peixoto committed
51

52
using namespace boost::python;
53

Tiago Peixoto's avatar
Tiago Peixoto committed
54
55
56
57
void extended_clustering(GraphInterface& g, boost::python::list props);
void get_motifs(GraphInterface& g, size_t k, boost::python::list subgraph_list,
                boost::python::list hist, boost::python::list pvmaps, bool collect_vmaps,
                boost::python::list p, bool comp_iso, bool fill_list, rng_t& rng);
58
59
60
61
62
63

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