graph_clustering.cc 2.17 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 <boost/python.hpp>

Tiago Peixoto's avatar
Tiago Peixoto committed
28 29 30 31
using namespace std;
using namespace boost;
using namespace graph_tool;

32
python::tuple global_clustering(GraphInterface& g)
Tiago Peixoto's avatar
Tiago Peixoto committed
33
{
34
    double c, c_err;
35 36 37
    bool directed = g.GetDirected();
    g.SetDirected(false);
    run_action<graph_tool::detail::never_directed>()
38
        (g, bind<void>(get_global_clustering(), _1, ref(c), ref(c_err)))();
39 40
    g.SetDirected(directed);
    return 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 46 47
    bool directed = g.GetDirected();
    g.SetDirected(false);
    run_action<graph_tool::detail::never_directed>()
48
        (g, bind<void>(set_clustering_to_property(), _1, _2),
49 50 51
         writable_vertex_scalar_properties())(prop);
    g.SetDirected(directed);
}
Tiago Peixoto's avatar
Tiago Peixoto committed
52

53
using namespace boost::python;
54

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

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