graph_community_network.cc 2.8 KB
Newer Older
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>
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
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
19
20
21
22
#include "graph_filtering.hh"
#include "graph.hh"
#include "graph_selectors.hh"
#include "graph_properties.hh"

23
24
25
26
27
//#include <boost/lambda/bind.hpp>
#include <boost/bind.hpp>
#include <boost/bind/placeholders.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/python.hpp>
28

29
#include "graph_community_network.hh"
30
31
32

using namespace std;
using namespace boost;
33

34
35
using namespace graph_tool;

36
37
38
39

void community_network(GraphInterface& gi, GraphInterface& cgi,
                       boost::any community_property, boost::any vertex_count,
                       boost::any edge_count, boost::any weight)
40
{
41
42
43
44
45
46
47
48
49
    typedef DynamicPropertyMapWrap<double,GraphInterface::edge_t> weight_map_t;
    typedef ConstantPropertyMap<double,GraphInterface::edge_t> no_weight_map_t;
    typedef mpl::vector<weight_map_t,no_weight_map_t> weight_properties;

    if (weight.empty())
        weight = no_weight_map_t(1.0);
    else
        weight = weight_map_t(weight, edge_scalar_properties());

50
51
    typedef property_map_type::apply<int32_t,
                                     GraphInterface::vertex_index_map_t>::type
52
53
        vcount_t;
    vcount_t vcount(gi.GetVertexIndex());
54
    try
55
    {
56
        vcount = any_cast<vcount_t>(vertex_count);
57
    }
58
    catch (bad_any_cast&)
59
    {
Tiago Peixoto's avatar
Tiago Peixoto committed
60
        throw ValueException("invalid vertex count property");
61
    }
62
63
64
65
66
67
68

    typedef property_map_types::apply<mpl::vector<int32_t,double>,
                                      GraphInterface::edge_index_map_t,
                                      mpl::bool_<false> >::type
        ecount_properties;

    if (!belongs<ecount_properties>()(edge_count))
Tiago Peixoto's avatar
Tiago Peixoto committed
69
        throw ValueException("invalid edge count property");
70
71

     run_action<>()(gi, bind<void>(get_community_network(), _1,
72
73
74
                                   ref(cgi.GetGraph()), cgi.GetVertexIndex(),
                                   cgi.GetEdgeIndex(), _2,
                                   _3, vcount, _4),
75
76
77
                   vertex_properties(), weight_properties(),
                   ecount_properties())
        (community_property, weight, edge_count);
78
}