8 namespace graph_algorithm
14 return ERR(
"graph is a nullptr");
17 if (subgraph_gates.empty())
19 return ERR(
"no subgraph gates provided");
22 igraph_vector_int_t i_gates;
25 i_gates = std::move(res.get());
29 return ERR(res.get_error());
34 igraph_vector_int_destroy(&i_gates);
38 return ERR(res.get_error());
48 return ERR(
"graph is a nullptr");
51 if (subgraph_gates.empty())
53 return ERR(
"no subgraph gates provided");
56 igraph_vector_int_t i_gates;
59 i_gates = std::move(res.get());
63 return ERR(res.get_error());
68 igraph_vector_int_destroy(&i_gates);
72 return ERR(res.get_error());
82 return ERR(
"graph is a nullptr");
85 if (subgraph_vertices.empty())
87 return ERR(
"no subgraph vertices provided");
90 igraph_vector_int_t i_gates;
91 if (
auto res = igraph_vector_int_init(&i_gates, subgraph_vertices.size()); res != IGRAPH_SUCCESS)
93 return ERR(igraph_strerror(res));
96 for (
u32 i = 0; i < subgraph_vertices.size(); i++)
98 VECTOR(i_gates)[i] = subgraph_vertices.at(i);
103 igraph_vector_int_destroy(&i_gates);
107 return ERR(res.get_error());
115 if (graph ==
nullptr)
117 return ERR(
"graph is a nullptr");
120 if (subgraph_vertices.empty())
122 return ERR(
"no subgraph vertices provided");
125 igraph_vector_int_t i_gates;
126 if (
auto res = igraph_vector_int_init(&i_gates, subgraph_vertices.size()); res != IGRAPH_SUCCESS)
128 return ERR(igraph_strerror(res));
132 for (
auto it = subgraph_vertices.begin(); it != subgraph_vertices.end(); it++)
134 VECTOR(i_gates)[i] = *it;
140 igraph_vector_int_destroy(&i_gates);
144 return ERR(res.get_error());
152 if (graph ==
nullptr)
154 return ERR(
"graph is a nullptr");
157 igraph_vs_t v_sel = igraph_vss_vector(subgraph_vertices);
158 u32 subgraph_size = igraph_vector_int_size(subgraph_vertices);
160 igraph_vector_int_t i_vertex_map;
161 if (
auto res = igraph_vector_int_init(&i_vertex_map, subgraph_size); res != IGRAPH_SUCCESS)
163 igraph_vs_destroy(&v_sel);
164 return ERR(igraph_strerror(res));
168 if (
const auto res = igraph_induced_subgraph_map(graph->
get_graph(), &i_subg, v_sel, IGRAPH_SUBGRAPH_AUTO,
nullptr, &i_vertex_map); res != IGRAPH_SUCCESS)
170 igraph_vs_destroy(&v_sel);
171 igraph_vector_int_destroy(&i_vertex_map);
172 return ERR(igraph_strerror(res));
175 std::unordered_map<u32, Gate*> nodes_to_gates;
178 std::vector<Gate*> gates = res.get();
179 for (
u32 i = 0; i < gates.size(); i++)
181 nodes_to_gates[i] = gates.at(i);
186 igraph_destroy(&i_subg);
187 igraph_vs_destroy(&v_sel);
188 igraph_vector_int_destroy(&i_vertex_map);
189 return ERR(res.get_error());
192 auto subgraph = std::unique_ptr<NetlistGraph>(
new NetlistGraph(graph->
get_netlist(), std::move(i_subg), std::move(nodes_to_gates)));
194 igraph_vs_destroy(&v_sel);
195 igraph_vector_int_destroy(&i_vertex_map);
197 return OK(std::move(subgraph));
A directed graph corresponding to a netlist.
Netlist * get_netlist() const
Get the netlist associated with the netlist graph.
Result< igraph_vector_int_t > get_vertices_from_gates_igraph(const std::vector< Gate * > &gates) const
Get the vertices corresponding to the specified gates.
Result< std::vector< Gate * > > get_gates_from_vertices_igraph(const igraph_vector_int_t *vertices) const
Get the gates corresponding to the specified vertices.
igraph_t * get_graph() const
Get the graph object of the netlist graph.
Result< std::unique_ptr< NetlistGraph > > get_subgraph_igraph(const NetlistGraph *graph, const igraph_vector_int_t *subgraph_vertices)
Compute the subgraph induced by the specified vertices, including all edges between these vertices.
Result< std::unique_ptr< NetlistGraph > > get_subgraph(const NetlistGraph *graph, const std::vector< Gate * > &subgraph_gates)
Compute the subgraph induced by the specified gates, including all edges between the corresponding ve...
This file contains the class that holds a netlist graph.
This file contains functions related to subgraphs.