* of parallel edges. The only vertex property constructed is \a
* vertex_index_t.
*/
-using NFAUndirectedGraph =
- boost::adjacency_list<boost::setS, // out edges
- boost::listS, // vertices
- boost::undirectedS, // graph is undirected
- boost::property<boost::vertex_index_t, size_t>>;
+using NFAUndirectedGraph = boost::adjacency_list<
+ boost::listS, // out edges
+ boost::listS, // vertices
+ boost::undirectedS, // graph is undirected
+ boost::property<boost::vertex_index_t, size_t>>; // vertex properties
using NFAUndirectedVertex = NFAUndirectedGraph::vertex_descriptor;
boost::put(boost::vertex_index, ug, nuv, idx++);
}
+ // Track seen edges so that we don't insert parallel edges.
+ using Vertex = typename Graph::vertex_descriptor;
+ unordered_set<std::pair<Vertex, Vertex>> seen;
+ seen.reserve(num_edges(g));
+ auto make_ordered_edge = [](Vertex a, Vertex b) {
+ return std::make_pair(std::min(a, b), std::max(a, b));
+ };
+
for (const auto &e : ue2::edges_range(g)) {
auto u = source(e, g);
auto v = target(e, g);
continue;
}
+ if (!seen.emplace(make_ordered_edge(u, v)).second) {
+ continue; // skip parallel edge.
+ }
+
NFAUndirectedVertex new_u = old2new.at(u);
NFAUndirectedVertex new_v = old2new.at(v);