You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Minimum Path Cover problem on a directed **acyclic** graph (*DAG*) is defined as follows:
6
+
7
+
-**INPUT**: A directed graph $G = (V,E)$.
8
+
9
+
-**OUTPUT**: A minimum number $k$ of source-to-sink paths, $P_1,\dots,P_k$ such that every edge $e \in E$ appears in at least one $P_i$.
10
+
11
+
!!! info "Note"
12
+
The graph may have more than one source or sink nodes. The solution paths are required to start in some source node, and end in some sink node.
13
+
14
+
## 2. Solving the problem
15
+
16
+
We create the graph as a [networkx DiGraph](https://networkx.org/documentation/stable/reference/classes/digraph.html). In real project, you will likely have a method that transforms your graph to a DiGraph. We also give an attribute `flow` for every edge storing its flow value.
17
+
18
+
```python
19
+
import flowpaths as fp
20
+
import networkx as nx
21
+
22
+
graph = nx.DiGraph()
23
+
graph.add_edge("s", "a")
24
+
graph.add_edge("s", "b")
25
+
graph.add_edge("a", "b")
26
+
graph.add_edge("a", "c")
27
+
graph.add_edge("b", "c")
28
+
graph.add_edge("c", "d")
29
+
graph.add_edge("c", "t")
30
+
graph.add_edge("d", "t")
31
+
32
+
mpc_model = fp.MinPathCover(graph)
33
+
mpc_model.solve()
34
+
```
35
+
36
+
The solution of `MinPathCover` is a dictionary, with an key `'paths'` containing the solution paths:
This class finds, if possible, `k` paths covering the edges of a directed acyclic graph (DAG) -- and generalizations of this problem, see the parameters below.
24
+
25
+
Parameters
26
+
----------
27
+
- `G : nx.DiGraph`
28
+
29
+
The input directed acyclic graph, as networkx DiGraph.
30
+
31
+
- `k: int`
32
+
33
+
The number of paths to decompose in.
34
+
35
+
- `subpath_constraints : list`, optional
36
+
37
+
List of subpath constraints. Default is an empty list.
38
+
Each subpath constraint is a list of edges that must be covered by some solution path, according
39
+
to the `subpath_constraints_coverage` or `subpath_constraints_coverage_length` parameters (see below).
Coverage fraction of the subpath constraints that must be covered by some solution paths.
44
+
45
+
Defaults to `1.0` (meaning that 100% of the edges of the constraint need to be covered by some solution path). See [subpath constraints documentation](subpath-constraints.md#3-relaxing-the-constraint-coverage)
Coverage length of the subpath constraints. Default is `None`. If set, this overrides `subpath_constraints_coverage`,
50
+
and the coverage constraint is expressed in terms of the subpath constraint length.
51
+
`subpath_constraints_coverage_length` is then the fraction of the total length of the constraint (specified via `edge_length_attr`) needs to appear in some solution path.
52
+
See [subpath constraints documentation](subpath-constraints.md#3-relaxing-the-constraint-coverage)
53
+
54
+
- `edge_length_attr : str`, optional
55
+
56
+
Attribute name for edge lengths. Default is `None`.
57
+
58
+
- `edges_to_ignore : list`, optional
59
+
60
+
List of edges to ignore when adding constrains on flow explanation by the weighted paths.
61
+
Default is an empty list. See [ignoring edges documentation](ignoring-edges.md)
62
+
63
+
- `optimization_options : dict`, optional
64
+
65
+
Dictionary with the optimization options. Default is `None`. See [optimization options documentation](solver-options-optimizations.md).
66
+
67
+
- `solver_options : dict`, optional
68
+
69
+
Dictionary with the solver options. Default is `None`. See [solver options documentation](solver-options-optimizations.md).
Copy file name to clipboardExpand all lines: flowpaths/minflowdecomp.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@
10
10
importcopy
11
11
importmath
12
12
13
-
classMinFlowDecomp(pathmodel.AbstractPathModelDAG): # Note that we inherit from AbstractPathModelDAG to be able to use this class to also compute safe paths,
13
+
classMinFlowDecomp(pathmodel.AbstractPathModelDAG): # Note that we inherit from AbstractPathModelDAG to be able to use this class to also compute safe paths.
14
14
"""
15
15
A class to decompose a network flow if a directed acyclic graph into a minimum number of weighted paths.
16
16
"""
@@ -138,9 +138,9 @@ def __init__(
138
138
139
139
defsolve(self) ->bool:
140
140
"""
141
-
Attempts to solve the flow distribution problem using a model with varying number of paths.
141
+
Attempts to solve the flow decomposition problem using a model with varying number of paths.
142
142
143
-
This method iterates over a range of possible path counts, creating and solving a flow decomposition model for each count.
143
+
This method iterates over a range of possible path numbers, creating and solving a flow decomposition model for each count.
144
144
If a solution is found, it stores the solution and relevant statistics, and returns True. If no solution is found after
145
145
iterating through all possible path counts, it returns False.
0 commit comments