Skip to content

Commit aa5e687

Browse files
GiggleLiuisPANNclaude
authored
Fix #422: [Model] TwoDimensionalConsecutiveSets (#673)
* Add plan for #422: [Model] TwoDimensionalConsecutiveSets * Implement #422: [Model] TwoDimensionalConsecutiveSets * chore: remove plan file after implementation * fix: address PR #673 review comments * fix: resolve remaining review findings for TwoDimensionalConsecutiveSets * Fix example-db API: adapt to new ModelExampleSpec format The ModelExampleSpec struct changed on main to use instance/optimal_config/optimal_value fields instead of a build closure. Also update Typst paper to use new example-db format. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Separate validation from subset sorting in try_new Split validation_error (which validated AND sorted) into a pure validate() function and an explicit sorting step in try_new(). 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>
1 parent e70b661 commit aa5e687

10 files changed

Lines changed: 638 additions & 82 deletions

File tree

docs/paper/reductions.typ

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,11 @@
136136
"SchedulingWithIndividualDeadlines": [Scheduling With Individual Deadlines],
137137
"StaffScheduling": [Staff Scheduling],
138138
"MinimumTardinessSequencing": [Minimum Tardiness Sequencing],
139-
"SequencingToMinimizeWeightedTardiness": [Sequencing to Minimize Weighted Tardiness],
140-
"SequencingToMinimizeMaximumCumulativeCost": [Sequencing to Minimize Maximum Cumulative Cost],
141139
"ConsecutiveOnesSubmatrix": [Consecutive Ones Submatrix],
140+
"SequencingToMinimizeMaximumCumulativeCost": [Sequencing to Minimize Maximum Cumulative Cost],
141+
"SequencingToMinimizeWeightedTardiness": [Sequencing to Minimize Weighted Tardiness],
142142
"SumOfSquaresPartition": [Sum of Squares Partition],
143+
"TwoDimensionalConsecutiveSets": [2-Dimensional Consecutive Sets],
143144
"SequencingWithinIntervals": [Sequencing Within Intervals],
144145
"DirectedTwoCommodityIntegralFlow": [Directed Two-Commodity Integral Flow],
145146
"ConjunctiveBooleanQuery": [Conjunctive Boolean Query],
@@ -1906,6 +1907,52 @@ A classical NP-complete problem from Garey and Johnson @garey1979[Ch.~3, p.~76],
19061907
]
19071908
}
19081909

1910+
#{
1911+
let x = load-model-example("TwoDimensionalConsecutiveSets")
1912+
let n = x.instance.alphabet_size
1913+
let subs = x.instance.subsets
1914+
let m = subs.len()
1915+
let sol = (config: x.optimal_config, metric: x.optimal_value)
1916+
let config = sol.config
1917+
// Build groups from config: groups.at(g) = list of symbols in group g
1918+
let groups = range(n).map(g => range(n).filter(s => config.at(s) == g))
1919+
// Only non-empty groups
1920+
let nonempty = groups.enumerate().filter(((_, g)) => g.len() > 0)
1921+
let k = nonempty.len()
1922+
let fmt-set(s) = "${" + s.map(e => str(e)).join(", ") + "}$"
1923+
[
1924+
#problem-def("TwoDimensionalConsecutiveSets")[
1925+
Given finite alphabet $Sigma = {0, 1, dots, n - 1}$ and collection $cal(C) = {Sigma_1, dots, Sigma_m}$ of subsets of $Sigma$, determine whether $Sigma$ can be partitioned into disjoint sets $X_1, X_2, dots, X_k$ such that each $X_i$ has at most one element in common with each $Sigma_j$, and for each $Sigma_j in cal(C)$ there is an index $l(j)$ with $Sigma_j subset.eq X_(l(j)) union X_(l(j)+1) union dots.c union X_(l(j)+|Sigma_j|-1)$.
1926+
][
1927+
This problem generalizes the Consecutive Sets problem (SR18) by requiring not just that each subset's elements appear consecutively in an ordering, but that they be spread across consecutive groups of a partition where each group contributes at most one element per subset. Shown NP-complete by Lipski @lipski1977fct via transformation from Graph 3-Colorability. The problem arises in information storage and retrieval where records must be organized in contiguous blocks. It remains NP-complete if all subsets have at most 5 elements, but is solvable in polynomial time if all subsets have at most 2 elements. The brute-force algorithm assigns each of $n$ symbols to one of up to $n$ groups, giving $O^*(n^n)$ time#footnote[No algorithm improving on brute-force enumeration is known for this problem.].
1928+
1929+
*Example.* Let $Sigma = {0, 1, dots, #(n - 1)}$ and $cal(C) = {#range(m).map(i => $Sigma_#(i + 1)$).join(", ")}$ with #subs.enumerate().map(((i, s)) => $Sigma_#(i + 1) = #fmt-set(s)$).join(", "). A valid partition uses $k = #k$ groups: #nonempty.map(((g, elems)) => $X_#(g + 1) = #fmt-set(elems)$).join(", "). Each group intersects every subset in at most one element, and each subset's elements span exactly $|Sigma_j|$ consecutive groups. For instance, $Sigma_1 = {0, 1, 2}$ maps to groups $X_1, X_2, X_3$ (consecutive), and $Sigma_5 = {0, 5}$ maps to groups $X_1, X_2$ (consecutive). Multiple valid partitions exist for this instance, differing only by unused or shifted group labels.
1930+
1931+
#figure(
1932+
canvas(length: 1cm, {
1933+
import draw: *
1934+
// Draw groups as labeled columns
1935+
let gw = 1.4
1936+
let gh = 0.45
1937+
for (col, (g, elems)) in nonempty.enumerate() {
1938+
let x0 = col * (gw + 0.3)
1939+
// Group header
1940+
content((x0 + gw / 2, 0.5), $X_#(g + 1)$, anchor: "south")
1941+
// Draw box for the group
1942+
rect((x0, -elems.len() * gh), (x0 + gw, 0),
1943+
stroke: 0.5pt + black, fill: rgb("#e8f0fe"))
1944+
// Elements inside
1945+
for (row, elem) in elems.enumerate() {
1946+
content((x0 + gw / 2, -row * gh - gh / 2), text(size: 9pt, str(elem)))
1947+
}
1948+
}
1949+
}),
1950+
caption: [2-Dimensional Consecutive Sets: partition of $Sigma = {0, dots, 5}$ into #k groups satisfying intersection and consecutiveness constraints for all #m subsets.],
1951+
) <fig:two-dim-consecutive-sets>
1952+
]
1953+
]
1954+
}
1955+
19091956
== Optimization Problems
19101957

19111958
#{

docs/paper/references.bib

Lines changed: 86 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -944,20 +944,25 @@ @article{papadimitriou1982
944944
doi = {10.1145/322307.322309}
945945
}
946946

947-
@book{papadimitriou-steiglitz1982,
948-
author = {Christos H. Papadimitriou and Kenneth Steiglitz},
949-
title = {Combinatorial Optimization: Algorithms and Complexity},
950-
publisher = {Prentice-Hall},
951-
address = {Englewood Cliffs, NJ},
952-
year = {1982}
947+
@article{booth1976,
948+
author = {Booth, Kellogg S. and Lueker, George S.},
949+
title = {Testing for the consecutive ones property, interval graphs, and graph planarity using {PQ}-tree algorithms},
950+
journal = {Journal of Computer and System Sciences},
951+
volume = {13},
952+
number = {3},
953+
pages = {335--379},
954+
year = {1976}
953955
}
954956

955-
@techreport{Heidari2022,
956-
author = {Heidari, Shahrokh and Dinneen, Michael J. and Delmas, Patrice},
957-
title = {An Equivalent {QUBO} Model to the Minimum Multi-Way Cut Problem},
958-
institution = {Centre for Discrete Mathematics and Theoretical Computer Science, University of Auckland},
959-
year = {2022},
960-
number = {CDMTCS-565}
957+
@article{boothlueker1976,
958+
author = {Kellogg S. Booth and George S. Lueker},
959+
title = {Testing for the Consecutive Ones Property, Interval Graphs, and Graph Planarity Using {PQ}-Tree Algorithms},
960+
journal = {Journal of Computer and System Sciences},
961+
volume = {13},
962+
number = {3},
963+
pages = {335--379},
964+
year = {1976},
965+
doi = {10.1016/S0022-0000(76)80045-1}
961966
}
962967

963968
@phdthesis{booth1975,
@@ -967,25 +972,25 @@ @phdthesis{booth1975
967972
year = {1975}
968973
}
969974

970-
@article{booth1976,
971-
author = {Booth, Kellogg S. and Lueker, George S.},
972-
title = {Testing for the consecutive ones property, interval graphs, and graph planarity using {PQ}-tree algorithms},
973-
journal = {Journal of Computer and System Sciences},
974-
volume = {13},
975-
number = {3},
976-
pages = {335--379},
977-
year = {1976}
975+
@article{chopra1996,
976+
author = {Sunil Chopra and Jonathan H. Owen},
977+
title = {Extended formulations for the A-cut problem},
978+
journal = {Mathematical Programming},
979+
volume = {73},
980+
pages = {7--30},
981+
year = {1996},
982+
doi = {10.1007/BF02592096}
978983
}
979984

980-
@article{lawler1972,
981-
author = {Eugene L. Lawler},
982-
title = {A Procedure for Computing the $K$ Best Solutions to Discrete Optimization Problems and Its Application to the Shortest Path Problem},
983-
journal = {Management Science},
984-
volume = {18},
985-
number = {7},
986-
pages = {401--405},
985+
@article{coffman1972,
986+
author = {Edward G. Coffman and Ronald L. Graham},
987+
title = {Optimal Scheduling for Two-Processor Systems},
988+
journal = {Acta Informatica},
989+
volume = {1},
990+
number = {3},
991+
pages = {200--213},
987992
year = {1972},
988-
doi = {10.1287/mnsc.18.7.401}
993+
doi = {10.1007/BF00288685}
989994
}
990995

991996
@article{eppstein1992,
@@ -999,14 +1004,23 @@ @article{eppstein1992
9991004
doi = {10.1007/BF01994880}
10001005
}
10011006

1002-
@article{chopra1996,
1003-
author = {Sunil Chopra and Jonathan H. Owen},
1004-
title = {Extended formulations for the A-cut problem},
1005-
journal = {Mathematical Programming},
1006-
volume = {73},
1007-
pages = {7--30},
1008-
year = {1996},
1009-
doi = {10.1007/BF02592096}
1007+
@techreport{Heidari2022,
1008+
author = {Heidari, Shahrokh and Dinneen, Michael J. and Delmas, Patrice},
1009+
title = {An Equivalent {QUBO} Model to the Minimum Multi-Way Cut Problem},
1010+
institution = {Centre for Discrete Mathematics and Theoretical Computer Science, University of Auckland},
1011+
year = {2022},
1012+
number = {CDMTCS-565}
1013+
}
1014+
1015+
@article{hu1961,
1016+
author = {Te Chiang Hu},
1017+
title = {Parallel Sequencing and Assembly Line Problems},
1018+
journal = {Operations Research},
1019+
volume = {9},
1020+
number = {6},
1021+
pages = {841--848},
1022+
year = {1961},
1023+
doi = {10.1287/opre.9.6.841}
10101024
}
10111025

10121026
@article{kou1977,
@@ -1020,26 +1034,15 @@ @article{kou1977
10201034
doi = {10.1137/0206005}
10211035
}
10221036

1023-
@article{boothlueker1976,
1024-
author = {Kellogg S. Booth and George S. Lueker},
1025-
title = {Testing for the Consecutive Ones Property, Interval Graphs, and Graph Planarity Using {PQ}-Tree Algorithms},
1026-
journal = {Journal of Computer and System Sciences},
1027-
volume = {13},
1028-
number = {3},
1029-
pages = {335--379},
1030-
year = {1976},
1031-
doi = {10.1016/S0022-0000(76)80045-1}
1032-
}
1033-
1034-
@article{ullman1975,
1035-
author = {Jeffrey D. Ullman},
1036-
title = {NP-Complete Scheduling Problems},
1037-
journal = {Journal of Computer and System Sciences},
1038-
volume = {10},
1039-
number = {3},
1040-
pages = {384--393},
1041-
year = {1975},
1042-
doi = {10.1016/S0022-0000(75)80008-0}
1037+
@article{lawler1972,
1038+
author = {Eugene L. Lawler},
1039+
title = {A Procedure for Computing the $K$ Best Solutions to Discrete Optimization Problems and Its Application to the Shortest Path Problem},
1040+
journal = {Management Science},
1041+
volume = {18},
1042+
number = {7},
1043+
pages = {401--405},
1044+
year = {1972},
1045+
doi = {10.1287/mnsc.18.7.401}
10431046
}
10441047

10451048
@article{lenstra1978,
@@ -1053,26 +1056,24 @@ @article{lenstra1978
10531056
doi = {10.1287/opre.26.1.22}
10541057
}
10551058

1056-
@article{coffman1972,
1057-
author = {Edward G. Coffman and Ronald L. Graham},
1058-
title = {Optimal Scheduling for Two-Processor Systems},
1059-
journal = {Acta Informatica},
1060-
volume = {1},
1061-
number = {3},
1062-
pages = {200--213},
1063-
year = {1972},
1064-
doi = {10.1007/BF00288685}
1059+
@inproceedings{lipski1977fct,
1060+
author = {Witold Lipski Jr.},
1061+
title = {Two {NP}-Complete Problems Related to Information Retrieval},
1062+
booktitle = {Fundamentals of Computation Theory (FCT 1977)},
1063+
series = {Lecture Notes in Computer Science},
1064+
volume = {56},
1065+
pages = {452--458},
1066+
publisher = {Springer},
1067+
year = {1977},
1068+
doi = {10.1007/3-540-08442-8_115}
10651069
}
10661070

1067-
@article{hu1961,
1068-
author = {Te Chiang Hu},
1069-
title = {Parallel Sequencing and Assembly Line Problems},
1070-
journal = {Operations Research},
1071-
volume = {9},
1072-
number = {6},
1073-
pages = {841--848},
1074-
year = {1961},
1075-
doi = {10.1287/opre.9.6.841}
1071+
@book{papadimitriou-steiglitz1982,
1072+
author = {Christos H. Papadimitriou and Kenneth Steiglitz},
1073+
title = {Combinatorial Optimization: Algorithms and Complexity},
1074+
publisher = {Prentice-Hall},
1075+
address = {Englewood Cliffs, NJ},
1076+
year = {1982}
10761077
}
10771078

10781079
@inproceedings{papadimitriou1979,
@@ -1083,3 +1084,14 @@ @inproceedings{papadimitriou1979
10831084
year = {1979},
10841085
doi = {10.1145/800135.804393}
10851086
}
1087+
1088+
@article{ullman1975,
1089+
author = {Jeffrey D. Ullman},
1090+
title = {NP-Complete Scheduling Problems},
1091+
journal = {Journal of Computer and System Sciences},
1092+
volume = {10},
1093+
number = {3},
1094+
pages = {384--393},
1095+
year = {1975},
1096+
doi = {10.1016/S0022-0000(75)80008-0}
1097+
}

docs/src/cli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ Stdin is supported with `-`:
502502
```bash
503503
pred create MIS --graph 0-1,1-2,2-3 | pred solve -
504504
pred create MIS --graph 0-1,1-2,2-3 | pred solve - --solver brute-force
505+
pred create TwoDimensionalConsecutiveSets --alphabet-size 6 --sets "0,1,2;3,4,5;1,3;2,4;0,5" | pred solve - --solver brute-force
505506
```
506507
507508
When the problem is not ILP, the solver automatically reduces it to ILP, solves, and maps the solution back. The auto-reduction is shown in the output:

problemreductions-cli/src/cli.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ Flags by problem type:
243243
ComparativeContainment --universe, --r-sets, --s-sets [--r-weights] [--s-weights]
244244
X3C (ExactCoverBy3Sets) --universe, --sets (3 elements each)
245245
SetBasis --universe, --sets, --k
246-
PrimeAttributeName --universe, --deps, --query
247246
MinimumCardinalityKey --num-attributes, --dependencies, --k
247+
PrimeAttributeName --universe, --deps, --query
248+
TwoDimensionalConsecutiveSets --alphabet-size, --sets
248249
BicliqueCover --left, --right, --biedges, --k
249250
BalancedCompleteBipartiteSubgraph --left, --right, --biedges, --k
250251
BiconnectivityAugmentation --graph, --potential-edges, --budget [--num-vertices]
@@ -307,8 +308,9 @@ Examples:
307308
pred create UndirectedTwoCommodityIntegralFlow --graph 0-2,1-2,2-3 --capacities 1,1,2 --source-1 0 --sink-1 3 --source-2 1 --sink-2 3 --requirement-1 1 --requirement-2 1
308309
pred create X3C --universe 9 --sets \"0,1,2;0,2,4;3,4,5;3,5,7;6,7,8;1,4,6;2,5,8\"
309310
pred create SetBasis --universe 4 --sets \"0,1;1,2;0,2;0,1,2\" --k 3
311+
pred create MinimumCardinalityKey --num-attributes 6 --dependencies \"0,1>2;0,2>3;1,3>4;2,4>5\" --k 2
310312
pred create PrimeAttributeName --universe 6 --deps \"0,1>2,3,4,5;2,3>0,1,4,5\" --query 3
311-
pred create MinimumCardinalityKey --num-attributes 6 --dependencies \"0,1>2;0,2>3;1,3>4;2,4>5\" --k 2")]
313+
pred create TwoDimensionalConsecutiveSets --alphabet-size 6 --sets \"0,1,2;3,4,5;1,3;2,4;0,5\"")]
312314
pub struct CreateArgs {
313315
/// Problem type (e.g., MIS, QUBO, SAT). Omit when using --example.
314316
#[arg(value_parser = crate::problem_name::ProblemNameParser)]
@@ -547,7 +549,7 @@ pub struct CreateArgs {
547549
/// Number of available workers for StaffScheduling
548550
#[arg(long)]
549551
pub num_workers: Option<u64>,
550-
/// Alphabet size for LCS, SCS, or StringToStringCorrection (optional; inferred from the input strings if omitted)
552+
/// Alphabet size for LCS, SCS, StringToStringCorrection, or TwoDimensionalConsecutiveSets (optional; inferred from the input strings if omitted)
551553
#[arg(long)]
552554
pub alphabet_size: Option<usize>,
553555
/// Number of attributes for AdditionalKey or MinimumCardinalityKey
@@ -597,6 +599,7 @@ Examples:
597599
pred solve reduced.json -o solution.json # save result to file
598600
pred create MIS --graph 0-1,1-2 | pred solve - # read from stdin when an ILP path exists
599601
pred create StringToStringCorrection --source-string \"0,1,2,3,1,0\" --target-string \"0,1,3,2,1\" --bound 2 | pred solve - --solver brute-force
602+
pred create TwoDimensionalConsecutiveSets --alphabet-size 6 --sets \"0,1,2;3,4,5;1,3;2,4;0,5\" | pred solve - --solver brute-force
600603
pred solve problem.json --timeout 10 # abort after 10 seconds
601604
602605
Typical workflow:

problemreductions-cli/src/commands/create.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,18 @@ fn example_for(canonical: &str, graph_type: Option<&str>) -> &'static str {
445445
"--universe 4 --r-sets \"0,1,2,3;0,1\" --s-sets \"0,1,2,3;2,3\" --r-weights 2,5 --s-weights 3,6"
446446
}
447447
"SetBasis" => "--universe 4 --sets \"0,1;1,2;0,2;0,1,2\" --k 3",
448-
"PrimeAttributeName" => {
449-
"--universe 6 --deps \"0,1>2,3,4,5;2,3>0,1,4,5\" --query 3"
450-
}
451448
"LongestCommonSubsequence" => {
452449
"--strings \"010110;100101;001011\" --bound 3 --alphabet-size 2"
453450
}
454451
"MinimumCardinalityKey" => {
455452
"--num-attributes 6 --dependencies \"0,1>2;0,2>3;1,3>4;2,4>5\" --k 2"
456453
}
454+
"PrimeAttributeName" => {
455+
"--universe 6 --deps \"0,1>2,3,4,5;2,3>0,1,4,5\" --query 3"
456+
}
457+
"TwoDimensionalConsecutiveSets" => {
458+
"--alphabet-size 6 --sets \"0,1,2;3,4,5;1,3;2,4;0,5\""
459+
}
457460
"ShortestCommonSupersequence" => "--strings \"0,1,2;1,2,0\" --bound 4",
458461
"SequencingToMinimizeMaximumCumulativeCost" => {
459462
"--costs 2,-1,3,-2,1,-3 --precedence-pairs \"0>2,1>2,1>3,2>4,3>5,4>5\" --bound 4"
@@ -1794,6 +1797,27 @@ pub fn create(args: &CreateArgs, out: &OutputConfig) -> Result<()> {
17941797
)
17951798
}
17961799

1800+
// TwoDimensionalConsecutiveSets
1801+
"TwoDimensionalConsecutiveSets" => {
1802+
let alphabet_size = args.alphabet_size.or(args.universe).ok_or_else(|| {
1803+
anyhow::anyhow!(
1804+
"TwoDimensionalConsecutiveSets requires --alphabet-size (or --universe) and --sets\n\n\
1805+
Usage: pred create TwoDimensionalConsecutiveSets --alphabet-size 6 --sets \"0,1,2;3,4,5;1,3;2,4;0,5\""
1806+
)
1807+
})?;
1808+
let sets = parse_sets(args)?;
1809+
(
1810+
ser(
1811+
problemreductions::models::set::TwoDimensionalConsecutiveSets::try_new(
1812+
alphabet_size,
1813+
sets,
1814+
)
1815+
.map_err(anyhow::Error::msg)?,
1816+
)?,
1817+
resolved_variant.clone(),
1818+
)
1819+
}
1820+
17971821
// BicliqueCover
17981822
"BicliqueCover" => {
17991823
let usage = "pred create BicliqueCover --left 2 --right 2 --biedges 0-0,0-1,1-1 --k 2";

0 commit comments

Comments
 (0)