11 #pragma GCC diagnostic push
12 #pragma GCC diagnostic ignored "-Wshadow"
14 #pragma clang diagnostic ignored "-Wself-assign-overloaded"
15 #pragma clang diagnostic ignored "-Wnested-anon-types"
16 #pragma clang diagnostic ignored "-Wshadow-field-in-constructor-modified"
25 #include "pybind11/operators.h"
26 #include "pybind11/pybind11.h"
27 #include "pybind11/stl.h"
28 #include "pybind11/stl_bind.h"
30 #pragma GCC diagnostic pop
35 #ifdef PYBIND11_MODULE
36 PYBIND11_MODULE(graph_algorithm, m)
38 m.doc() =
"Graph algorithms based on igraph operating on a netlist graph abstraction.";
42 py::module m(
"graph_algorithm",
"Graph algorithms based on igraph operating on a netlist graph abstraction.");
45 py::class_<GraphAlgorithmPlugin, RawPtrWrapper<GraphAlgorithmPlugin>,
BasePluginInterface> py_graph_algorithm_plugin(m,
"GraphAlgorithmPlugin");
48 The name of the plugin.
54 Get the name of the plugin.
56 :returns: The name of the plugin.
61 The version of the plugin.
67 Get the version of the plugin.
69 :returns: The version of the plugin.
74 The description of the plugin.
80 Get the description of the plugin.
82 :returns: The description of the plugin.
87 A set of plugin names that this plugin depends on.
93 Get a set of plugin names that this plugin depends on.
95 :returns: A set of plugin names that this plugin depends on.
99 py::class_<graph_algorithm::NetlistGraph> py_netlist_graph(m, "NetlistGraph", R
"(
100 Holds a directed graph corresponding to a netlist.
103 py::enum_<graph_algorithm::NetlistGraph::Direction>(py_netlist_graph, "Direction", R
"(
104 The direction of exploration within the graph.
112 py_netlist_graph.def_static(
114 [](
Netlist* nl,
bool create_dummy_vertices =
false,
const std::function<
bool(
const Net*)>& filter =
nullptr) -> std::unique_ptr<graph_algorithm::NetlistGraph> {
122 log_error(
"python_context",
"error encountered while creating a graph from a netlist:\n{}", res.get_error().get());
127 py::arg(
"create_dummy_vertices") =
false,
128 py::arg(
"filter") =
nullptr,
129 py::keep_alive<0, 1>(),
130 R
"(Create a directed graph from a netlist. Optionally create dummy nodes at nets missing a source or destination. An optional filter can be applied to exclude undesired edges.
132 :param hal_py.Netlist nl: The netlist.
133 :param bool create_dummy_vertices: Set ``True`` to create dummy vertices, ``False`` otherwise. Defaults to ``False``.
134 :param lambda filter: An optional filter that is evaluated on every net of the netlist. Defaults to ``None``.
135 :returns: The netlist graph on success, ``None`` otherwise.
136 :rtype: graph_algorithm.NetlistGraph or None
139 py_netlist_graph.def_static(
140 "from_netlist_no_edges",
141 [](
Netlist* nl,
const std::vector<Gate*>& gates = {}) -> std::unique_ptr<graph_algorithm::NetlistGraph> {
149 log_error(
"python_context",
"error encountered while creating a graph from a netlist:\n{}", res.get_error().get());
154 py::arg(
"gates") = std::vector<Gate*>(),
155 py::keep_alive<0, 1>(),
156 R
"(Create an empty directed graph from a netlist, i.e., vertices for all gates are created, but no edges are added.
158 :param hal_py.Netlist nl: The netlist.
159 :param list[hal_py.Gate] gates: The gates to include in the graph. If omitted, all gates of the netlist will be included.
160 :returns: The netlist graph on success, ``None`` otherwise.
161 :rtype: graph_algorithm.NetlistGraph or None
164 py_netlist_graph.def_static(
166 [](
const std::vector<Gate*>& gates,
const std::set<Gate*>& split_gates = {},
const std::function<bool(
const Net*)>& filter =
nullptr) -> std::unique_ptr<graph_algorithm::NetlistGraph> {
174 log_error(
"python_context",
"error encountered while creating a graph from a set of gates:\n{}", res.get_error().get());
179 py::arg(
"split_gates") = std::set<Gate*>(),
180 py::arg(
"filter") =
nullptr,
181 py::keep_alive<0, 1>(),
182 R
"(Create a directed graph from a subset of the gates of a netlist.
184 Only the given gates become vertices and only nets between two of them become edges, so the graph is a closed world irrespective of what the gates are connected to elsewhere in the netlist.
186 Gates in ``split_gates`` are represented by two vertices instead of one: a primary vertex carrying only the outgoing edges of the gate and a shadow vertex carrying only its incoming edges.
187 This breaks feedback through those gates, which makes a sequential loop such as the round function of a cipher acyclic without having to copy it into a netlist of its own.
188 Both vertices resolve back to the same gate, so use ``is_shadow_vertex`` to tell the two roles apart.
189 A shadow vertex is only created if the gate actually has incoming edges within the graph.
191 Vertices are numbered in the order of ``gates``, so pass them in a deterministic order to obtain a reproducible graph.
193 :param list[hal_py.Gate] gates: The gates to include in the graph. Must all belong to the same netlist.
194 :param set[hal_py.Gate] split_gates: The gates to represent by a primary and a shadow vertex. Gates that are not part of ``gates`` are ignored. Defaults to an empty set.
195 :param lambda filter: An optional filter that is evaluated on every net considered as an edge. Defaults to ``None``.
196 :returns: The netlist graph on success, ``None`` otherwise.
197 :rtype: graph_algorithm.NetlistGraph or None
200 py_netlist_graph.def(
203 auto res =
self.copy();
210 log_error(
"python_context",
"error encountered while copying netlist graph:\n{}", res.get_error().get());
214 py::keep_alive<0, 1>(),
216 Create a deep copy of the netlist graph.
218 :returns: The copied netlist graph on success, ``None`` otherwise.
219 :rtype: graph_algorithm.NetlistGraph or None
223 Get the netlist associated with the netlist graph.
225 :returns: The netlist.
226 :rtype: hal_py.Netlist
229 py_netlist_graph.def(
230 "get_gates_from_vertices",
232 auto res =
self.get_gates_from_vertices(vertices);
239 log_error(
"python_context",
"error encountered while getting gates from vertices:\n{}", res.get_error().get());
245 Get the gates corresponding to the specified list of vertices.
246 The result may contain ``None`` for dummy vertices.
248 :param list[int] vertices: A list of vertices.
249 :returns: A list of gates on success, ``None`` otherwise.
250 :rtype: list[hal_py.Gate] or None
253 py_netlist_graph.def(
254 "get_gates_from_vertices",
256 const auto res =
self.get_gates_from_vertices(vertices);
263 log_error(
"python_context",
"error encountered while getting gates from vertices:\n{}", res.get_error().get());
269 Get the gates corresponding to the specified set of vertices.
270 The result may contain ``None`` for dummy vertices.
272 :param set[int] vertices: A set of vertices.
273 :returns: A list of gates on success, ``None`` otherwise.
274 :rtype: list[hal_py.Gate] or None
277 py_netlist_graph.def(
278 "get_gates_set_from_vertices",
280 auto res =
self.get_gates_set_from_vertices(vertices);
287 log_error(
"python_context",
"error encountered while getting gates from vertices:\n{}", res.get_error().get());
293 Get the gates corresponding to the specified list of vertices.
295 :param list[int] vertices: A list of vertices.
296 :returns: A list of gates on success, ``None`` otherwise.
297 :rtype: set[hal_py.Gate] or None
300 py_netlist_graph.def(
301 "get_gates_set_from_vertices",
303 const auto res =
self.get_gates_set_from_vertices(vertices);
310 log_error(
"python_context",
"error encountered while getting gates from vertices:\n{}", res.get_error().get());
316 Get the gates corresponding to the specified set of vertices.
318 :param set[int] vertices: A set of vertices.
319 :returns: A list of gates on success, ``None`` otherwise.
320 :rtype: set[hal_py.Gate] or None
323 py_netlist_graph.def(
324 "get_gate_from_vertex",
326 const auto res =
self.get_gate_from_vertex(vertex);
333 log_error(
"python_context",
"error encountered while getting gate from vertex:\n{}", res.get_error().get());
339 Get the gates corresponding to the specified vertex.
341 :param int vertex: A vertex.
342 :returns: A gate on success, ``None`` otherwise.
343 :rtype: hal_py.Gate or None
346 py_netlist_graph.def(
347 "get_vertices_from_gates",
349 auto res =
self.get_vertices_from_gates(gates);
356 log_error(
"python_context",
"error encountered while getting vertices from gates:\n{}", res.get_error().get());
362 Get the vertices corresponding to the specified list of gates.
364 :param list[hal_py.Gate] gates: A list of gates.
365 :returns: A list of vertices on success, ``None`` otherwise.
366 :rtype: list[int] or None
369 py_netlist_graph.def(
370 "get_vertices_from_gates",
372 auto res =
self.get_vertices_from_gates(gates);
379 log_error(
"python_context",
"error encountered while getting vertices from gates:\n{}", res.get_error().get());
385 Get the vertices corresponding to the specified set of gates.
387 :param set[hal_py.Gate] gates: A set of gates.
388 :returns: A list of vertices on success, ``None`` otherwise.
389 :rtype: list[int] or None
392 py_netlist_graph.def(
393 "get_vertex_from_gate",
395 auto res =
self.get_vertex_from_gate(g);
402 log_error(
"python_context",
"error encountered while getting vertex from gate:\n{}", res.get_error().get());
408 Get the vertex corresponding to the specified gate.
410 :param hal_py.Gate g: A gate.
411 :returns: A vertex on success, ``None`` otherwise.
416 Check whether the specified vertex is a shadow vertex.
418 A shadow vertex carries only the incoming edges of a gate that was split by ``from_gates``, while the primary vertex of that gate carries only its outgoing edges.
419 Both resolve to the same gate, so this is the only way to tell which of the two roles a vertex stands for.
421 :param int vertex: A vertex.
422 :returns: ``True`` if the vertex is a shadow vertex, ``False`` otherwise.
426 py_netlist_graph.def(
427 "get_all_vertices_from_gate",
429 auto res =
self.get_all_vertices_from_gate(g);
436 log_error(
"python_context",
"error encountered while getting vertices from gate:\n{}", res.get_error().get());
442 Get all vertices corresponding to the specified gate, i.e., its primary vertex and, if the gate was split by ``from_gates``, its shadow vertex.
444 :param hal_py.Gate g: A gate.
445 :returns: The vertices of the gate on success, ``None`` otherwise.
446 :rtype: list[int] or None
450 Get the number of vertices in the netlist graph.
452 :param bool only_connected: Set ``True`` to only count vertices connected to at least one edge, ``False`` otherwise. Defaults to ``False``.
453 :returns: The number of vertices in the netlist graph.
458 Get the number of edges in the netlist graph.
460 :returns: The number of edges in the netlist graph.
464 py_netlist_graph.def(
467 auto res =
self.get_vertices(only_connected);
474 log_error(
"python_context",
"error encountered while getting vertices:\n{}", res.get_error().get());
478 py::arg(
"only_connected") =
false,
480 Get the vertices in the netlist graph.
482 :param bool only_connected: Set ``True`` to only return vertices connected to at least one edge, ``False`` otherwise. Defaults to ``False``.
483 :returns: A list of vertices on success, ``None`` otherwise.
484 :rtype: list[int] or None
487 py_netlist_graph.def(
490 auto res =
self.get_edges();
497 log_error(
"python_context",
"error encountered while getting edges:\n{}", res.get_error().get());
502 Get the edges between vertices in the netlist graph.
504 :returns: A list of edges on success, ``None`` otherwise.
505 :rtype: list[tuple(int,int)] or None
508 py_netlist_graph.def(
509 "get_edges_in_netlist",
511 auto res =
self.get_edges_in_netlist();
518 log_error(
"python_context",
"error encountered while getting edges:\n{}", res.get_error().get());
523 Get the edges between gates in the netlist corresponding to the netlist graph.
525 :returns: A list of edges on success, ``None`` otherwise.
526 :rtype: list[tuple(hal_py.Gate,hal_py.Gate)] or None
529 py_netlist_graph.def(
532 auto res =
self.add_edges(edges);
539 log_error(
"python_context",
"error encountered while adding edges:\n{}", res.get_error().get());
545 Add edges between the specified pairs of source and destination gates to the netlist graph.
546 The gates must already correspond to vertices in the graph.
548 :param list[tuple(hal_py.Gate,hal_py.Gate)] edges: The edges to add as pairs of gates.
549 :returns: ``True`` on success, ``False`` otherwise.
553 py_netlist_graph.def(
556 auto res =
self.add_edges(edges);
563 log_error(
"python_context",
"error encountered while adding edges:\n{}", res.get_error().get());
569 Add edges between the specified pairs of source and destination vertices to the netlist graph.
570 The vertices must already exist in the graph.
572 :param list[tuple(int,int)] edges: The edges to add as pairs of vertices.
573 :returns: ``True`` on success, ``False`` otherwise.
577 py_netlist_graph.def(
580 auto res =
self.add_edges(edges);
587 log_error(
"python_context",
"error encountered while adding edges:\n{}", res.get_error().get());
593 Add edges between the specified pairs of source and destination gates to the netlist graph.
594 The vertices must already exist in the graph.
596 :param dict[hal_py.Gate,set[hal_py.Gate]] edges: The edges to add as a dict from source gate to its destination gates.
597 :returns: ``True`` on success, ``False`` otherwise.
601 py_netlist_graph.def(
604 auto res =
self.delete_edges(edges);
611 log_error(
"python_context",
"error encountered while deleting edges:\n{}", res.get_error().get());
617 Delete edges between the specified pairs of source and destination gates from the netlist graph.
619 :param list[tuple(hal_py.Gate,hal_py.Gate)] edges: The edges to delete as pairs of gates.
620 :returns: ``True`` on success, ``False`` otherwise.
624 py_netlist_graph.def(
627 auto res =
self.delete_edges(edges);
634 log_error(
"python_context",
"error encountered while deleting edges:\n{}", res.get_error().get());
640 Delete edges between the specified pairs of source and destination vertices from the netlist graph.
642 :param list[tuple(int,int)] edges: The edges to delete as pairs of vertices.
643 :returns: ``True`` on success, ``False`` otherwise.
648 Print the edge list of the graph to stdout.
652 "get_connected_components",
661 log_error(
"python_context",
"error encountered while computing connected components:\n{}", res.get_error().get());
667 py::arg(
"min_size") = 0,
669 Compute the (strongly) connected components of the specified graph.
670 Returns each connected component as a list of vertices in the netlist graph.
672 :param graph_algorithm.NetlistGraph graph: The netlist graph.
673 :param bool strong: Set ``True`` to compute strongly connected components, ``False`` otherwise.
674 :param int min_size: Minimal size of a connected component to be part of the result. Set to ``0`` to include all components. Defaults to ``0``.
675 :returns: A list of strongly connected components on success, ``None`` otherwise.
676 :rtype: list[list[int]] or None
682 -> std::optional<std::vector<std::vector<u32>>> {
690 log_error(
"python_context",
"error encountered while computing neighborhood:\n{}", res.get_error().get());
695 py::arg(
"start_gates"),
697 py::arg(
"direction"),
698 py::arg(
"min_dist") = 0,
700 Compute the neighborhood of the given order for each of the specified gates within the given netlist graph.
701 For order 0, only the vertex itself is returned. For order 1, the vertex itself and all vertices that are its direct predecessors and/or successors (depending on the specified direction). For order 2, the neighborhood of order 1 plus all direct predecessors and/or successors of the vertices in order 1 are returned, etc.
702 Returns each neighborhood as a list of vertices in the netlist graph.
704 :param graph_algorithm.NetlistGraph graph: The netlist graph.
705 :param list[hal_py.Gate] start_gates: A list of gates for which to compute the neighborhood.
706 :param int order: The order of the neighborhood to compute.
707 :param graph_algorithm.NetlistGraph.Direction direction: The direction in which the neighborhood should be computed.
708 :param int min_dist: The minimum distance of the vertices to include in the result.
709 :returns: A list of neighborhoods of each of the provided start gates (in order) on success, ``None`` otherwise.
710 :rtype: list[list[int]] or None
716 -> std::optional<std::vector<std::vector<u32>>> {
724 log_error(
"python_context",
"error encountered while computing neighborhood:\n{}", res.get_error().get());
729 py::arg(
"start_vertices"),
731 py::arg(
"direction"),
732 py::arg(
"min_dist") = 0,
734 Compute the neighborhood of the given order for each of the specified vertices within the given netlist graph.
735 For order 0, only the vertex itself is returned. For order 1, the vertex itself and all vertices that are its direct predecessors and/or successors (depending on the specified direction). For order 2, the neighborhood of order 1 plus all direct predecessors and/or successors of the vertices in order 1 are returned, etc.
736 Returns each neighborhood as a list of vertices in the netlist graph.
738 :param graph_algorithm.NetlistGraph graph: The netlist graph.
739 :param list[int] start_vertices: A list of vertices for which to compute the neighborhood.
740 :param int order: The order of the neighborhood to compute.
741 :param graph_algorithm.NetlistGraph.Direction direction: The direction in which the neighborhood should be computed.
742 :param int min_dist: The minimum distance of the vertices to include in the result.
743 :returns: A list of neighborhoods of each of the provided start vertices (in order) on success, ``None`` otherwise.
744 :rtype: list[list[int]] or None
748 "get_shortest_paths",
750 -> std::optional<std::vector<std::vector<u32>>> {
758 log_error(
"python_context",
"error encountered while computing shortest paths:\n{}", res.get_error().get());
763 py::arg(
"from_gate"),
765 py::arg(
"direction"),
767 Compute a shortest path from the specified ``from_gate`` to each of the given ``to_gates`` by traversing in the provided direction.
768 Returns one shortest path for each end gate, even if multiple shortest paths exist.
769 Each shortest path is given as a list of vertices in the order of traversal.
771 :param graph_algorithm.NetlistGraph graph: The netlist graph.
772 :param hal_py.Gate from_gate: The start gate of the shortest path.
773 :param list[hal_py.Gate] to_gates: A list of end gates of the shortest path.
774 :param graph_algorithm.NetlistGraph.Direction direction: The direction in which to compute the shortest paths starting at the ``from_gate``.
775 :returns: The shortest paths in order of the ``to_gates`` on success, an error otherwise.
776 :rtype: list[list[int]] or None
780 "get_shortest_paths",
782 -> std::optional<std::vector<std::vector<u32>>> {
790 log_error(
"python_context",
"error encountered while computing shortest paths:\n{}", res.get_error().get());
795 py::arg(
"from_vertex"),
796 py::arg(
"to_vertices"),
797 py::arg(
"direction"),
799 Compute a shortest path from the specified ``from_vertex`` to each of the given ``to_vertices`` by traversing in the provided direction.
800 Returns one shortest path for each end vertex, even if multiple shortest paths exist.
801 Each shortest path is given as a list of vertices in the order of traversal.
803 :param graph_algorithm.NetlistGraph graph: The netlist graph.
804 :param int from_vertex: The start vertex of the shortest path.
805 :param list[int] to_vertices: A list of end vertices of the shortest path.
806 :param graph_algorithm.NetlistGraph.Direction direction: The direction in which to compute the shortest paths starting at the ``from_vertex``.
807 :returns: The shortest paths in order of the ``to_vertices`` on success, an error otherwise.
808 :rtype: list[list[int]] or None
812 "get_all_shortest_paths",
814 -> std::optional<std::vector<std::vector<u32>>> {
822 log_error(
"python_context",
"error encountered while computing all shortest paths:\n{}", res.get_error().get());
827 py::arg(
"from_gate"),
829 py::arg(
"direction"),
831 Compute shortest paths from the specified ``from_gate`` to each of the given ``to_gates`` by traversing in the provided direction.
832 Returns all shortest paths for each end gate.
833 Each shortest path is given as a list of vertices in the order of traversal.
835 :param graph_algorithm.NetlistGraph graph: The netlist graph.
836 :param hal_py.Gate from_gate: The start gate of the shortest path.
837 :param list[hal_py.Gate] to_gates: A list of end gates of the shortest path.
838 :param graph_algorithm.NetlistGraph.Direction direction: The direction in which to compute the shortest paths starting at the ``from_gate``.
839 :returns: The shortest paths in order of the ``to_gates`` on success, an error otherwise.
840 :rtype: list[list[int]] or None
844 "get_all_shortest_paths",
846 -> std::optional<std::vector<std::vector<u32>>> {
854 log_error(
"python_context",
"error encountered while computing all shortest paths:\n{}", res.get_error().get());
859 py::arg(
"from_vertex"),
860 py::arg(
"to_vertices"),
861 py::arg(
"direction"),
863 Compute shortest paths from the specified ``from_vertex`` to each of the given ``to_vertices`` by traversing in the provided direction.
864 Returns all shortest paths for each end gate.
865 Each shortest path is given as a list of vertices in the order of traversal.
867 :param graph_algorithm.NetlistGraph graph: The netlist graph.
868 :param int from_vertex: The start vertex of the shortest path.
869 :param list[int] to_vertices: A list of end vertices of the shortest path.
870 :param graph_algorithm.NetlistGraph.Direction direction: The direction in which to compute the shortest paths starting at the ``from_vertex``.
871 :returns: The shortest paths in order of the ``to_vertices`` on success, an error otherwise.
872 :rtype: list[list[int]] or None
877 [](
const graph_algorithm::NetlistGraph* graph,
const std::vector<Gate*>& subgraph_gates) -> std::optional<std::unique_ptr<graph_algorithm::NetlistGraph>> {
885 log_error(
"python_context",
"error encountered while computing subgraph:\n{}", res.get_error().get());
890 py::arg(
"subgraph_gates"),
891 py::keep_alive<0, 1>(),
893 Compute the subgraph induced by the specified gates, including all edges between the corresponding vertices.
895 :param graph_algorithm.NetlistGraph graph: The netlist graph.
896 :param list[hal_py.Gate] subgraph_gates: A list of gates that make up the subgraph.
897 :returns: The subgraph as a new netlist graph on success, ``None`` otherwise.
898 :rtype: graph_algorithm.NetlistGraph or None
903 [](
const graph_algorithm::NetlistGraph* graph,
const std::set<Gate*>& subgraph_gates) -> std::optional<std::unique_ptr<graph_algorithm::NetlistGraph>> {
911 log_error(
"python_context",
"error encountered while computing subgraph:\n{}", res.get_error().get());
916 py::arg(
"subgraph_gates"),
917 py::keep_alive<0, 1>(),
919 Compute the subgraph induced by the specified gates, including all edges between the corresponding vertices.
921 :param graph_algorithm.NetlistGraph graph: The netlist graph.
922 :param set[hal_py.Gate] subgraph_gates: A set of gates that make up the subgraph.
923 :returns: The subgraph as a new netlist graph on success, ``None`` otherwise.
924 :rtype: graph_algorithm.NetlistGraph or None
929 [](
const graph_algorithm::NetlistGraph* graph,
const std::vector<u32>& subgraph_vertices) -> std::optional<std::unique_ptr<graph_algorithm::NetlistGraph>> {
937 log_error(
"python_context",
"error encountered while computing subgraph:\n{}", res.get_error().get());
942 py::arg(
"subgraph_vertices"),
943 py::keep_alive<0, 1>(),
945 Compute the subgraph induced by the specified vertices, including all edges between these vertices.
947 :param graph_algorithm.NetlistGraph graph: The netlist graph.
948 :param list[int] subgraph_vertices: A list of vertices that make up the subgraph.
949 :returns: The subgraph as a new netlist graph on success, ``None`` otherwise.
950 :rtype: graph_algorithm.NetlistGraph or None
955 [](
const graph_algorithm::NetlistGraph* graph,
const std::set<u32>& subgraph_vertices) -> std::optional<std::unique_ptr<graph_algorithm::NetlistGraph>> {
963 log_error(
"python_context",
"error encountered while computing subgraph:\n{}", res.get_error().get());
968 py::arg(
"subgraph_vertices"),
969 py::keep_alive<0, 1>(),
971 Compute the subgraph induced by the specified vertices, including all edges between these vertices.
973 :param graph_algorithm.NetlistGraph graph: The netlist graph.
974 :param set[int] subgraph_vertices: A set of vertices that make up the subgraph.
975 :returns: The subgraph as a new netlist graph on success, ``None`` otherwise.
976 :rtype: graph_algorithm.NetlistGraph or None
979 #ifndef PYBIND11_MODULE
std::string get_description() const override
Get a short description of the plugin.
std::string get_version() const override
Get the version of the plugin.
std::set< std::string > get_dependencies() const override
Get the plugin dependencies.
std::string get_name() const override
Get the name of the plugin.
A directed graph corresponding to a netlist.
Netlist * get_netlist() const
Get the netlist associated with the netlist graph.
u32 get_num_vertices(bool only_connected=false) const
Get the number of vertices in the netlist graph.
bool is_shadow_vertex(const u32 vertex) const
Check whether the specified vertex is a shadow vertex.
static Result< std::unique_ptr< NetlistGraph > > from_netlist(Netlist *nl, bool create_dummy_vertices=false, const std::function< bool(const Net *)> &filter=nullptr)
Create a directed graph from 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.
static Result< std::unique_ptr< NetlistGraph > > from_gates(const std::vector< Gate * > &gates, const std::set< Gate * > &split_gates={}, const std::function< bool(const Net *)> &filter=nullptr)
Create a directed graph from a subset of the gates of a netlist.
void print() const
Print the edge list of the graph to stdout.
u32 get_num_edges() const
Get the number of edges in the netlist graph.
static Result< std::unique_ptr< NetlistGraph > > from_netlist_no_edges(Netlist *nl, const std::vector< Gate * > &gates={})
Create an empty directed graph from a netlist.
This file contains functions related to graph components.
#define log_error(channel,...)
const Module * module(const Gate *g, const NodeBoxes &boxes)
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_connected_components(const NetlistGraph *graph, bool strong, u32 min_size=0)
Compute the (strongly) connected components of the specified graph.
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::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...
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.
This file contains the class that holds a netlist graph.
This file contains all functions related to the HAL plugin API.
This file contains functions related to shortest paths in graphs.
This file contains functions related to subgraphs.