graph_assortativity.cc 1.94 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/>.

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

#include "graph_assortativity.hh"
Tiago Peixoto's avatar
Tiago Peixoto committed
24 25 26 27

using namespace std;
using namespace graph_tool;

28
pair<double,double>
29
assortativity_coefficient(GraphInterface& gi,
30
                          GraphInterface::deg_t deg)
Tiago Peixoto's avatar
Tiago Peixoto committed
31
{
32
    double a, a_err;
33
    run_action<>()(gi,bind<void>(get_assortativity_coefficient(), _1, _2,
34
                                 ref(a), ref(a_err)), scalar_selectors())
35
        (degree_selector(deg));
36 37 38 39
    return make_pair(a, a_err);
}

pair<double,double>
40
scalar_assortativity_coefficient(GraphInterface& gi,
41
                                 GraphInterface::deg_t deg)
42 43
{
    double a, a_err;
44
    run_action<>()(gi, bind<void>(get_scalar_assortativity_coefficient(),
45
                                  _1, _2, ref(a), ref(a_err)),
46
                   scalar_selectors())
47
        (degree_selector(deg));
48
    return make_pair(a, a_err);
Tiago Peixoto's avatar
Tiago Peixoto committed
49
}
50 51 52 53 54 55 56 57 58 59

#include <boost/python.hpp>

using namespace boost::python;

void export_assortativity()
{
    def("assortativity_coefficient", &assortativity_coefficient);
    def("scalar_assortativity_coefficient", &scalar_assortativity_coefficient);
}