use crate::graph::Graph;
use crate::id::{EdgeId, NodeId};
use petgraph::graph::UnGraph;
use std::collections::HashMap;
impl<N, P, E> Graph<N, P, E> {
pub fn to_petgraph(&self) -> UnGraph<NodeId, EdgeId> {
let mut pg = UnGraph::new_undirected();
let mut map: HashMap<NodeId, petgraph::graph::NodeIndex> = HashMap::new();
for (id, _) in self.nodes() {
map.insert(id, pg.add_node(id));
}
for (edge, _) in self.all_edges() {
if let Some((a, b)) = self.edge_nodes(edge) {
pg.add_edge(map[&a], map[&b], edge);
}
}
pg
}
}