Commit 9138901a authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix inconsistent degree()/in_degree()/in_neighbours() semantics for undirected graphs

parent 977b4516
......@@ -92,11 +92,7 @@ struct get_eigentrust
t_temp[v] = 0;
for (const auto& e : in_or_out_edges_range(v, g))
{
typename graph_traits<Graph>::vertex_descriptor s;
if (graph_tool::is_directed(g))
s = source(e, g);
else
s = target(e, g);
auto s = source(e, g);
if (!graph_tool::is_directed(g))
t_temp[v] += get(c, e) * t[s] / abs(c_sum[s]);
else
......
......@@ -67,11 +67,7 @@ struct get_eigenvector
c_temp[v] = 0;
for (const auto& e : in_or_out_edges_range(v, g))
{
typename graph_traits<Graph>::vertex_descriptor s;
if (graph_tool::is_directed(g))
s = source(e, g);
else
s = target(e, g);
auto s = source(e, g);
c_temp[v] += get(w, e) * c[s];
}
norm += power(c_temp[v], 2);
......
......@@ -78,11 +78,7 @@ struct get_hits
x_temp[v] = 0;
for (const auto& ie : in_or_out_edges_range(v, g))
{
typename graph_traits<Graph>::vertex_descriptor s;
if (graph_tool::is_directed(g))
s = source(ie, g);
else
s = target(ie, g);
auto s = source(ie, g);
x_temp[v] += get(w, ie) * y[s];
}
x_norm += power(x_temp[v], 2);
......
......@@ -64,11 +64,7 @@ struct get_katz
c_temp[v] = get(beta, v);
for (const auto& e : in_or_out_edges_range(v, g))
{
typename graph_traits<Graph>::vertex_descriptor s;
if (graph_tool::is_directed(g))
s = source(e, g);
else
s = target(e, g);
auto s = source(e, g);
c_temp[v] += alpha * get(w, e) * c[s];
}
delta += abs(c_temp[v] - c[v]);
......
......@@ -63,11 +63,7 @@ struct get_pagerank
rank_type r = 0;
for (const auto& e : in_or_out_edges_range(v, g))
{
typename graph_traits<Graph>::vertex_descriptor s;
if (graph_tool::is_directed(g))
s = source(e, g);
else
s = target(e, g);
auto s = source(e, g);
r += (get(rank, s) * get(weight, e)) / get(deg, s);
}
......
......@@ -228,6 +228,17 @@ inline __attribute__((always_inline)) __attribute__((flatten))
auto
in_edges(typename graph_traits<undirected_adaptor<Graph>>::vertex_descriptor u,
const undirected_adaptor<Graph>& g)
{
typedef typename graph_traits<undirected_adaptor<Graph>>::in_edge_iterator
iter_t;
return std::make_pair(iter_t(), iter_t());
}
template <class Graph>
inline __attribute__((always_inline)) __attribute__((flatten))
auto
_all_edges_in(typename graph_traits<undirected_adaptor<Graph>>::vertex_descriptor u,
const undirected_adaptor<Graph>& g)
{
return _all_edges_in(u, g.original_graph());
}
......@@ -333,7 +344,7 @@ auto
in_degree(typename graph_traits<undirected_adaptor<Graph> >::vertex_descriptor u,
const undirected_adaptor<Graph>& g)
{
return out_degree(u, g);
return 0;
}
//==============================================================================
......
......@@ -408,10 +408,7 @@ typename filt_graph<G, EP, VP>::degree_size_type
degree(typename filt_graph<G, EP, VP>::vertex_descriptor u,
const filt_graph<G, EP, VP>& g)
{
if (is_directed(g))
return in_degree(u, g) + out_degree(u, g);
else
return out_degree(u, g);
return in_degree(u, g) + out_degree(u, g);
}
template <typename G, typename EP, typename VP>
......
......@@ -251,8 +251,7 @@ struct get_edge_dispatch
{
for (auto e : in_or_out_edges_range(vertex(t, g), g))
{
auto w = graph_tool::is_directed(g) ?
source(e, g) : target(e, g);
auto w = source(e, g);
if (w == vertex(s, g))
{
if (!graph_tool::is_directed(g) && e.s != s)
......
......@@ -369,6 +369,19 @@ struct in_edge_iteratorS
}
};
template <class Graph>
struct _all_edges_in_iteratorS
{
typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
typedef typename boost::graph_traits<Graph>::in_edge_iterator type;
inline __attribute__((always_inline))
static std::pair<type,type> get_edges(vertex_descriptor v,
const Graph& g)
{
return _all_edges_in(v, g);
}
};
// out edges selector for completeness
template <class Graph>
struct out_edge_iteratorS
......@@ -412,7 +425,7 @@ struct in_or_out_edge_iteratorS
<typename boost::graph_traits<Graph>::directed_category,
boost::directed_tag>::value,
in_edge_iteratorS<Graph>,
out_edge_iteratorS<Graph>>::type
_all_edges_in_iteratorS<Graph>>::type
{};
// helper types for in_neighbor_iteratorS
......@@ -474,6 +487,20 @@ struct in_neighbor_iteratorS
}
};
template <class Graph>
struct _all_neighbors_in_iteratorS
{
typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
typedef typename boost::graph_traits<Graph>::in_edge_iterator type;
inline __attribute__((always_inline))
static std::pair<type,type> get_neighbors(vertex_descriptor v,
const Graph& g)
{
return _all_neighbors_ins(v, g);
}
};
// out edges selector for completeness
template <class Graph>
struct out_neighbor_iteratorS
......@@ -518,7 +545,7 @@ struct in_or_out_neighbors_iteratorS
<typename boost::graph_traits<Graph>::directed_category,
boost::directed_tag>::value,
in_neighbor_iteratorS<Graph>,
out_neighbor_iteratorS<Graph>>::type
_all_neighbors_in_iteratorS<Graph>>::type
{};
// range adaptors
......
......@@ -48,12 +48,15 @@ struct get_incidence
++pos;
}
for (const auto& e : in_edges_range(v, g))
if (graph_tool::is_directed(g))
{
data[pos] = 1;
i[pos] = get(vindex, v);
j[pos] = get(eindex, e);
++pos;
for (const auto& e : in_edges_range(v, g))
{
data[pos] = 1;
i[pos] = get(vindex, v);
j[pos] = get(eindex, e);
++pos;
}
}
}
}
......
......@@ -466,7 +466,7 @@ void get_all_preds(Graph g, Dist dist, Pred pred, Weight weight, Preds preds,
typedef decltype(d) dist_t;
for (auto e : in_or_out_edges_range(v, g))
{
auto u = graph_tool::is_directed(g) ? source(e, g) : target(e, g);
auto u = source(e, g);
if (!std::is_floating_point<dist_t>::value)
{
if (dist_t(dist[u] + get(weight, e)) == d)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment