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

Change Graph.max_edge_index to Graph.edge_index_range

parent 5c872d16
......@@ -143,7 +143,7 @@ void betweenness(GraphInterface& g, boost::any weight,
std::placeholders::_1, g.get_vertex_index(),
std::placeholders::_2,
std::placeholders::_3, weight, normalize,
g.get_num_vertices(), g.get_max_edge_index()),
g.get_num_vertices(), g.get_edge_index_range()),
edge_floating_properties(),
vertex_floating_properties())
(edge_betweenness, vertex_betweenness);
......
......@@ -240,7 +240,7 @@ struct move_sweep_dispatch
vector<int64_t>& target_list, bool deg_corr, bool dense,
bool multigraph, double beta, bool sequential,
bool parallel, bool random_move, double c, bool verbose,
size_t max_edge_index, size_t nmerges, size_t niter,
size_t edge_index_range, size_t nmerges, size_t niter,
Vprop merge_map, partition_stats_t& partition_stats,
rng_t& rng, double& S, size_t& nmoves,
GraphInterface& bgi)
......@@ -250,7 +250,7 @@ struct move_sweep_dispatch
target_list(target_list), deg_corr(deg_corr), dense(dense),
multigraph(multigraph), beta(beta), sequential(sequential),
parallel(parallel), random_move(random_move),
c(c), verbose(verbose), max_edge_index(max_edge_index),
c(c), verbose(verbose), edge_index_range(edge_index_range),
nmerges(nmerges), niter(niter), merge_map(merge_map),
partition_stats(partition_stats), rng(rng), S(S),
nmoves(nmoves), bgi(bgi)
......@@ -275,7 +275,7 @@ struct move_sweep_dispatch
bool random_move;
double c;
bool verbose;
size_t max_edge_index;
size_t edge_index_range;
size_t nmerges;
size_t niter;
Vprop merge_map;
......@@ -367,7 +367,7 @@ struct move_sweep_dispatch
{
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
size_t eidx = random_move ? 1 : max_edge_index;
size_t eidx = random_move ? 1 : edge_index_range;
typedef typename property_map<Graph, vertex_index_t>::type vindex_map_t;
typedef typename property_map_type::apply<Sampler<vertex_t, boost::mpl::false_>,
......@@ -386,7 +386,7 @@ struct move_sweep_dispatch
overlap_stats_t ostats;
vector<size_t> free_blocks;
auto state = make_block_state(g, eweight.get_unchecked(max_edge_index),
auto state = make_block_state(g, eweight.get_unchecked(edge_index_range),
vweight.get_unchecked(num_vertices(g)),
b.get_unchecked(num_vertices(g)), bg,
emat, mrs,
......@@ -412,7 +412,7 @@ struct move_sweep_dispatch
label.get_unchecked(num_vertices(bg)),
vlist, block_list,
deg_corr, dense, multigraph, beta,
eweight.get_unchecked(max_edge_index),
eweight.get_unchecked(edge_index_range),
vweight.get_unchecked(num_vertices(g)),
g, sequential, parallel, random_move, c,
nmerges,
......@@ -490,7 +490,7 @@ boost::python::object do_move_sweep(GraphInterface& gi, GraphInterface& bgi,
label, vlist, block_list,
target_list, deg_corr, dense, multigraph,
beta, sequential, parallel, random_move, c, verbose,
gi.get_max_edge_index(), nmerges, niter, merge_map,
gi.get_edge_index_range(), nmerges, niter, merge_map,
partition_stats, rng, S, nmoves, bgi),
mrs, mrp, mrm, wr, b, placeholders::_1,
std::ref(emat), sampler, cavity_sampler, weighted))();
......@@ -532,9 +532,9 @@ boost::any do_build_egroups(GraphInterface& gi, GraphInterface& bgi,
boost::any oegroups;
run_action<graph_tool::detail::all_graph_views, boost::mpl::true_>()
(gi, std::bind<void>(build_egroups(), b, std::ref(oegroups),
esrcpos.get_unchecked(gi.get_max_edge_index()),
etgtpos.get_unchecked(gi.get_max_edge_index()),
eweights.get_unchecked(gi.get_max_edge_index()),
esrcpos.get_unchecked(gi.get_edge_index_range()),
etgtpos.get_unchecked(gi.get_edge_index_range()),
eweights.get_unchecked(gi.get_edge_index_range()),
placeholders::_1, bgi.get_vertex_index(),
bgi.get_num_vertices(), weighted, empty))();
return oegroups;
......
......@@ -62,7 +62,7 @@ struct cov_move_sweep_dispatch
bool sequential, bool parallel, bool random_move,
bool node_coherent, bool confine_layers, double c,
bool verbose, size_t meindex,
vector<size_t> max_edge_index, size_t nmerges,
vector<size_t> edge_index_range, size_t nmerges,
size_t niter, Vprop merge_map,
vector<std::reference_wrapper<partition_stats_t>>& partition_stats,
vector<std::reference_wrapper<overlap_partition_stats_t>>& overlap_partition_stats,
......@@ -82,7 +82,7 @@ struct cov_move_sweep_dispatch
sequential(sequential), parallel(parallel), random_move(random_move),
node_coherent(node_coherent), confine_layers(confine_layers),
c(c), verbose(verbose), meindex(meindex),
max_edge_index(max_edge_index),
edge_index_range(edge_index_range),
nmerges(nmerges), niter(niter), merge_map(merge_map),
partition_stats(partition_stats),
overlap_partition_stats(overlap_partition_stats),
......@@ -117,7 +117,7 @@ struct cov_move_sweep_dispatch
double c;
bool verbose;
size_t meindex;
vector<size_t> max_edge_index;
vector<size_t> edge_index_range;
size_t nmerges;
size_t niter;
Vprop merge_map;
......@@ -300,10 +300,10 @@ struct cov_move_sweep_dispatch
for (size_t i = 0; i < mrs.size(); ++i)
{
size_t eidx = random_move ? 1 : max_edge_index[i];
size_t eidx = random_move ? 1 : edge_index_range[i];
state_t state = make_block_state(gs[i].get(),
eweight[i].get().get_unchecked(max_edge_index[i]),
eweight[i].get().get_unchecked(edge_index_range[i]),
vweight[i].get().get_unchecked(num_vertices(gs[i].get())),
bs[i].get().get_unchecked(num_vertices(gs[i].get())),
bgs[i].get(),
......@@ -337,7 +337,7 @@ struct cov_move_sweep_dispatch
label.get_unchecked(B),
vlist, block_list, deg_corr,
dense, multigraph, beta,
eweight[0].get().get_unchecked(max_edge_index[0]),
eweight[0].get().get_unchecked(edge_index_range[0]),
vweight[0].get().get_unchecked(num_vertices(g)),
g, sequential, parallel, random_move, c,
nmerges,
......@@ -375,10 +375,10 @@ struct cov_move_sweep_dispatch
vector<state_t> states;
for (size_t i = 0; i < mrs.size(); ++i)
{
size_t eidx = random_move ? 1 : max_edge_index[i];
size_t eidx = random_move ? 1 : edge_index_range[i];
state_t state = make_block_state(gs[i].get(),
eweight[i].get().get_unchecked(max_edge_index[i]),
eweight[i].get().get_unchecked(edge_index_range[i]),
vweight[i].get().get_unchecked(num_vertices(gs[i].get())),
bs[i].get().get_unchecked(num_vertices(gs[i].get())),
bgs[i].get(),
......@@ -577,7 +577,7 @@ boost::python::object do_cov_move_sweep(GraphInterface& gi,
vector<size_t> eidx;
for (GraphInterface& g : gis)
eidx.push_back(g.get_max_edge_index());
eidx.push_back(g.get_edge_index_range());
auto bgi = from_rlist<GraphInterface>(obgi);
......@@ -606,7 +606,7 @@ boost::python::object do_cov_move_sweep(GraphInterface& gi,
label, vlist, block_list, target_blocks, deg_corr, dense,
multigraph, beta, sequential, parallel, random_move,
node_coherent, confine_layers, c, verbose,
gi.get_max_edge_index(), eidx, nmerges, niter, merge_map,
gi.get_edge_index_range(), eidx, nmerges, niter, merge_map,
partition_stats, overlap_partition_stats, overlap_stats,
master, slave, rng, S, nmoves, bgi, bmap, brmap, free_blocks, B),
std::ref(mrs), std::ref(mrp), std::ref(mrm), std::ref(wr),
......@@ -653,7 +653,7 @@ void do_ec_hist(GraphInterface& gi, boost::any& aevc, boost::any& aec)
GraphInterface::edge_index_map_t>::type
emap_t;
typename emap_t::unchecked_t ec =
any_cast<emap_t&>(aec).get_unchecked(gi.get_max_edge_index());
any_cast<emap_t&>(aec).get_unchecked(gi.get_edge_index_range());
run_action<>()(gi, std::bind<void>(ec_hist(), placeholders::_1,
placeholders::_2, std::ref(ec)),
edge_properties())(aevc);
......
......@@ -58,7 +58,7 @@ struct move_sweep_overlap_dispatch
bool parallel_edges, double beta,
bool sequential, bool parallel,
bool random_move, double c, bool node_coherent,
bool verbose, size_t max_edge_index,
bool verbose, size_t edge_index_range,
size_t nmerges, size_t niter, Vprop merge_map,
overlap_stats_t& overlap_stats,
overlap_partition_stats_t& partition_stats,
......@@ -71,7 +71,7 @@ struct move_sweep_overlap_dispatch
multigraph(multigraph), parallel_edges(parallel_edges), beta(beta),
sequential(sequential), parallel(parallel), random_move(random_move),
c(c), node_coherent(node_coherent), verbose(verbose),
max_edge_index(max_edge_index), nmerges(nmerges),
edge_index_range(edge_index_range), nmerges(nmerges),
niter(niter), merge_map(merge_map), overlap_stats(overlap_stats),
partition_stats(partition_stats), rng(rng), S(S), nmoves(nmoves), bgi(bgi)
{}
......@@ -97,7 +97,7 @@ struct move_sweep_overlap_dispatch
double c;
bool node_coherent;
bool verbose;
size_t max_edge_index;
size_t edge_index_range;
size_t nmerges;
size_t niter;
Vprop merge_map;
......@@ -180,7 +180,7 @@ struct move_sweep_overlap_dispatch
{
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
size_t eidx = random_move ? 1 : max_edge_index;
size_t eidx = random_move ? 1 : edge_index_range;
typedef typename property_map<Graph, vertex_index_t>::type vindex_map_t;
typedef typename property_map_type::apply<Sampler<vertex_t, boost::mpl::false_>,
......@@ -197,7 +197,7 @@ struct move_sweep_overlap_dispatch
vector<size_t> free_blocks;
auto state = make_block_state(g,
eweight.get_unchecked(max_edge_index),
eweight.get_unchecked(edge_index_range),
vweight.get_unchecked(num_vertices(g)),
b.get_unchecked(num_vertices(g)),
bg, emat, mrs,
......@@ -325,7 +325,7 @@ do_move_sweep_overlap(GraphInterface& gi, GraphInterface& bgi, boost::any& emat,
(eweight, vweight, oegroups, esrcpos, etgtpos,
label, vlist, block_list, target_blocks, deg_corr, dense,
multigraph, parallel_edges, beta, sequential, parallel,
random_move, c, node_coherent, verbose, gi.get_max_edge_index(),
random_move, c, node_coherent, verbose, gi.get_edge_index_range(),
nmerges, niter, merge_map, overlap_stats, partition_stats,
rng, S, nmoves, bgi),
mrs, mrp, mrm, wr, b, placeholders::_1,
......
......@@ -71,7 +71,7 @@ void edmonds_karp_max_flow(GraphInterface& gi, size_t src, size_t sink,
run_action<graph_tool::detail::always_directed>()
(gi, std::bind(get_edmonds_karp_max_flow(),
placeholders::_1, gi.get_vertex_index(), gi.get_edge_index(),
gi.get_max_edge_index(),
gi.get_edge_index_range(),
src, sink, placeholders::_2, placeholders::_3),
writable_edge_scalar_properties(), writable_edge_scalar_properties())
(capacity,res);
......
......@@ -97,7 +97,7 @@ void kolmogorov_max_flow(GraphInterface& gi, size_t src, size_t sink,
{
run_action<graph_tool::detail::always_directed, boost::mpl::true_>()
(gi, std::bind(get_kolmogorov_max_flow(),
placeholders::_1, gi.get_edge_index(), gi.get_max_edge_index(),
placeholders::_1, gi.get_edge_index(), gi.get_edge_index_range(),
gi.get_vertex_index(), src, sink, placeholders::_2,
placeholders::_3),
writable_edge_scalar_properties(), writable_edge_scalar_properties())
......
......@@ -88,7 +88,7 @@ void push_relabel_max_flow(GraphInterface& gi, size_t src, size_t sink,
run_action<graph_tool::detail::always_directed, boost::mpl::true_>()
(gi, std::bind(get_push_relabel_max_flow(),
placeholders::_1, gi.get_vertex_index(), gi.get_edge_index(),
gi.get_max_edge_index(),
gi.get_edge_index_range(),
src, sink, placeholders::_2, placeholders::_3),
writable_edge_scalar_properties(), writable_edge_scalar_properties())
(capacity,res);
......
......@@ -139,7 +139,7 @@ size_t random_rewire(GraphInterface& gi, string strat, size_t niter,
emap_t;
emap_t::unchecked_t pin =
any_cast<emap_t>(apin).get_unchecked(gi.get_max_edge_index());
any_cast<emap_t>(apin).get_unchecked(gi.get_edge_index_range());
if (strat == "erdos")
......
......@@ -145,7 +145,7 @@ public:
std::shared_ptr<multigraph_t> get_graph_ptr() {return _mg;}
vertex_index_map_t get_vertex_index() {return _vertex_index;}
edge_index_map_t get_edge_index() {return _edge_index;}
size_t get_max_edge_index() {return _mg->get_last_index();}
size_t get_edge_index_range() {return _mg->get_edge_index_range();}
graph_index_map_t get_graph_index() {return graph_index_map_t(0);}
......
......@@ -164,7 +164,7 @@ public:
typedef std::vector<std::pair<vertex_t, vertex_t> > edge_list_t;
typedef typename integer_range<Vertex>::iterator vertex_iterator;
adj_list(): _n_edges(0), _last_idx(0), _keep_epos(false) {}
adj_list(): _n_edges(0), _edge_index_range(0), _keep_epos(false) {}
struct get_vertex
{
......@@ -262,7 +262,7 @@ public:
void reindex_edges()
{
_free_indexes.clear();
_last_idx = 0;
_edge_index_range = 0;
_in_edges.clear();
_in_edges.resize(_out_edges.size());
for (size_t i = 0; i < _out_edges.size(); ++i)
......@@ -272,9 +272,9 @@ public:
{
auto& oe = oes[j];
Vertex v = oe.first;
oe.second = _last_idx;
_in_edges[v].emplace_back(i, _last_idx);
_last_idx++;
oe.second = _edge_index_range;
_in_edges[v].emplace_back(i, _edge_index_range);
_edge_index_range++;
}
}
......@@ -301,7 +301,7 @@ public:
return _keep_epos;
}
size_t get_last_index() const { return _last_idx; }
size_t get_edge_index_range() const { return _edge_index_range; }
static Vertex null_vertex() { return std::numeric_limits<Vertex>::max(); }
......@@ -318,17 +318,17 @@ public:
[](const auto &a, const auto& b) -> bool
{return a.idx < b.idx;});
if (iter == erange.second)
_last_idx = 0;
_edge_index_range = 0;
else
_last_idx = iter->idx + 1;
_edge_index_range = iter->idx + 1;
auto iter_idx = std::remove_if(_free_indexes.begin(),
_free_indexes.end(),
[&](auto idx) -> bool
{return idx > _last_idx;});
{return idx > _edge_index_range;});
_free_indexes.erase(iter_idx, _free_indexes.end());
_free_indexes.shrink_to_fit();
if (_keep_epos)
_epos.resize(_last_idx);
_epos.resize(_edge_index_range);
_epos.shrink_to_fit();
}
......@@ -337,7 +337,7 @@ private:
vertex_list_t _out_edges;
vertex_list_t _in_edges;
size_t _n_edges;
size_t _last_idx;
size_t _edge_index_range;
std::deque<size_t> _free_indexes; // indexes of deleted edges to be used up
// for new edges to avoid very large
// indexes, and unnecessary property map
......@@ -347,7 +347,7 @@ private:
void rebuild_epos()
{
_epos.resize(_last_idx);
_epos.resize(_edge_index_range);
for (size_t i = 0; i < _out_edges.size(); ++i)
{
auto& oes = _out_edges[i];
......@@ -771,7 +771,7 @@ add_edge(Vertex s, Vertex t, adj_list<Vertex>& g)
Vertex idx;
if (g._free_indexes.empty())
{
idx = g._last_idx++;
idx = g._edge_index_range++;
}
else
{
......
......@@ -470,7 +470,7 @@ BOOST_PYTHON_MODULE(libgraph_tool_core)
.def("clear_edges", &GraphInterface::clear_edges)
.def("get_vertex_index", &GraphInterface::get_vertex_index)
.def("get_edge_index", &GraphInterface::get_edge_index)
.def("get_max_edge_index", &GraphInterface::get_max_edge_index)
.def("get_edge_index_range", &GraphInterface::get_edge_index_range)
.def("re_index_edges", &GraphInterface::re_index_edges)
.def("shrink_to_fit", &GraphInterface::shrink_to_fit)
.def("get_graph_index", &GraphInterface::get_graph_index)
......
......@@ -279,7 +279,7 @@ GraphInterface::GraphInterface(const GraphInterface& gi, bool keep_ref,
boost::any avorder = python::extract<boost::any>(vorder)();
run_action<>()
(const_cast<GraphInterface&>(gi),
std::bind(do_graph_copy(gi._mg->get_last_index()),
std::bind(do_graph_copy(gi._mg->get_edge_index_range()),
std::placeholders::_1, std::ref(*_mg),
gi._vertex_index, _vertex_index, gi._edge_index,
_edge_index, std::placeholders::_2, std::ref(vprops),
......
......@@ -151,7 +151,7 @@ boost::any GraphInterface::get_graph_view() const
{
boost::any graph =
check_filtered(*_mg, _edge_filter_map, _edge_filter_invert,
_edge_filter_active, _mg->get_last_index(),
_edge_filter_active, _mg->get_edge_index_range(),
_vertex_filter_map, _vertex_filter_invert,
_vertex_filter_active,
const_cast<GraphInterface&>(*this), _reversed,
......
......@@ -445,7 +445,7 @@ struct graph_action
graph_action(GraphInterface& g, Action a)
: _g(g), _a(a, g, num_vertices(*g._mg),
max(g._mg->get_last_index(), size_t(1))) {}
max(g._mg->get_edge_index_range(), size_t(1))) {}
template <class... Args>
void operator()(Args&&... args) const
......
......@@ -31,7 +31,7 @@ struct do_edge_endpoint
{
template <class Graph, class EdgeIndexMap, class VertexPropertyMap>
void operator()(Graph& g, EdgeIndexMap, VertexPropertyMap prop,
boost::any aeprop, size_t max_edge_index) const
boost::any aeprop, size_t edge_index_range) const
{
typedef typename property_traits<VertexPropertyMap>::value_type vval_t;
typedef typename boost::mpl::if_<std::is_same<vval_t, size_t>, int64_t, vval_t>::type
......@@ -39,7 +39,7 @@ struct do_edge_endpoint
typedef typename property_map_type::apply<val_t, EdgeIndexMap>::type
eprop_t;
eprop_t eprop = any_cast<eprop_t>(aeprop);
eprop.reserve(max_edge_index);
eprop.reserve(edge_index_range);
int i, N = num_vertices(g);
#pragma omp parallel for default(shared) private(i) \
......@@ -67,15 +67,15 @@ struct do_edge_endpoint
void edge_endpoint(GraphInterface& gi, boost::any prop,
boost::any eprop, std::string endpoint)
{
size_t max_edge_index = gi.get_max_edge_index();
size_t edge_index_range = gi.get_edge_index_range();
if (endpoint == "source")
run_action<>()(gi, std::bind(do_edge_endpoint<true>(), placeholders::_1,
gi.get_edge_index(), placeholders::_2, eprop,
max_edge_index),
edge_index_range),
vertex_properties())(prop);
else
run_action<>()(gi, std::bind(do_edge_endpoint<false>(), placeholders::_1,
gi.get_edge_index(), placeholders::_2, eprop,
max_edge_index),
edge_index_range),
vertex_properties())(prop);
}
......@@ -158,8 +158,8 @@ void subgraph_isomorphism(GraphInterface& gi1, GraphInterface& gi2,
}
else
{
edge_label1 = any_cast<elabel_t>(edge_label1).get_unchecked(gi1.get_max_edge_index());
edge_label2 = any_cast<elabel_t>(edge_label2).get_unchecked(gi2.get_max_edge_index());
edge_label1 = any_cast<elabel_t>(edge_label1).get_unchecked(gi1.get_edge_index_range());
edge_label2 = any_cast<elabel_t>(edge_label2).get_unchecked(gi2.get_edge_index_range());
}
vector<vlabel_t> vmaps;
......
......@@ -646,7 +646,7 @@ class PropertyMap(object):
if self.__key_type == 'v':
n = g._Graph__graph.get_num_vertices(False)
elif self.__key_type == 'e':
n = g.max_edge_index
n = g.edge_index_range
else:
n = 1
a = self.__map.get_array(n)
......@@ -683,11 +683,11 @@ class PropertyMap(object):
libcore.mark_edges(g._Graph__graph, _prop("e", g, filt[0]))
if filt[1]:
filt[0].a = numpy.logical_not(filt[0].a)
elif g.max_edge_index != g.num_edges():
elif g.edge_index_range != g.num_edges():
filt = (g.new_edge_property("bool"), False)
libcore.mark_edges(g._Graph__graph, _prop("e", g, filt[0]))
if filt[0] is None:
N = g.max_edge_index
N = g.edge_index_range
else:
N = (filt[0].a == (not filt[1])).sum()
if get:
......@@ -786,7 +786,7 @@ class PropertyMap(object):
idx = g.vertex_index
filt = vfilt
else:
N = g.max_edge_index + 1
N = g.edge_index_range
idx = g.edge_index
filt = efilt
a = [["" for j in range(N)] for i in range(len(p))]
......@@ -878,7 +878,7 @@ class PropertyMap(object):
if self.key_type() == "v":
size = g.num_vertices(True)
elif self.key_type() == "e":
size = g.max_edge_index
size = g.edge_index_range
else:
size = 1
self.__map.resize(size)
......@@ -2100,11 +2100,11 @@ class Graph(object):
However this will always happen whenever no
edges are deleted from the graph.""")
def _get_max_edge_index(self):
return self.__graph.get_max_edge_index()
def _get_edge_index_range(self):
return self.__graph.get_edge_index_range()
max_edge_index = property(_get_max_edge_index,
doc="The maximum value of the edge index map.")
edge_index_range = property(_get_edge_index_range,
doc="The size of the range of edge indexes.")
def reindex_edges(self):
"""
......
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