graph_assortativity.cc 2.01 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  Tiago de Paula Peixoto <tiago@forked.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 30
assortativity_coefficient(const GraphInterface& gi,
                          GraphInterface::deg_t deg)
Tiago Peixoto's avatar
Tiago Peixoto committed
31
{
32
    using namespace boost::lambda;
33
    double a, a_err;
34 35 36
    run_action<>()(gi,bind<void>(get_assortativity_coefficient(), _1, _2,
                                 var(a), var(a_err)), all_selectors())
        (degree_selector(deg, gi));
37 38 39 40
    return make_pair(a, a_err);
}

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

#include <boost/python.hpp>

using namespace boost::python;

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