Commit 1d8167da authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix planarity test with noncontiguous edge indexes

This fixes issue #712
parent ee939bb6
Pipeline #966 passed with stage
in 43 minutes and 31 seconds
......@@ -71,8 +71,7 @@ void planar_layout(GraphInterface& gi, boost::any aembed_map, boost::any apos)
pos(get(vertex_index_t(), g), num_vertices(g));
chrobak_payne_straight_line_drawing(g, embed, ordering.begin(),
ordering.end(), pos,
get(vertex_index, g));
ordering.end(), pos);
parallel_vertex_loop
(g,
[&](auto& v)
......
......@@ -39,13 +39,28 @@ struct mark_planar_edge
struct do_maximal_planar
{
template <class Graph, class VertexIndex, class EdgeIndex>
void operator()(Graph& g, VertexIndex vertex_index, EdgeIndex edge_index) const
typedef typename eprop_map_t<size_t>::type::unchecked_t eimap_t;
typedef typename vprop_map_t<size_t>::type::unchecked_t vimap_t;
template <class Graph>
eimap_t get_edge_index(const Graph& g) const
{
eimap_t::checked_t eidx;
size_t E = 0;
for (auto e : edges_range(g))
eidx[e] = E++;
return eidx.get_unchecked();
}
template <class Graph>
void operator()(Graph& g) const
{
unchecked_vector_property_map
<vector<typename graph_traits<Graph>::edge_descriptor>, VertexIndex>
embedding(vertex_index, num_vertices(g));
typename vprop_map_t<vector<typename graph_traits<Graph>::edge_descriptor>>::type::unchecked_t
embedding(num_vertices(g));
eimap_t edge_index = get_edge_index(g);
bool is_planar = boyer_myrvold_planarity_test
(boyer_myrvold_params::graph = g,
boyer_myrvold_params::edge_index_map = edge_index,
......@@ -60,7 +75,7 @@ struct do_maximal_planar
(boyer_myrvold_params::graph = g,
boyer_myrvold_params::edge_index_map = edge_index,
boyer_myrvold_params::embedding = embedding);
make_maximal_planar(g, embedding, vertex_index, edge_index, vis);
make_maximal_planar(g, embedding, get(vertex_index, g), edge_index, vis);
}
};
......@@ -73,7 +88,6 @@ void maximal_planar(GraphInterface& gi)
[&](auto&& graph)
{
return do_maximal_planar()
(std::forward<decltype(graph)>(graph), gi.get_vertex_index(),
gi.get_edge_index());
(std::forward<decltype(graph)>(graph));
})();
}
......@@ -48,37 +48,51 @@ struct get_planar_embedding
EdgeMap _edge_map;
};
template <class Graph, class VertexIndex, class EdgeIndex, class EmbedMap,
typedef typename eprop_map_t<size_t>::type::unchecked_t eimap_t;
typedef typename vprop_map_t<size_t>::type::unchecked_t vimap_t;
template <class Graph>
eimap_t get_edge_index(const Graph& g) const
{
eimap_t::checked_t eidx;
size_t E = 0;
for (auto e : edges_range(g))
eidx[e] = E++;
return eidx.get_unchecked();
}
template <class Graph, class EmbedMap,
class KurMap>
void operator()(Graph& g, VertexIndex vertex_index, EdgeIndex edge_index,
EmbedMap embed_map, KurMap kur_map, bool& is_planar) const
void operator()(Graph& g, EmbedMap embed_map,
KurMap kur_map, bool& is_planar) const
{
edge_inserter<KurMap> kur_insert(kur_map);
unchecked_vector_property_map
<vector<typename graph_traits<Graph>::edge_descriptor>, VertexIndex>
embedding(vertex_index, num_vertices(g));
typename vprop_map_t<vector<typename graph_traits<Graph>::edge_descriptor>>::type::unchecked_t
embedding(num_vertices(g));
eimap_t edge_index = get_edge_index(g);
is_planar = boyer_myrvold_planarity_test
(boyer_myrvold_params::graph = g,
boyer_myrvold_params::edge_index_map = edge_index,
boyer_myrvold_params::embedding = embedding,
boyer_myrvold_params::kuratowski_subgraph = kur_insert);
auto eidx = get(boost::edge_index, g);
parallel_vertex_loop
(g,
[&](auto v)
{
embed_map[v].clear();
for (auto& e : embedding[v])
embed_map[v].push_back(edge_index[e]);
embed_map[v].push_back(eidx[e]);
});
}
template <class Graph, class VertexIndex, class EdgeIndex, class KurMap>
void operator()(Graph& g, VertexIndex, EdgeIndex edge_index,
dummy_property_map, KurMap kur_map,
template <class Graph, class KurMap>
void operator()(Graph& g, dummy_property_map, KurMap kur_map,
bool& is_planar) const
{
edge_inserter<KurMap> kur_insert(kur_map);
eimap_t edge_index = get_edge_index(g);
is_planar = boyer_myrvold_planarity_test
(boyer_myrvold_params::graph = g,
boyer_myrvold_params::edge_index_map = edge_index,
......@@ -101,8 +115,8 @@ bool is_planar(GraphInterface& gi, boost::any embed_map, boost::any kur_map)
dummy_property_map>::type vertex_map_types;
run_action<graph_tool::detail::never_directed>()
(gi, std::bind(get_planar_embedding(), std::placeholders::_1, gi.get_vertex_index(),
gi.get_edge_index(), std::placeholders::_2, std::placeholders::_3,
(gi, std::bind(get_planar_embedding(), std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
std::ref(is_planar)),
vertex_map_types(), edge_map_types())
(embed_map, kur_map);
......
......@@ -212,7 +212,6 @@ def planar_layout(g, pos=None):
pos = u.new_vp("vector<double>")
else:
pos = u.own_property(pos)
make_maximal_planar(u)
libgraph_tool_layout.planar_layout(u._Graph__graph,
_prop("v", u, embed),
_prop("v", u, pos))
......
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