Skip to content

Commit 47ea067

Browse files
GiggleLiuclaudezazabap
authored
Fix #295: Add DirectedTwoCommodityIntegralFlow model (#660)
* Add plan for #295: DirectedTwoCommodityIntegralFlow Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Implement #295: Add DirectedTwoCommodityIntegralFlow model Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: remove plan file after implementation * fix: address PR #660 review follow-ups * fix: improve D2CIF CLI guidance * fix: remove duplicate CLI fields from merge (capacities, source/sink, requirements) Both DirectedTwoCommodityIntegralFlow and UndirectedTwoCommodityIntegralFlow share the same CLI fields. The merge with main created duplicates. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: zazabap <sweynan@icloud.com>
1 parent a4c3516 commit 47ea067

15 files changed

Lines changed: 926 additions & 123 deletions

File tree

docs/paper/reductions.typ

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"PartitionIntoTriangles": [Partition Into Triangles],
109109
"FlowShopScheduling": [Flow Shop Scheduling],
110110
"MinimumTardinessSequencing": [Minimum Tardiness Sequencing],
111+
"DirectedTwoCommodityIntegralFlow": [Directed Two-Commodity Integral Flow],
111112
)
112113

113114
// Definition label: "def:<ProblemName>" — each definition block must have a matching label
@@ -2091,6 +2092,53 @@ NP-completeness was established by Garey, Johnson, and Stockmeyer @gareyJohnsonS
20912092
]
20922093
}
20932094

2095+
#problem-def("DirectedTwoCommodityIntegralFlow")[
2096+
Given a directed graph $G = (V, A)$ with arc capacities $c: A -> ZZ^+$, two source-sink pairs $(s_1, t_1)$ and $(s_2, t_2)$, and requirements $R_1, R_2 in ZZ^+$, determine whether there exist two integral flow functions $f_1, f_2: A -> ZZ_(>= 0)$ such that (1) $f_1(a) + f_2(a) <= c(a)$ for all $a in A$, (2) flow $f_i$ is conserved at every vertex except $s_1, s_2, t_1, t_2$, and (3) the net flow into $t_i$ under $f_i$ is at least $R_i$ for $i in {1, 2}$.
2097+
][
2098+
Directed Two-Commodity Integral Flow is a fundamental NP-complete problem in multicommodity flow theory, catalogued as ND38 in Garey & Johnson @garey1979. While single-commodity max-flow is solvable in polynomial time and fractional multicommodity flow reduces to linear programming, requiring integral flows with just two commodities makes the problem NP-complete.
2099+
2100+
NP-completeness was proved by Even, Itai, and Shamir via reduction from 3-SAT @even1976. The problem remains NP-complete even when all arc capacities are 1 and $R_1 = 1$. No sub-exponential exact algorithm is known; brute-force enumeration over $(C + 1)^(2|A|)$ flow assignments dominates, where $C = max_(a in A) c(a)$.#footnote[No algorithm improving on brute-force is known for Directed Two-Commodity Integral Flow.]
2101+
2102+
*Example.* Consider a directed graph with 6 vertices and 8 arcs (all with unit capacity), sources $s_1 = 0$, $s_2 = 1$, sinks $t_1 = 4$, $t_2 = 5$, and requirements $R_1 = R_2 = 1$. Commodity 1 routes along the path $0 -> 2 -> 4$ and commodity 2 along $1 -> 3 -> 5$, satisfying all capacity and conservation constraints.
2103+
2104+
#figure(
2105+
canvas(length: 1cm, {
2106+
import draw: *
2107+
let positions = (
2108+
(0, 1), // 0 = s1
2109+
(0, -1), // 1 = s2
2110+
(2, 1), // 2
2111+
(2, -1), // 3
2112+
(4, 1), // 4 = t1
2113+
(4, -1), // 5 = t2
2114+
)
2115+
let labels = ($s_1$, $s_2$, $2$, $3$, $t_1$, $t_2$)
2116+
let arcs = ((0, 2), (0, 3), (1, 2), (1, 3), (2, 4), (2, 5), (3, 4), (3, 5))
2117+
// Commodity 1 path: arcs 0 (0->2) and 4 (2->4)
2118+
let c1-arcs = (0, 4)
2119+
// Commodity 2 path: arcs 3 (1->3) and 7 (3->5)
2120+
let c2-arcs = (3, 7)
2121+
2122+
// Draw arcs
2123+
for (idx, (u, v)) in arcs.enumerate() {
2124+
let from = positions.at(u)
2125+
let to = positions.at(v)
2126+
let color = if c1-arcs.contains(idx) { blue } else if c2-arcs.contains(idx) { red } else { gray.darken(20%) }
2127+
let thickness = if c1-arcs.contains(idx) or c2-arcs.contains(idx) { 1.2pt } else { 0.6pt }
2128+
line(from, to, stroke: (paint: color, thickness: thickness), mark: (end: "straight", scale: 0.5))
2129+
}
2130+
2131+
// Draw vertices
2132+
for (k, pos) in positions.enumerate() {
2133+
let fill = if k == 0 or k == 4 { blue.lighten(70%) } else if k == 1 or k == 5 { red.lighten(70%) } else { white }
2134+
circle(pos, radius: 0.3, fill: fill, stroke: 0.6pt, name: str(k))
2135+
content(pos, text(8pt, labels.at(k)))
2136+
}
2137+
}),
2138+
caption: [Two-commodity flow: commodity 1 (blue, $s_1 -> 2 -> t_1$) and commodity 2 (red, $s_2 -> 3 -> t_2$).],
2139+
) <fig:d2cif>
2140+
]
2141+
20942142
// Completeness check: warn about problem types in JSON but missing from paper
20952143
#{
20962144
let json-models = {

docs/paper/references.bib

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,17 @@ @inproceedings{cordella2004
682682
doi = {10.1109/TPAMI.2004.75}
683683
}
684684

685+
@article{even1976,
686+
author = {Shimon Even and Alon Itai and Adi Shamir},
687+
title = {On the Complexity of Timetable and Multicommodity Flow Problems},
688+
journal = {SIAM Journal on Computing},
689+
volume = {5},
690+
number = {4},
691+
pages = {691--703},
692+
year = {1976},
693+
doi = {10.1137/0205048}
694+
}
695+
685696
@article{papadimitriou1982,
686697
author = {Christos H. Papadimitriou and Mihalis Yannakakis},
687698
title = {The Complexity of Restricted Spanning Tree Problems},

docs/src/reductions/problem_schemas.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,52 @@
8989
}
9090
]
9191
},
92+
{
93+
"name": "DirectedTwoCommodityIntegralFlow",
94+
"description": "Two-commodity integral flow feasibility on a directed graph",
95+
"fields": [
96+
{
97+
"name": "graph",
98+
"type_name": "DirectedGraph",
99+
"description": "Directed graph G = (V, A)"
100+
},
101+
{
102+
"name": "capacities",
103+
"type_name": "Vec<u64>",
104+
"description": "Capacity c(a) for each arc"
105+
},
106+
{
107+
"name": "source_1",
108+
"type_name": "usize",
109+
"description": "Source vertex s_1 for commodity 1"
110+
},
111+
{
112+
"name": "sink_1",
113+
"type_name": "usize",
114+
"description": "Sink vertex t_1 for commodity 1"
115+
},
116+
{
117+
"name": "source_2",
118+
"type_name": "usize",
119+
"description": "Source vertex s_2 for commodity 2"
120+
},
121+
{
122+
"name": "sink_2",
123+
"type_name": "usize",
124+
"description": "Sink vertex t_2 for commodity 2"
125+
},
126+
{
127+
"name": "requirement_1",
128+
"type_name": "u64",
129+
"description": "Flow requirement R_1 for commodity 1"
130+
},
131+
{
132+
"name": "requirement_2",
133+
"type_name": "u64",
134+
"description": "Flow requirement R_2 for commodity 2"
135+
}
136+
]
137+
},
92138
{
93139
"name": "ExactCoverBy3Sets",
94140
"description": "Determine if a collection of 3-element subsets contains an exact cover",

0 commit comments

Comments
 (0)