Directed graphs with global source and global sink
This class is used in AbstractWalkModelDiGraph as a wrapper (with unique global source and unique global sink) to pass the directed graph to the ILP models.
stDiGraph
stDiGraph(
base_graph: DiGraph,
additional_starts: (
list | None
) = None,
additional_ends: (
list | None
) = None,
)
Bases: AbstractSourceSinkGraph
General directed graph with global source/sink and SCC condensation helpers.
This class now subclasses AbstractSourceSinkGraph
, which performs the common augmentation
(adding global source/sink and validating additional boundary nodes). The remaining
logic here focuses on strongly connected component (SCC) handling and the condensation
expansion used for width and incompatible sequence computations.
This class inherits from networkx.DiGraph. The graph equals base_graph
plus:
- a global source connected to all sources of
base_graph
and to all nodes inadditional_starts
; - a global sink connected from all sinks of
base_graph
and from all nodes inadditional_ends
.
Warning
The graph base_graph
must satisfy the following properties:
- the nodes must be strings;
base_graph
must have at least one source (i.e. node without incoming edges), or at least one node inadditional_starts
;base_graph
must have at least one sink (i.e. node without outgoing edges), or at least one node inadditional_ends
.
Raises:
ValueError
: If any of the above three conditions are not satisfied.ValueError
: If any node inadditional_starts
is not in the base graph.ValueError
: If any node inadditional_ends
is not in the base graph.
Source code in flowpaths/stdigraph.py
get_number_of_nontrivial_SCCs
Returns the number of non-trivial SCCs (i.e. SCCs with at least one edge).
Source code in flowpaths/stdigraph.py
get_size_of_largest_SCC
Returns the size of the largest SCC (in terms of number of edges).
get_width
Returns the width of the graph, which we define as the minimum number of \(s\)-\(t\) walks needed to cover all edges.
This is computed as the width of the condensation DAGs (minimum number of \(s\)-\(t\) paths to cover all edges), with the following modification.
Nodes v
in the condensation corresponding to non-trivial SCCs (i.e. SCCs with more than one node, equivalent to having at least one edge)
are subdivided into a edge (v, v_expanded)
, all condensation in-neighbors of v
are connected to v
,
and all condensation out-neighbors of v
are connected from v_expanded
.
Parameters:
-
edges_to_ignore
: A list of edges in the original graph to ignore when computing the width.The width is then computed as as above, with the exception that:
-
If an edge
(u,v)
inedges_to_ignore
is between different SCCs, then the corresponding edge to ignore is between the two SCCs in the condensation graph, and we can ignore it when computing the normal width of the condensation. -
If an edge
(u,v)
inedges_to_ignore
is inside the same SCC, then we remove the edge(u,v)
from (a copy of) the member edges of the SCC in the condensation. If an SCCv
has no more member edges left, we can also add the condensation edge(v, v_expanded)
to the list of edges to ignore when computing the width of the condensation.
-
Source code in flowpaths/stdigraph.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
|