From 97fbce27012efb32032721c508629fa6e05646be Mon Sep 17 00:00:00 2001 From: "julian.speith" Date: Wed, 8 May 2024 14:18:14 +0200 Subject: [PATCH] added constructor accepting igraph graph object --- .../include/graph_algorithm/netlist_graph.h | 4 +++- plugins/graph_algorithm/src/netlist_graph.cpp | 21 ++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/plugins/graph_algorithm/include/graph_algorithm/netlist_graph.h b/plugins/graph_algorithm/include/graph_algorithm/netlist_graph.h index ee8f7182942..eaa5bb58917 100644 --- a/plugins/graph_algorithm/include/graph_algorithm/netlist_graph.h +++ b/plugins/graph_algorithm/include/graph_algorithm/netlist_graph.h @@ -56,7 +56,9 @@ namespace hal ALL }; - ~NetlistGraph(); + NetlistGraph(Netlist* nl, igraph_t&& graph, std::unordered_map&& m_nodes_to_gates); + + ~NetlistGraph(); /** * Create a directed graph from a netlist. Optionally create dummy vertices at nets missing a source or destination. An optional filter can be applied to exclude undesired edges. diff --git a/plugins/graph_algorithm/src/netlist_graph.cpp b/plugins/graph_algorithm/src/netlist_graph.cpp index e99b1a294b3..fefd434d9b4 100644 --- a/plugins/graph_algorithm/src/netlist_graph.cpp +++ b/plugins/graph_algorithm/src/netlist_graph.cpp @@ -14,12 +14,23 @@ namespace hal { } + NetlistGraph::NetlistGraph(Netlist* nl, igraph_t&& graph, std::unordered_map&& nodes_to_gates) : m_nl(nl), m_graph(std::move(graph)), m_nodes_to_gates(std::move(nodes_to_gates)) + { + for (const auto& [node, gate] : m_nodes_to_gates) + { + if (gate) + { + m_gates_to_nodes[gate] = node; + } + } + } + NetlistGraph::~NetlistGraph() { igraph_destroy(&m_graph); } - Result> NetlistGraph::from_netlist(Netlist* nl, bool create_dummy_nodes, const std::function& filter) + Result> NetlistGraph::from_netlist(Netlist* nl, bool create_dummy_vertices, const std::function& filter) { if (!nl) { @@ -44,13 +55,13 @@ namespace hal dst_gates.push_back(dst_ep->get_gate()); } - if (src_gates.empty() && create_dummy_nodes) + if (src_gates.empty() && create_dummy_vertices) { // if no sources, add one dummy edge for every destination // all dummy edges will come from the same dummy node edge_counter += dst_gates.size(); } - else if (dst_gates.empty() && create_dummy_nodes) + else if (dst_gates.empty() && create_dummy_vertices) { // if no destinations, add one dummy edge for every source // all dummy edges will go to the same dummy node @@ -96,7 +107,7 @@ namespace hal dst_gates.push_back(dst_ep->get_gate()); } - if (src_gates.empty() && create_dummy_nodes) + if (src_gates.empty() && create_dummy_vertices) { // if no sources, add one dummy node const u32 dummy_node = node_counter++; @@ -107,7 +118,7 @@ namespace hal VECTOR(edges)[edge_index++] = graph->m_gates_to_nodes.at(dst_gate); } } - else if (dst_gates.empty() && create_dummy_nodes) + else if (dst_gates.empty() && create_dummy_vertices) { // if no destinations, add one dummy node const u32 dummy_node = node_counter++;