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
## AI coding agent guide for this repo (flowpaths)
2
+
3
+
Purpose: Python package to decompose weighted digraphs into weighted paths/walks via (M)ILP. Default solver is HiGHS (highspy); Gurobi (gurobipy) is optional.
- Safety/optimizations live under `flowpaths/utils/*` and are toggled via `optimization_options` in concrete solvers.
11
+
12
+
How solutions are built (DAG models)
13
+
- Create k edge-binary vars x(u,v,i) constrained to be s–t paths; add weights/constraints per objective. Output is `{'paths'|'walks', 'weights'}`; node-origin paths are condensed back.
14
+
-`MinFlowDecomp` minimizes number of paths; uses width lower bound, minimal generating set, and subgraph scanning; may accept a greedy solution if it matches a lower bound.
-`weight_type` is int or float; choose deliberately (affects feasibility/integrality). `flow_attr_origin` is "edge" (default) or "node"; only node-mode allows `additional_starts/ends`.
21
+
-`elements_to_ignore`: edges (tuples) in edge-mode; node names (strings) in node-mode. `subpath_constraints` support coverage by fraction or length (`length_attr`).
22
+
23
+
Example (from README/tests)
24
+
```python
25
+
import flowpaths as fp, networkx as nx
26
+
G = nx.DiGraph(); G.add_edge('s','a', flow=2); G.add_edge('a','t', flow=2)
27
+
m = fp.MinFlowDecomp(G, flow_attr='flow'); m.solve(); sol = m.get_solution()
28
+
```
29
+
30
+
Developer workflows
31
+
- Setup: `pip install -e ".[dev]"`; optional `pip install gurobipy` and set `GRB_LICENSE_FILE`.
- Docs: `mkdocs serve` (sources in `docs/`, nav in `mkdocs.yml`).
35
+
36
+
Pitfalls/checks
37
+
- Path models require a DAG; flows must be non-negative and conserve at non s/t nodes. If `is_solved()` is False, check `solver.get_model_status()`; `kTimeLimit` → raise `time_limit`.
Copy file name to clipboardExpand all lines: flowpaths/kflowdecomp.py
+85-39Lines changed: 85 additions & 39 deletions
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,7 @@ def __init__(
24
24
subpath_constraints_coverage_length: float=None,
25
25
length_attr: str=None,
26
26
elements_to_ignore: list= [],
27
+
solution_weights_superset: list=None,
27
28
optimization_options: dict= {},
28
29
solver_options: dict= {},
29
30
):
@@ -87,6 +88,12 @@ def __init__(
87
88
88
89
List of edges (or nodes, if `flow_attr_origin` is `"node"`) to ignore when adding constrains on flow explanation by the weighted paths. Default is an empty list. See [ignoring edges documentation](ignoring-edges.md)
89
90
91
+
- `solution_weights_superset: list`, optional
92
+
93
+
List of allowed weights for the paths. Default is `None`.
94
+
If set, the model will use the solution path weights only from this set, with the property that **every weight in this list
95
+
appears at most once in the solution weight**. That is, if you want to have more paths with the same weight, add it more times to `solution_weights_superset`.
96
+
90
97
- `optimization_options : dict`, optional
91
98
92
99
Dictionary with the optimization options. Default is `None`. See [optimization options documentation](solver-options-optimizations.md).
@@ -164,7 +171,11 @@ def __init__(
164
171
)
165
172
)
166
173
174
+
ifk<=0ornotisinstance(k, int):
175
+
utils.logger.error(f"{__name__}: k must be a positive integer, not {k}")
176
+
raiseValueError(f"k must be a positive integer, not {k}")
Copy file name to clipboardExpand all lines: flowpaths/kleastabserrors.py
+56-34Lines changed: 56 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -108,8 +108,8 @@ def __init__(
108
108
- `solution_weights_superset: list`, optional
109
109
110
110
List of allowed weights for the paths. Default is `None`.
111
-
If set, the model will use the solution path weights only from this set, with the property that **every weight in the superset
112
-
appears at most once in the solution weight**.
111
+
If set, the model will use the solution path weights only from this set, with the property that **every weight in this list
112
+
appears at most once in the solution weight**. That is, if you want to have more paths with the same weight, add it more times to `solution_weights_superset`.
0 commit comments