graph_assortativity.cc 2.13 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 21

#include "graph_filtering.hh"
#include "graph_selectors.hh"
#include "graph_properties.hh"
22 23 24
#include "graph.hh"

#include "graph_assortativity.hh"
Tiago Peixoto's avatar
Tiago Peixoto committed
25 26 27 28 29 30 31

using namespace std;
using namespace boost;
using namespace boost::lambda;
using namespace graph_tool;


32
pair<double,double>
33
GraphInterface::GetAssortativityCoefficient(GraphInterface::deg_t deg) const
Tiago Peixoto's avatar
Tiago Peixoto committed
34
{
35 36 37
    double a, a_err;
    try
    {
38 39 40 41
        run_action<>()(*this, 
                       bind<void>(get_assortativity_coefficient(), _1, _2,
                                  var(a), var(a_err)), all_selectors())
            (degree_selector(deg, _properties));
42 43 44
    }
    catch (dynamic_get_failure &e)
    {
45 46
        throw GraphException("error getting scalar property: " +
                             string(e.what()));
47 48 49 50 51 52
    }

    return make_pair(a, a_err);
}

pair<double,double>
53 54
GraphInterface::GetScalarAssortativityCoefficient(GraphInterface::deg_t deg)
    const
55 56
{
    double a, a_err;
Tiago Peixoto's avatar
Tiago Peixoto committed
57 58
    try
    {
59 60 61 62
        run_action<>()(*this, bind<void>(get_scalar_assortativity_coefficient(),
                                         _1, _2, var(a), var(a_err)),
                   all_selectors())
            (degree_selector(deg, _properties));
Tiago Peixoto's avatar
Tiago Peixoto committed
63 64 65
    }
    catch (dynamic_get_failure &e)
    {
66 67
        throw GraphException("error getting scalar property: " +
                             string(e.what()));
Tiago Peixoto's avatar
Tiago Peixoto committed
68 69
    }

70
    return make_pair(a, a_err);
Tiago Peixoto's avatar
Tiago Peixoto committed
71
}