7 namespace graph_algorithm
13 return ERR(
"graph is a nullptr");
16 if (start_gates.empty())
18 return ERR(
"no start gates provided");
21 igraph_vector_int_t i_gates;
24 i_gates = std::move(res.get());
28 return ERR(res.get_error());
33 igraph_vector_int_destroy(&i_gates);
37 return ERR(res.get_error());
47 return ERR(
"graph is a nullptr");
50 if (start_vertices.empty())
52 return ERR(
"no start vertices provided");
55 igraph_vector_int_t i_gates;
56 if (
auto res = igraph_vector_int_init(&i_gates, start_vertices.size()); res != IGRAPH_SUCCESS)
58 return ERR(igraph_strerror(res));
61 for (
u32 i = 0; i < start_vertices.size(); i++)
63 VECTOR(i_gates)[i] = start_vertices.at(i);
68 igraph_vector_int_destroy(&i_gates);
72 return ERR(res.get_error());
82 return ERR(
"graph is a nullptr");
85 igraph_vs_t v_sel = igraph_vss_vector(start_vertices);
86 igraph_neimode_t mode;
99 igraph_vs_destroy(&v_sel);
100 return ERR(
"invalid direction 'NONE'");
103 igraph_vector_int_list_t neighborhoods_raw;
104 if (
auto res = igraph_vector_int_list_init(&neighborhoods_raw, 1); res != IGRAPH_SUCCESS)
106 igraph_vs_destroy(&v_sel);
107 return ERR(igraph_strerror(res));
110 if (
auto res = igraph_neighborhood(graph->
get_graph(), &neighborhoods_raw, v_sel, order, mode, min_dist); res != IGRAPH_SUCCESS)
112 igraph_vs_destroy(&v_sel);
113 igraph_vector_int_list_destroy(&neighborhoods_raw);
114 return ERR(igraph_strerror(res));
117 std::vector<std::vector<u32>> neighborhoods;
118 const u32 num_neighborhoods = igraph_vector_int_list_size(&neighborhoods_raw);
119 for (
u32 i = 0; i < num_neighborhoods; i++)
121 auto vec = igraph_vector_int_list_get_ptr(&neighborhoods_raw, i);
123 const u32 vec_size = igraph_vector_int_size(vec);
124 std::vector<u32> tmp(vec_size);
125 for (
u32 j = 0; j < vec_size; j++)
127 tmp[j] = VECTOR(*vec)[j];
129 neighborhoods.push_back(std::move(tmp));
132 igraph_vs_destroy(&v_sel);
133 igraph_vector_int_list_destroy(&neighborhoods_raw);
135 return OK(neighborhoods);
A directed graph corresponding to a netlist.
Direction
The direction of exploration within the graph.
@ ALL
Explore in both directions, i.e., treat the graph as undirected.
@ NONE
No direction, invalid default setting.
@ IN
Explore through the inputs of the current node, i.e., traverse backwards.
@ OUT
Explore through the outputs of the current node, i.e., traverse forwards.
Result< igraph_vector_int_t > get_vertices_from_gates_igraph(const std::vector< Gate * > &gates) const
Get the vertices corresponding to the specified gates.
igraph_t * get_graph() const
Get the graph object of the netlist graph.
Result< std::vector< std::vector< u32 > > > get_neighborhood_igraph(NetlistGraph *graph, const igraph_vector_int_t *start_vertices, u32 order, NetlistGraph::Direction direction, u32 min_dist=0)
Compute the neighborhood of the given order for each of the specified vertices within the given netli...
Result< std::vector< std::vector< u32 > > > get_neighborhood(NetlistGraph *graph, const std::vector< Gate * > &start_gates, u32 order, NetlistGraph::Direction direction, u32 min_dist=0)
Compute the neighborhood of the given order for each of the specified gates within the given netlist ...
This file contains functions related to neighborhoods in graphs.