Commit a9a2ba7f authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Implement graph_tool::is_directed()

parent 314bc212
......@@ -542,7 +542,7 @@ public:
size_t kout = out_degreeS()(v, _g);
size_t kin = 0;
if (is_directed::apply<g_t>::type::value)
if (graph_tool::is_directed(_g))
kin = in_degreeS()(v, _g);
double dS = entries_dS<exact>(m_entries, _mrs, _emat, _bg);
......@@ -556,7 +556,7 @@ public:
if (multigraph)
dS += _overlap_stats.virtual_move_parallel_dS(v, r, nr, _b, _g);
if (!is_directed::apply<g_t>::type::value)
if (!graph_tool::is_directed(_g))
kin = kout;
auto vt = [&](auto mrp, auto mrm, auto nr)
......@@ -938,7 +938,7 @@ public:
if (c > 0)
{
size_t B = num_vertices(_bg);
if (is_directed::apply<g_t>::type::value)
if (graph_tool::is_directed(_g))
p_rand = c * B / double(_mrp[t] + _mrm[t] + c * B);
else
p_rand = c * B / double(_mrp[t] + c * B);
......@@ -995,7 +995,7 @@ public:
size_t kout = out_degreeS()(v, _g, _eweight);
size_t kin = kout;
if (is_directed::apply<g_t>::type::value)
if (graph_tool::is_directed(_g))
kin = in_degreeS()(v, _g, _eweight);
size_t vi = _overlap_stats.get_node(v);
......@@ -1006,7 +1006,7 @@ public:
for (auto e : all_edges_range(v, _g))
{
vertex_t u = target(e, _g);
if (is_directed::apply<g_t>::type::value && u == v)
if (graph_tool::is_directed(_g) && u == v)
u = source(e, _g);
vertex_t t = _b[u];
if (u == v)
......@@ -1022,7 +1022,7 @@ public:
int mst = mts;
int mtm = mtp;
if (is_directed::apply<g_t>::type::value)
if (graph_tool::is_directed(_g))
{
mst = 0;
const auto& me = m_entries.get_me(s, t, _emat);
......@@ -1035,7 +1035,7 @@ public:
{
int dts = get<0>(m_entries.get_delta(t, s));
int dst = dts;
if (is_directed::apply<g_t>::type::value)
if (graph_tool::is_directed(_g))
dst = get<0>(m_entries.get_delta(s, t));
mts += dts;
......@@ -1054,7 +1054,7 @@ public:
}
}
if (is_directed::apply<g_t>::type::value)
if (graph_tool::is_directed(_g))
{
p += ew * ((mts + mst + c) / (mtp + mtm + c * B));
}
......@@ -1371,7 +1371,7 @@ public:
{
if (!be[e].empty() || target(e, g) != t)
continue;
if (is_directed::apply<Graph>::type::value || s < target(e, g))
if (graph_tool::is_directed(g) || s < target(e, g))
be[e] = {_b[u], _b[v]};
else
be[e] = {_b[v], _b[u]};
......@@ -1522,7 +1522,7 @@ public:
{
size_t r = _b[source(e, _g)];
size_t s = _b[target(e, _g)];
if (!is_directed::apply<g_t>::type::value && s < r)
if (!graph_tool::is_directed(_g) && s < r)
std::swap(r, s);
mrs[std::make_pair(r, s)] += _eweight[e];
}
......
......@@ -92,7 +92,7 @@ struct overlap_partition_stats_t
bool allow_empty)
: _overlap_stats(ostats), _bmap(bmap), _vmap(vmap),
_allow_empty(allow_empty),
_directed(is_directed::apply<Graph>::type::value)
_directed(graph_tool::is_directed(g))
{
_D = 0;
......@@ -587,7 +587,7 @@ struct overlap_partition_stats_t
template <class Graph>
double get_delta_edges_dl(size_t v, size_t r, size_t nr, size_t actual_B,
const Graph&)
const Graph& g)
{
if (r == nr || _allow_empty)
return 0;
......@@ -602,9 +602,9 @@ struct overlap_partition_stats_t
if (dB != 0)
{
auto get_x = [](size_t B) -> size_t
auto get_x = [&g](size_t B) -> size_t
{
if (is_directed::apply<Graph>::type::value)
if (graph_tool::is_directed(g))
return B * B;
else
return (B * (B + 1)) / 2;
......
......@@ -87,7 +87,7 @@ public:
auto w = _out_neighbors[u];
if (w == _null)
continue;
if (!is_directed::apply<Graph>::type::value && size_t(node_index[w]) < i)
if (!graph_tool::is_directed(g) && size_t(node_index[w]) < i)
continue;
out_us[node_index[w]].push_back(u);
}
......@@ -105,9 +105,9 @@ public:
_mi[u] = _mi[w] = _parallel_bundles.size() - 1;
size_t r = b[u];
size_t s = b[w];
if (!is_directed::apply<Graph>::type::value && r > s)
if (!graph_tool::is_directed(g) && r > s)
std::swap(r, s);
h[std::make_tuple(r, s, !is_directed::apply<Graph>::type::value && u == w)]++;
h[std::make_tuple(r, s, !graph_tool::is_directed(g) && u == w)]++;
}
}
}
......@@ -115,7 +115,7 @@ public:
}
template <class Graph, class VProp>
void add_half_edge(size_t v, size_t v_r, VProp& b, Graph&)
void add_half_edge(size_t v, size_t v_r, VProp& b, Graph& g)
{
size_t u = _node_index[v];
size_t kin = (_in_neighbors[v] != _null);
......@@ -142,14 +142,14 @@ public:
s = b[u];
}
auto& h = _parallel_bundles[m];
if (!is_directed::apply<Graph>::type::value && r > s)
if (!graph_tool::is_directed(g) && r > s)
std::swap(r, s);
h[std::make_tuple(r, s, !is_directed::apply<Graph>::type::value && u == v)]++;
h[std::make_tuple(r, s, !graph_tool::is_directed(g) && u == v)]++;
}
}
template <class Graph, class VProp>
void remove_half_edge(size_t v, size_t v_r, VProp& b, Graph&)
void remove_half_edge(size_t v, size_t v_r, VProp& b, Graph& g)
{
size_t u = _node_index[v];
size_t kin = (_in_neighbors[v] != _null);
......@@ -179,9 +179,9 @@ public:
s = b[u];
}
auto& h = _parallel_bundles[m];
if (!is_directed::apply<Graph>::type::value && r > s)
if (!graph_tool::is_directed(g) && r > s)
std::swap(r, s);
auto iter = h.find(std::make_tuple(r, s, !is_directed::apply<Graph>::type::value && u == v));
auto iter = h.find(std::make_tuple(r, s, !graph_tool::is_directed(g) && u == v));
assert(iter->second > 0);
iter->second--;
if (iter->second == 0)
......@@ -230,7 +230,7 @@ public:
size_t u_kin = ((in_deg + out_deg) > 0) ? in_deg : in_degreeS()(v, g);
size_t u_kout = ((in_deg + out_deg) > 0) ? out_deg : out_degreeS()(v, g);
auto deg = _block_nodes[r].find(u)->second;
auto deg = _block_nodes[r].find(u)->second;
auto ndeg = deg;
ndeg.first -= u_kin;
ndeg.second -= u_kout;
......@@ -255,7 +255,7 @@ public:
template <class Graph, class VProp>
double virtual_move_parallel_dS(size_t v, size_t v_r, size_t v_nr, VProp& b,
Graph&, bool bundled=false) const
Graph& g, bool bundled=false) const
{
int m = _mi[v];
if (m == -1)
......@@ -279,9 +279,9 @@ public:
ns = s;
}
if (!is_directed::apply<Graph>::type::value && r > s)
if (!graph_tool::is_directed(g) && r > s)
std::swap(r, s);
if (!is_directed::apply<Graph>::type::value && nr > ns)
if (!graph_tool::is_directed(g) && nr > ns)
std::swap(nr, ns);
auto& h = _parallel_bundles[m];
......@@ -294,7 +294,7 @@ public:
return iter->second;
};
bool is_loop = !is_directed::apply<Graph>::type::value && u == v;
bool is_loop = !graph_tool::is_directed(g) && u == v;
int c = get_h(std::make_tuple(r, s, is_loop));
int nc = get_h(std::make_tuple(nr, ns, is_loop));
......
......@@ -91,7 +91,7 @@ public:
{
if (!self_loops)
continue;
if (!is_directed::apply<Graph>::type::value)
if (!graph_tool::is_directed(g))
w /= 2;
}
us.emplace_back(u, 0);
......
......@@ -42,7 +42,7 @@ struct get_adjacency
j[pos] = get(index, source(e, g));
++pos;
if (!is_directed::apply<Graph>::type::value)
if (!graph_tool::is_directed(g))
{
data[pos] = get(weight, e);
i[pos] = get(index, source(e, g));
......
......@@ -39,7 +39,7 @@ struct get_incidence
{
for (const auto& e : out_edges_range(v, g))
{
if (is_directed::apply<Graph>::type::value)
if (graph_tool::is_directed(g))
data[pos] = -1;
else
data[pos] = 1;
......
......@@ -88,7 +88,7 @@ struct get_laplacian
j[pos] = get(index, source(e, g));
++pos;
if (!is_directed::apply<Graph>::type::value)
if (!graph_tool::is_directed(g))
{
data[pos] = -get(weight, e);
i[pos] = get(index, source(e, g));
......
......@@ -49,7 +49,7 @@ struct label_parallel_edges
vertex_t u = target(*e, g);
// do not visit edges twice in undirected graphs
if (!is_directed::apply<Graph>::type::value && u < v)
if (!graph_tool::is_directed(g) && u < v)
continue;
if (u == v)
......
......@@ -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 = boost::is_directed(g) ? source(e, g) : target(e, g);
auto u = graph_tool::is_directed(g) ? source(e, g) : target(e, g);
if (!std::is_floating_point<dist_t>::value)
{
if (dist_t(dist[u] + get(weight, e)) == d)
......
......@@ -83,7 +83,7 @@ double inv_log_weighted(Vertex u, Vertex v, Mark& mark, Graph& g)
{
if (mark[w])
{
if (is_directed::apply<Graph>::type::value)
if (graph_tool::is_directed(g))
count += 1. / log(in_degreeS()(w, g));
else
count += 1. / log(out_degree(w, g));
......
......@@ -127,7 +127,7 @@ struct find_edges
(g,
[&](auto e)
{
if (!is_directed::apply<Graph>::type::value)
if (!graph_tool::is_directed(g))
{
if (edge_set.find(eindex[e]) == edge_set.end())
edge_set.insert(eindex[e]);
......
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