graph_correlations.cc 3.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/>.

18
#include "graph_filtering.hh"
Tiago Peixoto's avatar
Tiago Peixoto committed
19 20 21 22 23 24 25

#include <boost/lambda/bind.hpp>

#include "graph.hh"
#include "histogram.hh"
#include "graph_selectors.hh"
#include "graph_properties.hh"
26 27

#include "graph_correlations.hh"
Tiago Peixoto's avatar
Tiago Peixoto committed
28 29 30 31 32 33

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

34 35 36 37 38 39 40 41 42 43 44
// implementations spread across different compile units to minimize memory
// usage during compilation
void graph_correlations_imp1(const GraphInterface& g, hist2d_t& hist,
                             boost::any deg1, boost::any deg2,
                             boost::any weight);
void graph_correlations_imp2(const GraphInterface& g, hist2d_t& hist,
                             boost::any deg1, boost::any deg2,
                             boost::any weight);
void graph_correlations_imp3(const GraphInterface& g, hist2d_t& hist,
                             boost::any deg1, boost::any deg2,
                             boost::any weight);
45

46
typedef ConstantPropertyMap<int,GraphInterface::edge_t> cweight_map_t;
Tiago Peixoto's avatar
Tiago Peixoto committed
47

48
hist2d_t
49
GraphInterface::GetVertexCorrelationHistogram(GraphInterface::deg_t deg1,
50
                                              GraphInterface::deg_t deg2,
51
                                              string weight) const
Tiago Peixoto's avatar
Tiago Peixoto committed
52 53 54
{
    hist2d_t hist;

55
    try
56
    {
57 58 59
        any weight_prop;
        if (weight != "")
            weight_prop = prop(weight, _edge_index, _properties);
60
        else
61 62
            weight_prop = cweight_map_t(1);

63 64
        run_action<>()(*this, get_correlation_histogram<hist2d_t>(hist),
                       all_selectors(), all_selectors(),
65 66 67 68 69 70 71 72 73 74
                       mpl::vector<cweight_map_t>())
            (degree_selector(deg1, _properties),
             degree_selector(deg2, _properties), weight);
        graph_correlations_imp1(*this, hist, degree_selector(deg1, _properties),
                                degree_selector(deg2, _properties), weight);
        graph_correlations_imp2(*this, hist, degree_selector(deg1, _properties),
                                degree_selector(deg2, _properties), weight);
        graph_correlations_imp3(*this, hist, degree_selector(deg1, _properties),
                                degree_selector(deg2, _properties), weight);

Tiago Peixoto's avatar
Tiago Peixoto committed
75
    }
76
    catch (dynamic_get_failure &e)
Tiago Peixoto's avatar
Tiago Peixoto committed
77
    {
78
        throw GraphException("error getting scalar property: " +
79
                             string(e.what()));
Tiago Peixoto's avatar
Tiago Peixoto committed
80
    }
81

Tiago Peixoto's avatar
Tiago Peixoto committed
82 83
    return hist;
}