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));
126 if (
auto res = igraph_get_shortest_paths(graph->
get_graph(),
nullptr, &paths_raw,
nullptr, from_vertex, v_sel, mode,
nullptr,
nullptr); res != IGRAPH_SUCCESS)
128 igraph_vs_destroy(&v_sel);
129 igraph_vector_int_list_destroy(&paths_raw);
130 return ERR(igraph_strerror(res));
133 std::vector<std::vector<u32>> paths;
134 for (
u32 i = 0; i < igraph_vector_int_list_size(&paths_raw); i++)
136 auto vec = igraph_vector_int_list_get_ptr(&paths_raw, i);
138 u32 vec_size = igraph_vector_int_size(vec);
139 std::vector<u32> tmp(vec_size);
140 for (
u32 j = 0; j < igraph_vector_int_size(vec); j++)
142 tmp[j] = VECTOR(*vec)[j];
144 paths.push_back(std::move(tmp));
147 igraph_vs_destroy(&v_sel);
148 igraph_vector_int_list_destroy(&paths_raw);
155 if (graph ==
nullptr)
157 return ERR(
"graph is a nullptr");
162 return ERR(
"no source gate provided");
165 if (to_gates.empty())
167 return ERR(
"no destination gates provided");
173 from_vertex = res.get();
177 return ERR(res.get_error());
180 igraph_vector_int_t i_to_vertices;
183 i_to_vertices = std::move(res.get());
187 return ERR(res.get_error());
192 igraph_vector_int_destroy(&i_to_vertices);
196 return ERR(res.get_error());
204 if (graph ==
nullptr)
206 return ERR(
"graph is a nullptr");
209 if (to_vertices.empty())
211 return ERR(
"no destination vertices provided");
214 igraph_vector_int_t i_to_vertices;
215 if (
auto res = igraph_vector_int_init(&i_to_vertices, to_vertices.size()); res != IGRAPH_SUCCESS)
217 return ERR(igraph_strerror(res));
220 for (
u32 i = 0; i < to_vertices.size(); i++)
222 VECTOR(i_to_vertices)[i] = to_vertices.at(i);
227 igraph_vector_int_destroy(&i_to_vertices);
231 return ERR(res.get_error());
239 if (graph ==
nullptr)
241 return ERR(
"graph is a nullptr");
244 igraph_neimode_t mode;
257 return ERR(
"invalid direction 'NONE'");
260 igraph_vs_t v_sel = igraph_vss_vector(to_vertices);
261 igraph_vector_int_list_t paths_raw;
262 if (
auto res = igraph_vector_int_list_init(&paths_raw, 1); res != IGRAPH_SUCCESS)
264 igraph_vs_destroy(&v_sel);
265 return ERR(igraph_strerror(res));
269 if (
auto res = igraph_get_all_shortest_paths(graph->
get_graph(),
nullptr, &paths_raw,
nullptr,
nullptr, from_vertex, v_sel, mode); res != IGRAPH_SUCCESS)
271 igraph_vs_destroy(&v_sel);
272 igraph_vector_int_list_destroy(&paths_raw);
273 return ERR(igraph_strerror(res));
276 std::vector<std::vector<u32>> paths;
277 const u32 paths_size = igraph_vector_int_list_size(&paths_raw);
278 for (
u32 i = 0; i < paths_size; i++)
280 auto vec = igraph_vector_int_list_get_ptr(&paths_raw, i);
282 const u32 vec_size = igraph_vector_int_size(vec);
283 std::vector<u32> tmp(vec_size);
284 for (
u32 j = 0; j < vec_size; j++)
286 tmp[j] = VECTOR(*vec)[j];
288 paths.push_back(std::move(tmp));
291 igraph_vs_destroy(&v_sel);
292 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.