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
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
decompose_using_max_bottleck
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.
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_max_flow_value_and_check_positive_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 maximum edge antichain if it has not been previously calculated and stored. If the width has already been computed, the stored value is returned.
Returns
- int: The width of the graph.