kgrid — Minimum-Perimeter Convex Polygon Containing k Lattice Points

Anonymous implementation and experimental artifact for computing the minimum Euclidean perimeter Lk and an optimal convex lattice polygon containing exactly k points of ℤ2.

Code & Scripts

Rust Crate (kgrid, 1,934 lines)

Benchmark & Figure Scripts (Ruby)

Graphs

Optimal polygons for k=3..12
Optimal polygons for k = 3,…,12 (PNG).
Single-query running time
Single-query time up to k = 1016 with k0.639 fit (PNG).
Batch DP table work per radius
Batch DP table updates per radius for k ≤ 107 (PNG).
Polygon structural scaling
Optimal polygon scaling: vertices, boundary points, longest edge, deficit (PNG).

Experimental Tables & Raw Data

Raw data files: scaling.csv · spread_7_13.csv · spread_14.csv · rowmax_compare.csv · k_1_10000.csv · polys_1_10000.tar.gz · macros.tex

Batch Runs (3 threads; k ≤ 104 single-threaded)

RangeWith polygons (time)With polygons (RSS)Perimeters only (time)Perimeters only (RSS)
1 ≤ k ≤ 1040.07 s4 MB——
1 ≤ k ≤ 1050.29 s12 MB——
1 ≤ k ≤ 1064.3 s57 MB1.2 s8 MB
1 ≤ k ≤ 10775.6 s381 MB11.6 s16 MB

Single Queries at Powers of Ten (scaling.csv, table_single.tex)

kLkVerticesBoundary ptsLongest edgeTimeMemory
104353.4226255616114.00.001 s3 MB
1051120.2430389640328.00.002 s3 MB
1063544.36556423288749.00.004 s3 MB
10711209.5977835321,96391.00.010 s3 MB
10835448.8099871,1284,313151.00.024 s4 MB
109112099.6384082,4249,599278.00.078 s6 MB
1010354490.6414365,23221,091487.00.277 s18 MB
10111120998.15444611,22446,185867.01.4 s116 MB
10123544907.64065224,248100,5481554.02.9 s70 MB
101311209982.39073552,232218,8482769.011.7 s214 MB
101435449076.989269112,608475,6574909.0119 s1.2 GB
1015112099824.308192241,9471,032,8528735.0269 s2.0 GB
1016354490770.167571522,1282,235,86615523.080 min11.8 GB

Group-Update Comparison (rowmax_compare.csv, table_rowmax.tex)

kSMAWK updatesDirect opsDirectD&CSMAWK
1081.1 · 1062.3 · 1070.021 s0.007 s0.008 s
1095.2 · 1061.2 · 1080.103 s0.031 s0.030 s
10102.3 · 1076.1 · 1080.513 s0.129 s0.127 s
10111.9 · 1085.6 · 1094.331 s1.119 s1.090 s
10124.2 · 1081.5 · 101012.068 s2.479 s2.384 s
10131.8 · 1097.3 · 101059.381 s11.272 s10.685 s

Variation Within a Decade (spread_7_13.csv, spread_14.csv, table_spread.tex)

DecadeRunsMax timeMedian timeMax RSSMax Δ*
[107, 108)50.032 s0.023 s4 MB1.25
[108, 109)50.099 s0.056 s7 MB0.69
[109, 1010)50.357 s0.123 s25 MB0.93
[1010, 1011)51.0 s0.424 s102 MB1.68
[1011, 1012)56.1 s2.0 s495 MB1.32
[1012, 1013)513.6 s5.1 s983 MB0.93
[1013, 1014)5184 s44.6 s2.3 GB1.35
[1014, 1015)4187 s172 s3.8 GB0.97

How to Build, Run, and Reproduce Results

Download and unpack kgrid_anonymous.zip (requires Rust cargo edition 2021 and Ruby standard library):

unzip kgrid_anonymous.zip && cd kgrid

# Run unit tests (grouped DP vs. 0-1 knapsack, Hirschberg recovery, SMAWK) and build
cargo test
cargo build --release

# Single query with vertex reconstruction and Pick's theorem verification
target/release/kgrid query 1000000000000 --poly-file poly_1e12.txt

# Validate batch range against the unrestricted knapsack oracle
mkdir -p out
target/release/kgrid range 1 100000 --threads 3 --out out/range_100000.csv --stats out/stats_100000.csv
target/release/kgrid oracle 100000 --out out/oracle_100000.csv
ruby scripts/compare.rb out/range_100000.csv out/oracle_100000.csv

# Reproduce scaling, within-decade spread, and update-method benchmarks
ruby scripts/scaling.rb 4 15 --mem-limit 4 | tee out/scaling.csv
ruby scripts/spread.rb 7 12 3 1 | tee out/spread_7_12.csv
ruby scripts/rowmax_compare.rb out/rowmax_compare.csv 100000000 1000000000 10000000000 100000000000