stDiGraph
stDiGraph
Bases: DiGraph
Source code in flowpaths/stdigraph.py
__build_graph__
Builds the graph by adding nodes and edges from the base graph, and connecting source and sink nodes.
This method performs the following steps: 1. Checks if the base graph is a directed acyclic graph (DAG). If not, raises a ValueError. 2. Adds all nodes and edges from the base graph to the current graph. 3. Connects nodes with no incoming edges or specified as additional start nodes to the source node. 4. Connects nodes with no outgoing edges or specified as additional end nodes to the sink node. 5. Stores the edges connected to the source and sink nodes. 6. Initializes the width attribute to None.
Raises
- ValueError: If the base graph is not a directed acyclic graph (DAG).
Source code in flowpaths/stdigraph.py
compute_max_edge_antichain
Computes the maximum edge antichain in a directed graph.
Parameters
- get_antichain (bool): If True, the function also returns the antichain along with its cost. Default is False.
- weight_function (dict): A dictionary where keys are edges (tuples) and values are weights. If None, weights 1 are used for original graph edges, and weights 0 are used for global source / global sink edges. If given, the antichain weight is computed as the sum of the weights of the edges in the antichain, where edges that have some missing weight again get weight 0. Default is None.
Returns
- If get_antichain is False, returns the size of maximum edge antichain.
- If get_antichain is True, returns a tuple containing the size of maximum edge antichain and the antichain.
Source code in flowpaths/stdigraph.py
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 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
decompose_using_max_bottleneck
Decomposes the flow greedily into paths using the maximum bottleneck algorithm. This method iteratively finds the path with the maximum bottleneck capacity in the graph and decomposes the flow along that path. The process continues until no more paths can be found.
Note
The decomposition path do not contain the global source nor sink.
Returns
- tuple: A tuple containing two lists:
- paths (list of lists): A list of paths, where each path is represented as a list of nodes.
- weights (list): A list of weights (bottleneck capacities) corresponding to each path.
Source code in flowpaths/stdigraph.py
get_flow_width
Calculate, store, and return the flow-width of the graph.
The flow width is computed as the minimum number to cover all the edges, with the constraint
that an edge cannot be covered more time than the flow value given as flow_attr
in the edge data.
If the flow-width has already been computed, the stored value is returned.
Returns
- int: The flow-width of the graph.
Source code in flowpaths/stdigraph.py
get_max_flow_value_and_check_non_negative_flow
Determines the maximum flow value in the graph and checks for positive flow values.
This method iterates over all edges in the graph, ignoring edges specified in
self.edges_to_ignore
. It checks if each edge has the required flow attribute
specified by self.flow_attr
. If an edge does not have this attribute, a
ValueError is raised. If an edge has a negative flow value, a ValueError is
raised. The method returns the maximum flow value found among all edges.
Returns
- float: The maximum flow value among all edges in the graph.
Raises
- ValueError: If an edge does not have the required flow attribute.
- ValueError: If an edge has a negative flow value.
Source code in flowpaths/stdigraph.py
get_non_zero_flow_edges
Get all edges with non-zero flow values.
Returns
set A set of edges (tuples) that have non-zero flow values.
Source code in flowpaths/stdigraph.py
get_width
Calculate and return the width of the graph.
The width is computed as the minimum number of paths needed to cover all the edges of the graph,
except those in the edges_to_ignore
list.
If the width has already been computed and edges_to_ignore
is empty,
the stored value is returned.
Returns
- int: The width of the graph.