Skip to content

Commit e4130e9

Browse files
GiggleLiuclaude
andauthored
Fix #95: Add BinPacking model (#96)
* Add plan for #95: BinPacking model Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add BinPacking model (optimization, minimize bins) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: add BinPacking unit tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: register BinPacking in CLI dispatch Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: add BinPacking problem definition to paper Also fix pub(crate) -> mod consistency in optimization/mod.rs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * update * fix run-plan * fix: clippy warnings, add BinPacking edge-case tests and variant declarations - Fix trailing blank line in bin_packing.rs - Fix clippy large_enum_variant in CLI (Box<CreateArgs>) - Fix clippy unnecessary_map_or in graph.rs - Add declare_variants! for BinPacking<i32> and BinPacking<f64> - Remove unnecessary Default bound and problem_size methods - Add edge-case tests: empty items, wrong config length, out-of-range bin, f64, variant - Update Makefile run-plan target Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix model add * fix: update BinPacking model for main refactors, enrich paper entry - Remove stale problem_size_names/values (trait methods removed on main) - Add declare_variants! with verified O*(2^n) complexity (Björklund+ 2009) - Remove unnecessary Default trait bound on impl block - Add edge-case tests: empty items, wrong config length, out-of-range bin, f64 - Expand paper problem-def with background, algorithm citation, example, figure - Regenerate problem_schemas.json and reduction_graph.json Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: address PR #96 review feedback - Add "bp" lowercase alias in resolve_alias() (Copilot review) - Replace match/panic with matches!() macro to eliminate uncovered branch (codecov) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: remove completed BinPacking plan file Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3b719e2 commit e4130e9

15 files changed

Lines changed: 539 additions & 123 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,4 @@ claude-output.log
8484
.worktrees/
8585
.worktree/
8686
*.json
87+
.claude/worktrees/

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,13 @@ PLAN_FILE ?= $(shell ls -t docs/plans/*.md 2>/dev/null | head -1)
189189
run-plan:
190190
@NL=$$'\n'; \
191191
BRANCH=$$(git branch --show-current); \
192+
PLAN_FILE="$(PLAN_FILE)"; \
192193
if [ "$(AGENT_TYPE)" = "claude" ]; then \
193-
PROCESS="1. Read the plan file$${NL}2. Use /subagent-driven-development to execute tasks$${NL}3. Push: git push origin $$BRANCH$${NL}4. Create a pull request"; \
194+
PROCESS="1. Read the plan file$${NL}2. Choose the right skill to execute: use /add-model for new problem models, /add-rule for new reduction rules, or /subagent-driven-development for other tasks$${NL}3. Push: git push origin $$BRANCH$${NL}4. Create a pull request"; \
194195
else \
195196
PROCESS="1. Read the plan file$${NL}2. Execute the tasks step by step. For each task, implement and test before moving on.$${NL}3. Push: git push origin $$BRANCH$${NL}4. Create a pull request"; \
196197
fi; \
197-
PROMPT="Execute the plan in '$${PLAN_FILE}'."; \
198+
PROMPT="Execute the plan in '$$PLAN_FILE'."; \
198199
if [ -n "$(INSTRUCTIONS)" ]; then \
199200
PROMPT="$${PROMPT}$${NL}$${NL}## Additional Instructions$${NL}$(INSTRUCTIONS)"; \
200201
fi; \

docs/paper/reductions.typ

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"BMF": [Boolean Matrix Factorization],
5050
"PaintShop": [Paint Shop],
5151
"BicliqueCover": [Biclique Cover],
52+
"BinPacking": [Bin Packing],
5253
)
5354

5455
// Definition label: "def:<ProblemName>" — each definition block must have a matching label
@@ -801,6 +802,46 @@ Biclique Cover is equivalent to factoring the biadjacency matrix $M$ of the bipa
801802
) <fig:biclique-cover>
802803
]
803804

805+
#problem-def("BinPacking")[
806+
Given $n$ items with sizes $s_1, dots, s_n in RR^+$ and bin capacity $C > 0$, find an assignment $x: {1, dots, n} -> NN$ minimizing $|{x(i) : i = 1, dots, n}|$ (the number of distinct bins used) subject to $forall j: sum_(i: x(i) = j) s_i lt.eq C$.
807+
][
808+
Bin Packing is one of the classical NP-hard optimization problems @garey1979, with applications in logistics, cutting stock, and cloud resource allocation. The best known exact algorithm runs in $O^*(2^n)$ time via inclusion-exclusion over set partitions @bjorklund2009.
809+
810+
*Example.* Consider $n = 6$ items with sizes $(6, 6, 5, 5, 4, 4)$ and capacity $C = 10$. The lower bound is $ceil(30 slash 10) = 3$ bins. An optimal packing uses exactly 3 bins: $B_1 = {6, 4}$, $B_2 = {6, 4}$, $B_3 = {5, 5}$, each with total load $10 = C$.
811+
812+
#figure({
813+
canvas(length: 1cm, {
814+
let s = 0.28
815+
let w = 1.0
816+
let gap = 0.6
817+
let bins = ((6, 4), (6, 4), (5, 5))
818+
let fills = (
819+
(graph-colors.at(0), graph-colors.at(1)),
820+
(graph-colors.at(0), graph-colors.at(1)),
821+
(graph-colors.at(2), graph-colors.at(2)),
822+
)
823+
for i in range(3) {
824+
let x = i * (w + gap)
825+
draw.rect((x, 0), (x + w, 10 * s), stroke: 0.8pt + black)
826+
let y = 0
827+
for j in range(bins.at(i).len()) {
828+
let sz = bins.at(i).at(j)
829+
let c = fills.at(i).at(j)
830+
draw.rect((x, y), (x + w, y + sz * s), stroke: 0.4pt, fill: c)
831+
draw.content((x + w / 2, y + sz * s / 2), text(8pt, fill: white)[#sz])
832+
y += sz * s
833+
}
834+
draw.content((x + w / 2, -0.3), text(8pt)[$B_#(i + 1)$])
835+
}
836+
draw.line((-0.15, 10 * s), (2 * (w + gap) + w + 0.15, 10 * s),
837+
stroke: (dash: "dashed", paint: luma(150), thickness: 0.5pt))
838+
draw.content((-0.5, 10 * s), text(7pt)[$C$])
839+
})
840+
},
841+
caption: [Optimal packing of items with sizes $(6, 6, 5, 5, 4, 4)$ into 3 bins of capacity $C = 10$. Numbers indicate item sizes; all bins are fully utilized.],
842+
) <fig:binpacking-example>
843+
]
844+
804845
// Completeness check: warn about problem types in JSON but missing from paper
805846
#{
806847
let json-models = {

docs/src/reductions/problem_schemas.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@
5151
}
5252
]
5353
},
54+
{
55+
"name": "BinPacking",
56+
"description": "Assign items to bins minimizing number of bins used, subject to capacity",
57+
"fields": [
58+
{
59+
"name": "sizes",
60+
"type_name": "Vec<W>",
61+
"description": "Item sizes s_i for each item"
62+
},
63+
{
64+
"name": "capacity",
65+
"type_name": "W",
66+
"description": "Bin capacity C"
67+
}
68+
]
69+
},
5470
{
5571
"name": "CircuitSAT",
5672
"description": "Find satisfying input to a boolean circuit",

0 commit comments

Comments
 (0)