Directed acyclic graphs with global source and global sink
This class is used in AbstractPathModelDAG as a wrapper (with unique global source and unique global sink) to pass the DAG to the ILP models.
Width with subpath constraints
stDAG.get_width(...) supports optional subpath-constraint arguments. When constraints are passed,
width is computed as the constrained minimum path cover size (via MinPathCover) instead of plain antichain width.
stDAG
stDAG(
base_graph: DiGraph,
additional_starts: (
list | None
) = None,
additional_ends: (
list | None
) = None,
)
Bases: AbstractSourceSinkGraph
Augmented DAG with global source/sink.
This class derives from AbstractSourceSinkGraph, which centralises the creation of a
unique global source and sink and the shared flow utility helpers. Only DAG specific
validation (acyclicity) and derived DAG-only structures (topological orders and
reachability caches) remain here.
Source code in flowpaths/stdag.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/stdag.py
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 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
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/stdag.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/stdag.py
get_width
get_width(
edges_to_ignore: list = None,
subpath_constraints: list = None,
subpath_constraints_coverage: float = 1.0,
subpath_constraints_coverage_length: float = None,
length_attr: str = None,
solver_options: dict = None,
) -> int
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.