See also
Minimum-Paths Minimum Discordant Nodes
This model optimizes the number of paths for the k-Minimum Discordant Nodes objective in DAGs. It wraps NumPathsOptimization with:
model_type = kMinDiscordantNodesstop_on_delta_abs = 0
Thus, the routine iterates over increasing values of \(k\) and stops when the objective value no longer improves in absolute value (plateau criterion).
1. Definition
Given a DAG with node flow values, this model returns a decomposition minimizing the number of discordant nodes while selecting \(k\) automatically.
The search starts at
$$
k_0 = \max\left(\text{min_num_paths},\ \text{lowerbound}(k)\right)
$$
and increases \(k\) until one of the stopping conditions in NumPathsOptimization is met.
2. Solving the problem
import flowpaths as fp
import networkx as nx
G = nx.DiGraph()
G.add_node("s", flow=5)
G.add_node("a", flow=10)
G.add_node("t", flow=5)
G.add_edge("s", "a")
G.add_edge("a", "t")
model = fp.MinPathsMinDiscordantNodes(
G=G,
flow_attr="flow",
discordance_tolerance=0.1,
min_num_paths=1,
max_num_paths=10,
)
model.solve()
if model.is_solved():
sol = model.get_solution(remove_empty_paths=True)
print(model.model.k) # selected k
print(sol["paths"])
print(sol["weights"])
print(sol["discordant_nodes"])
Example search flow:
flowchart LR
start([Start at k0]) --> solvek[Solve k-MinDiscordantNodes at k]
solvek --> feasible{Solved?}
feasible -- no --> nextk[Increase k]
feasible -- yes --> plateau{Objective plateau?}
plateau -- no --> nextk
plateau -- yes --> stop([Return previous feasible model])
nextk --> solvek
3. References
-
Jin Zhao, Haodi Feng, Daming Zhu, Yu Lin, MultiTrans: An Algorithm for Path Extraction Through Mixed Integer Linear Programming for Transcriptome Assembly, IEEE/ACM Transactions on Computational Biology and Bioinformatics 19(1), 48-56, 2022.
-
See also flowpaths References.
MinPathsMinDiscordantNodes
MinPathsMinDiscordantNodes(
G: DiGraph,
flow_attr: str,
weight_type: type = float,
discordance_tolerance: float = 0.1,
subsequence_constraints: list = None,
additional_starts: list = None,
additional_ends: list = None,
optimization_options: dict = None,
solver_options: dict = None,
round_flow_values_to_int: bool = True,
flow_values_divisor: float = 1,
min_num_paths: int = None,
max_num_paths: int = 2
** 64,
time_limit: float = float(
"inf"
),
)
Bases: NumPathsOptimization
Minimize the number of paths for k-MinDiscordantNodes on DAG-like inputs.
The class wraps :class:NumPathsOptimization with:
- model_type fixed to kMinDiscordantNodes
- stop_on_delta_abs fixed to 0
This means the search over k stops at the first plateau, i.e. when the
objective no longer improves in absolute value.
Multi-component behavior
If G has multiple weakly connected components, this class solves one
component-local instance per component and merges the solutions.
Constraints and optional start/end nodes are filtered per component.
A single global time_limit is enforced across all component solves.
Build a MinPathsMinDiscordantNodes optimizer.
Parameters
G : nx.DiGraph
Input graph.
flow_attr : str
Node/edge attribute name used by the wrapped discordance model.
weight_type : type, default=float
Type for path weights (typically int or float).
discordance_tolerance : float, default=0.1
Relative tolerance used when deciding if a node is discordant.
subsequence_constraints : list, optional
List of node sequences that must be covered. In multi-component
mode, each sequence must lie entirely inside one component.
additional_starts : list, optional
Optional allowed start nodes. Filtered per component in
multi-component mode.
additional_ends : list, optional
Optional allowed end nodes. Filtered per component in
multi-component mode.
optimization_options : dict, optional
Options forwarded to underlying models.
solver_options : dict, optional
Solver backend options (HiGHS/Gurobi wrapper options).
flow_values_divisor : float, default=1
Divides node/edge flow values before solving. Division happens
before optional rounding.
min_num_paths : int, optional
Lower bound for k. If None, a lower bound is computed via
MinPathCover on a node-expanded graph (per component when
componentized).
max_num_paths : int, default=2**64
Upper bound for k.
time_limit : float, default=inf
Global time limit in seconds. For multi-component graphs, each
component receives the remaining budget.
Source code in flowpaths/minpathsmindiscordantnodes.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 203 204 | |
get_lowerbound_k
Return lower bound used for the k search.
Source code in flowpaths/minpathsmindiscordantnodes.py
get_objective_value
Return discordant-node count for the postprocessed solution.
Source code in flowpaths/minpathsmindiscordantnodes.py
get_solution
Return merged solution, optionally removing empty paths.
Source code in flowpaths/minpathsmindiscordantnodes.py
is_valid_solution
Validate transformed solution against original graph flow values.
Source code in flowpaths/minpathsmindiscordantnodes.py
solve
Solve the model.
For a single-component graph, delegates to NumPathsOptimization.
For multiple weakly connected components, solves components one by one,
consuming a shared global time budget and summing objective values.
Source code in flowpaths/minpathsmindiscordantnodes.py
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | |