Skip to content

Commit 84e189b

Browse files
GiggleLiuisPANNclaude
authored
Fix #411: [Model] CapacityAssignment (#747)
* Add plan for #411: [Model] CapacityAssignment * Implement #411: [Model] CapacityAssignment * chore: remove plan file after implementation * fix: rustfmt after merge with main * fix: update --capacities help text to cover CapacityAssignment Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Xiwei Pan <xiwei.pan@connect.hkust-gz.edu.cn> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Xiwei Pan <90967972+isPANN@users.noreply.github.com>
1 parent 94063e7 commit 84e189b

9 files changed

Lines changed: 608 additions & 25 deletions

File tree

docs/paper/reductions.typ

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
"BoundedComponentSpanningForest": [Bounded Component Spanning Forest],
118118
"BinPacking": [Bin Packing],
119119
"BoyceCoddNormalFormViolation": [Boyce-Codd Normal Form Violation],
120+
"CapacityAssignment": [Capacity Assignment],
120121
"ConsistencyOfDatabaseFrequencyTables": [Consistency of Database Frequency Tables],
121122
"ClosestVectorProblem": [Closest Vector Problem],
122123
"ConsecutiveSets": [Consecutive Sets],
@@ -5052,6 +5053,39 @@ A classical NP-complete problem from Garey and Johnson @garey1979[Ch.~3, p.~76],
50525053
]
50535054
}
50545055

5056+
#{
5057+
let x = load-model-example("CapacityAssignment")
5058+
[
5059+
#problem-def("CapacityAssignment")[
5060+
Given a finite set $C$ of communication links, an ordered set $M subset ZZ_(> 0)$ of capacities, cost and delay functions $g: C times M -> ZZ_(>= 0)$ and $d: C times M -> ZZ_(>= 0)$ such that for every $c in C$ and $i < j$ in the order of $M$ we have $g(c, i) <= g(c, j)$ and $d(c, i) >= d(c, j)$, and budgets $K, J in ZZ_(>= 0)$, determine whether there exists an assignment $sigma: C -> M$ such that $sum_(c in C) g(c, sigma(c)) <= K$ and $sum_(c in C) d(c, sigma(c)) <= J$.
5061+
][
5062+
Capacity Assignment is the bicriteria communication-network design problem SR7 in Garey & Johnson @garey1979. The original NP-completeness proof, via reduction from Subset Sum, is due to Van Sickle and Chandy @vansicklechandy1977. The model captures discrete provisioning of communication links, where upgrading a link increases installation cost but decreases delay. The direct witness encoding implemented in this repository yields an $O^*(|M|^(|C|))$ exact algorithm by brute-force enumeration#footnote[No algorithm improving on brute-force enumeration is known for the exact witness encoding used in this repository.]. Garey and Johnson also note a pseudo-polynomial dynamic-programming formulation when the budgets are small @garey1979.
5063+
5064+
*Example.* Let $C = {c_1, c_2, c_3}$, $M = {1, 2, 3}$, $K = 10$, and $J = 12$. With cost rows $(1, 3, 6)$, $(2, 4, 7)$, $(1, 2, 5)$ and delay rows $(8, 4, 1)$, $(7, 3, 1)$, $(6, 3, 1)$, the assignment $sigma = (2, 2, 2)$ has total cost $3 + 4 + 2 = 9 <= 10$ and total delay $4 + 3 + 3 = 10 <= 12$, so the instance is satisfiable. Brute-force enumeration finds exactly 5 satisfying assignments; for contrast, $sigma = (1, 1, 1)$ violates the delay budget and $sigma = (3, 3, 3)$ violates the cost budget.
5065+
5066+
#pred-commands(
5067+
"pred create --example " + problem-spec(x) + " -o capacity-assignment.json",
5068+
"pred solve capacity-assignment.json --solver brute-force",
5069+
"pred evaluate capacity-assignment.json --config " + x.optimal_config.map(str).join(","),
5070+
)
5071+
5072+
#figure({
5073+
table(
5074+
columns: (auto, auto, auto),
5075+
inset: 4pt,
5076+
align: left,
5077+
table.header([*Link*], [*Cost row*], [*Delay row*]),
5078+
[$c_1$], [$(1, 3, 6)$], [$(8, 4, 1)$],
5079+
[$c_2$], [$(2, 4, 7)$], [$(7, 3, 1)$],
5080+
[$c_3$], [$(1, 2, 5)$], [$(6, 3, 1)$],
5081+
)
5082+
},
5083+
caption: [Canonical Capacity Assignment instance with budgets $K = 10$ and $J = 12$. Each row lists the cost-delay trade-off for one communication link.],
5084+
) <fig:capacity-assignment>
5085+
]
5086+
]
5087+
}
5088+
50555089
#{
50565090
let x = load-model-example("PrecedenceConstrainedScheduling")
50575091
let n = x.instance.num_tasks

docs/paper/references.bib

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ @article{robertsonSeymour1995
213213
doi = {10.1006/jctb.1995.1006}
214214
}
215215

216+
@inproceedings{vansicklechandy1977,
217+
author = {Lawrence Van Sickle and K. Mani Chandy},
218+
title = {Computational Complexity of Network Design Algorithms},
219+
booktitle = {IFIP Congress 77},
220+
pages = {235--239},
221+
year = {1977}
222+
}
223+
216224
@article{bruckerGareyJohnson1977,
217225
author = {Peter Brucker and Michael R. Garey and David S. Johnson},
218226
title = {Scheduling equal-length tasks under tree-like precedence constraints to minimize maximum lateness},

problemreductions-cli/src/cli.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ Flags by problem type:
246246
PathConstrainedNetworkFlow --arcs, --capacities, --source, --sink, --paths, --requirement
247247
Factoring --target, --m, --n
248248
BinPacking --sizes, --capacity
249+
CapacityAssignment --capacities, --cost-matrix, --delay-matrix, --cost-budget, --delay-budget
249250
SubsetSum --sizes, --target
250251
SumOfSquaresPartition --sizes, --num-groups, --bound
251252
PaintShop --sequence
@@ -321,6 +322,7 @@ Examples:
321322
pred create MIS --graph 0-1,1-2,2-3 --weights 1,1,1
322323
pred create SAT --num-vars 3 --clauses \"1,2;-1,3\"
323324
pred create QUBO --matrix \"1,0.5;0.5,2\"
325+
pred create CapacityAssignment --capacities 1,2,3 --cost-matrix \"1,3,6;2,4,7;1,2,5\" --delay-matrix \"8,4,1;7,3,1;6,3,1\" --cost-budget 10 --delay-budget 12
324326
pred create GeneralizedHex --graph 0-1,0-2,0-3,1-4,2-4,3-4,4-5 --source 0 --sink 5
325327
pred create IntegralFlowWithMultipliers --arcs \"0>1,0>2,1>3,2>3\" --capacities 1,1,2,2 --source 0 --sink 3 --multipliers 1,2,3,1 --requirement 2
326328
pred create MultipleChoiceBranching/i32 --arcs \"0>1,0>2,1>3,2>3,1>4,3>5,4>5,2>4\" --weights 3,2,4,1,2,3,1,3 --partition \"0,1;2,3;4,7;5,6\" --bound 10
@@ -366,15 +368,21 @@ pub struct CreateArgs {
366368
/// Edge lengths (e.g., 2,3,1) [default: all 1s]
367369
#[arg(long)]
368370
pub edge_lengths: Option<String>,
369-
/// Edge capacities for multicommodity flow problems (e.g., 1,1,2)
371+
/// Capacities (edge capacities for flow problems, capacity levels for CapacityAssignment)
370372
#[arg(long)]
371373
pub capacities: Option<String>,
372-
/// Edge lower bounds for lower-bounded flow problems (e.g., 1,1,0,0,1,0,1)
373-
#[arg(long)]
374-
pub lower_bounds: Option<String>,
375374
/// Bundle capacities for IntegralFlowBundles (e.g., 1,1,1)
376375
#[arg(long)]
377376
pub bundle_capacities: Option<String>,
377+
/// Cost matrix for CapacityAssignment (semicolon-separated rows, e.g., "1,3,6;2,4,7")
378+
#[arg(long)]
379+
pub cost_matrix: Option<String>,
380+
/// Delay matrix for CapacityAssignment (semicolon-separated rows, e.g., "8,4,1;7,3,1")
381+
#[arg(long)]
382+
pub delay_matrix: Option<String>,
383+
/// Edge lower bounds for lower-bounded flow problems (e.g., 1,1,0,0,1,0,1)
384+
#[arg(long)]
385+
pub lower_bounds: Option<String>,
378386
/// Vertex multipliers in vertex order (e.g., 1,2,3,1)
379387
#[arg(long)]
380388
pub multipliers: Option<String>,
@@ -547,6 +555,12 @@ pub struct CreateArgs {
547555
/// Upper bound on total inter-partition arc cost
548556
#[arg(long)]
549557
pub cost_bound: Option<i32>,
558+
/// Budget on total cost for CapacityAssignment
559+
#[arg(long)]
560+
pub cost_budget: Option<u64>,
561+
/// Budget on total delay penalty for CapacityAssignment
562+
#[arg(long)]
563+
pub delay_budget: Option<u64>,
550564
/// Pattern graph edge list for SubgraphIsomorphism (e.g., 0-1,1-2,2-0)
551565
#[arg(long)]
552566
pub pattern: Option<String>,

0 commit comments

Comments
 (0)