1
+ // MIT License
2
+ //
3
+ // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4
+ // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5
+ // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6
+ // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7
+ //
8
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ // of this software and associated documentation files (the "Software"), to deal
10
+ // in the Software without restriction, including without limitation the rights
11
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ // copies of the Software, and to permit persons to whom the Software is
13
+ // furnished to do so, subject to the following conditions:
14
+ //
15
+ // The above copyright notice and this permission notice shall be included in all
16
+ // copies or substantial portions of the Software.
17
+ //
18
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ // SOFTWARE.
25
+
26
+ /* *
27
+ * @file centrality.h
28
+ * @brief This file contains functions related to centrality metrics in graphs.
29
+ */
30
+
31
+ #pragma once
32
+
33
+ #include " graph_algorithm/netlist_graph.h"
34
+ #include " hal_core/defines.h"
35
+ #include " hal_core/utilities/result.h"
36
+
37
+ #include < igraph/igraph.h>
38
+ #include < set>
39
+
40
+ namespace hal
41
+ {
42
+ class Gate ;
43
+
44
+ namespace graph_algorithm
45
+ {
46
+ /* *
47
+ * @brief Compute the harmonic centrality for a set of gates within a given graph.
48
+ *
49
+ * Harmonic centrality is a measure of centrality in a graph that is computed based on the inverse distances to all other vertices in the graph.
50
+ * In this version, the input vertices are provided as `Gate*` pointers. The specified `direction` parameter
51
+ * determines the edge direction to be considered when computing shortest paths.
52
+ *
53
+ * @param[in] graph - The netlist graph for which the harmonic centrality is to be computed.
54
+ * @param[in] gates - The gates representing vertices in the graph for which centrality should be computed.
55
+ * @param[in] direction - The direction of edges to consider (forward, backward, or both).
56
+ * @param[in] cutoff - The maximum path length to consider during computation. Defaults to `-1` (no cutoff).
57
+ * @returns OK() and a vector of centrality values (in the same order as the input gates) on success, an error otherwise.
58
+ */
59
+ Result<std::vector<double >> get_harmonic_centrality (const NetlistGraph* graph, const std::vector<Gate*>& gates, const NetlistGraph::Direction direction, const i32 cutoff = -1 );
60
+
61
+ /* *
62
+ * @brief Compute the harmonic centrality for a set of vertices within a given graph.
63
+ *
64
+ * Harmonic centrality is a measure of centrality in a graph that is computed based on the inverse distances to all other vertices in the graph.
65
+ * In this version, the input vertices are provided as their vertex IDs. The specified `direction` parameter
66
+ * determines the edge direction to be considered when computing shortest paths.
67
+ *
68
+ * @param[in] graph - The netlist graph for which the harmonic centrality is to be computed.
69
+ * @param[in] vertices - The vertex IDs for which centrality should be computed.
70
+ * @param[in] direction - The direction of edges to consider (forward, backward, or both).
71
+ * @param[in] cutoff - The maximum path length to consider during computation. Defaults to `-1` (no cutoff).
72
+ * @returns OK() and a vector of centrality values (in the same order as the input vertices) on success, an error otherwise.
73
+ */
74
+ Result<std::vector<double >> get_harmonic_centrality (const NetlistGraph* graph, const std::vector<u32>& vertices, const NetlistGraph::Direction direction, const i32 cutoff = -1 );
75
+
76
+ /* *
77
+ * @brief Compute the harmonic centrality for a set of vertices within a given graph.
78
+ *
79
+ * Harmonic centrality is a measure of centrality in a graph that is computed based on the inverse distances to all other vertices in the graph.
80
+ * In this version, the input vertices are provided as an `igraph_vector_int_t`, which is typically used by the underlying igraph library.
81
+ * The specified `direction` parameter determines the edge direction to be considered when computing shortest paths.
82
+ *
83
+ * @param[in] graph - The netlist graph for which the harmonic centrality is to be computed.
84
+ * @param[in] vertices - A pointer to an `igraph_vector_int_t` containing the vertex IDs for which centrality should be computed.
85
+ * @param[in] direction - The direction of edges to consider (forward, backward, or both).
86
+ * @param[in] cutoff - The maximum path length to consider during computation. Defaults to `-1` (no cutoff).
87
+ * @returns OK() and a vector of centrality values (in the same order as the input vertices) on success, an error otherwise.
88
+ */
89
+ Result<std::vector<double >> get_harmonic_centrality (const NetlistGraph* graph, const igraph_vector_int_t * vertices, const NetlistGraph::Direction direction, const i32 cutoff = -1 );
90
+
91
+ /* *
92
+ * @brief Compute the betweenness centrality for a set of gates within a given graph.
93
+ *
94
+ * Betweenness centrality is a measure of centrality in a graph that is based on the number of shortest paths passing through a vertex.
95
+ * In this version, the input vertices are provided as `Gate*` pointers. The `directed` parameter determines whether edges
96
+ * are considered as directed or undirected when computing shortest paths.
97
+ *
98
+ * @param[in] graph - The netlist graph for which the betweenness centrality is to be computed.
99
+ * @param[in] gates - The gates representing vertices in the graph for which centrality should be computed.
100
+ * @param[in] directed - If `true`, consider the graph directed; if `false`, consider it undirected.
101
+ * @param[in] cutoff - The maximum path length to consider during computation. Defaults to `-1` (no cutoff).
102
+ * @returns OK() and a vector of centrality values (in the same order as the input gates) on success, an error otherwise.
103
+ */
104
+ Result<std::vector<double >> get_betweenness_centrality (const NetlistGraph* graph, const std::vector<Gate*>& gates, const bool directed, const i32 cutoff = -1 );
105
+
106
+ /* *
107
+ * @brief Compute the betweenness centrality for a set of vertices within a given graph.
108
+ *
109
+ * Betweenness centrality is a measure of centrality in a graph that is based on the number of shortest paths passing through a vertex.
110
+ * In this version, the input vertices are provided as their vertex IDs. The `directed` parameter determines whether edges
111
+ * are considered as directed or undirected.
112
+ *
113
+ * @param[in] graph - The netlist graph for which the betweenness centrality is to be computed.
114
+ * @param[in] vertices - The vertex IDs for which centrality should be computed.
115
+ * @param[in] directed - If `true`, consider the graph directed; if `false`, consider it undirected.
116
+ * @param[in] cutoff - The maximum path length to consider during computation. Defaults to `-1` (no cutoff).
117
+ * @returns OK() and a vector of centrality values (in the same order as the input vertices) on success, an error otherwise.
118
+ */
119
+ Result<std::vector<double >> get_betweenness_centrality (const NetlistGraph* graph, const std::vector<u32>& vertices, const bool directed, const i32 cutoff = -1 );
120
+
121
+ /* *
122
+ * @brief Compute the betweenness centrality for a set of vertices within a given graph.
123
+ *
124
+ * Betweenness centrality is a measure of centrality in a graph that is based on the number of shortest paths passing through a vertex.
125
+ * In this version, the input vertices are provided as an `igraph_vector_int_t`, which is typically used by the underlying igraph library.
126
+ * The `directed` parameter determines whether edges are considered as directed or undirected.
127
+ *
128
+ * @param[in] graph - The netlist graph for which the betweenness centrality is to be computed.
129
+ * @param[in] vertices - A pointer to an `igraph_vector_int_t` containing the vertex IDs for which centrality should be computed.
130
+ * @param[in] directed - If `true`, consider the graph directed; if `false`, consider it undirected.
131
+ * @param[in] cutoff - The maximum path length to consider during computation. Defaults to `-1` (no cutoff).
132
+ * @returns OK() and a vector of centrality values (in the same order as the input vertices) on success, an error otherwise.
133
+ */
134
+ Result<std::vector<double >> get_betweenness_centrality (const NetlistGraph* graph, const igraph_vector_int_t * vertices, const bool directed, const i32 cutoff = -1 );
135
+
136
+ } // namespace graph_algorithm
137
+ } // namespace hal
0 commit comments