8 namespace graph_algorithm
14 return ERR(
"graph is a nullptr");
19 return ERR(
"no source gate provided");
24 return ERR(
"no destination gates provided");
30 from_vertex = res.get();
34 return ERR(res.get_error());
37 igraph_vector_int_t i_to_vertices;
40 i_to_vertices = std::move(res.get());
44 return ERR(res.get_error());
49 igraph_vector_int_destroy(&i_to_vertices);
53 return ERR(res.get_error());
63 return ERR(
"graph is a nullptr");
66 if (to_vertices.empty())
68 return ERR(
"no destination vertices provided");
71 igraph_vector_int_t i_to_vertices;
72 if (
auto res = igraph_vector_int_init(&i_to_vertices, to_vertices.size()); res != IGRAPH_SUCCESS)
74 return ERR(igraph_strerror(res));
77 for (
u32 i = 0; i < to_vertices.size(); i++)
79 VECTOR(i_to_vertices)[i] = to_vertices.at(i);
84 igraph_vector_int_destroy(&i_to_vertices);
88 return ERR(res.get_error());
98 return ERR(
"graph is a nullptr");
101 igraph_neimode_t mode;
114 return ERR(
"invalid direction 'NONE'");
117 igraph_vs_t v_sel = igraph_vss_vector(to_vertices);
118 igraph_vector_int_list_t paths_raw;
119 if (
auto res = igraph_vector_int_list_init(&paths_raw, 1); res != IGRAPH_SUCCESS)
121 igraph_vs_destroy(&v_sel);
122 return ERR(igraph_strerror(res));
125 if (
auto res = igraph_get_shortest_paths(graph->
get_graph(), &paths_raw,
nullptr, from_vertex, v_sel, mode,
nullptr,
nullptr); res != IGRAPH_SUCCESS)
127 igraph_vs_destroy(&v_sel);
128 igraph_vector_int_list_destroy(&paths_raw);
129 return ERR(igraph_strerror(res));
132 std::vector<std::vector<u32>> paths;
133 for (
u32 i = 0; i < igraph_vector_int_list_size(&paths_raw); i++)
135 auto vec = igraph_vector_int_list_get_ptr(&paths_raw, i);
137 u32 vec_size = igraph_vector_int_size(vec);
138 std::vector<u32> tmp(vec_size);
139 for (
u32 j = 0; j < igraph_vector_int_size(vec); j++)
141 tmp[j] = VECTOR(*vec)[j];
143 paths.push_back(std::move(tmp));
146 igraph_vs_destroy(&v_sel);
147 igraph_vector_int_list_destroy(&paths_raw);
154 if (graph ==
nullptr)
156 return ERR(
"graph is a nullptr");
161 return ERR(
"no source gate provided");
164 if (to_gates.empty())
166 return ERR(
"no destination gates provided");
172 from_vertex = res.get();
176 return ERR(res.get_error());
179 igraph_vector_int_t i_to_vertices;
182 i_to_vertices = std::move(res.get());
186 return ERR(res.get_error());
191 igraph_vector_int_destroy(&i_to_vertices);
195 return ERR(res.get_error());
203 if (graph ==
nullptr)
205 return ERR(
"graph is a nullptr");
208 if (to_vertices.empty())
210 return ERR(
"no destination vertices provided");
213 igraph_vector_int_t i_to_vertices;
214 if (
auto res = igraph_vector_int_init(&i_to_vertices, to_vertices.size()); res != IGRAPH_SUCCESS)
216 return ERR(igraph_strerror(res));
219 for (
u32 i = 0; i < to_vertices.size(); i++)
221 VECTOR(i_to_vertices)[i] = to_vertices.at(i);
226 igraph_vector_int_destroy(&i_to_vertices);
230 return ERR(res.get_error());
238 if (graph ==
nullptr)
240 return ERR(
"graph is a nullptr");
243 igraph_neimode_t mode;
256 return ERR(
"invalid direction 'NONE'");
259 igraph_vs_t v_sel = igraph_vss_vector(to_vertices);
260 igraph_vector_int_list_t paths_raw;
261 if (
auto res = igraph_vector_int_list_init(&paths_raw, 1); res != IGRAPH_SUCCESS)
263 igraph_vs_destroy(&v_sel);
264 return ERR(igraph_strerror(res));
267 if (
auto res = igraph_get_all_shortest_paths(graph->
get_graph(), &paths_raw,
nullptr,
nullptr, from_vertex, v_sel, mode); res != IGRAPH_SUCCESS)
269 igraph_vs_destroy(&v_sel);
270 igraph_vector_int_list_destroy(&paths_raw);
271 return ERR(igraph_strerror(res));
274 std::vector<std::vector<u32>> paths;
275 const u32 paths_size = igraph_vector_int_list_size(&paths_raw);
276 for (
u32 i = 0; i < paths_size; i++)
278 auto vec = igraph_vector_int_list_get_ptr(&paths_raw, i);
280 const u32 vec_size = igraph_vector_int_size(vec);
281 std::vector<u32> tmp(vec_size);
282 for (
u32 j = 0; j < vec_size; j++)
284 tmp[j] = VECTOR(*vec)[j];
286 paths.push_back(std::move(tmp));
289 igraph_vs_destroy(&v_sel);
290 igraph_vector_int_list_destroy(&paths_raw);
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< u32 > get_vertex_from_gate(Gate *g) const
Get the vertex corresponding to the specified gate.
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_all_shortest_paths(NetlistGraph *graph, Gate *from_gate, const std::vector< Gate * > &to_gates, NetlistGraph::Direction direction)
Compute shortest paths from the specified from_gate to each of the given to_gates by traversing in th...
Result< std::vector< std::vector< u32 > > > get_shortest_paths(NetlistGraph *graph, Gate *from_gate, const std::vector< Gate * > &to_gates, NetlistGraph::Direction direction)
Compute a shortest path from the specified from_gate to each of the given to_gates by traversing in t...
Result< std::vector< std::vector< u32 > > > get_all_shortest_paths_igraph(NetlistGraph *graph, u32 from_vertex, const igraph_vector_int_t *to_vertices, NetlistGraph::Direction direction)
Compute shortest paths from the specified from_vertex to each of the given to_vertices by traversing ...
Result< std::vector< std::vector< u32 > > > get_shortest_paths_igraph(NetlistGraph *graph, u32 from_vertex, const igraph_vector_int_t *to_vertices, NetlistGraph::Direction direction)
Compute a shortest path from the specified from_vertex to each of the given to_vertices by traversing...
This file contains the class that holds a netlist graph.
This file contains functions related to shortest paths in graphs.