Skip to content

Fix #95: Add BinPacking model#96

Merged
GiggleLiu merged 13 commits intomainfrom
issue-95-bin-packing
Feb 28, 2026
Merged

Fix #95: Add BinPacking model#96
GiggleLiu merged 13 commits intomainfrom
issue-95-bin-packing

Conversation

@GiggleLiu
Copy link
Contributor

Summary

  • Add BinPacking<W> optimization model to src/models/optimization/
  • Minimizes number of bins used for items with sizes subject to capacity constraints
  • Config space: each of n items assigned to one of n possible bins
  • Parameterized by weight type W (i32, f64) for item sizes

Closes #95

Plan

See docs/plans/2026-02-25-bin-packing.md for the full implementation plan covering:

  1. Model implementation (BinPacking<W> struct + Problem/OptimizationProblem traits)
  2. Unit tests (creation, evaluation, brute-force solver, serialization)
  3. CLI dispatch registration
  4. Paper documentation (#problem-def)

Test plan

  • Unit tests for creation, evaluation (valid/invalid), direction, serialization
  • Brute-force solver finds optimal solution on example instance (6 items, capacity 10)
  • CLI can load/solve/serialize BinPacking instances
  • make check passes (fmt + clippy + test)
  • Paper builds with new problem definition

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.90%. Comparing base (3b719e2) to head (eb6f8f5).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #96      +/-   ##
==========================================
+ Coverage   96.88%   96.90%   +0.01%     
==========================================
  Files         196      198       +2     
  Lines       26747    26908     +161     
==========================================
+ Hits        25913    26074     +161     
  Misses        834      834              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

GiggleLiu and others added 9 commits February 25, 2026 10:35
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Also fix pub(crate) -> mod consistency in optimization/mod.rs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…arations

- 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>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new optimization problem model, BinPacking, to the core library and wires it through schema/CLI/documentation so instances can be loaded/solved/serialized, alongside a small robustness fix in the UnitDiskMapping path decomposition greedy method.

Changes:

  • Add BinPacking<W> model (schema registration, evaluation, variants, exports) and unit tests.
  • Register BinPacking in the CLI dispatch and add naming/alias support.
  • Add BinPacking problem definition to the paper; clamp greedy path decomposition restarts to avoid empty layouts.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/models/optimization/bin_packing.rs New BinPacking optimization model implementation + schema/variants + tests module hook
src/models/optimization/mod.rs Register and re-export BinPacking from optimization module
src/models/mod.rs Re-export BinPacking from top-level models module
src/unit_tests/models/optimization/bin_packing.rs Unit tests for creation/evaluation/bruteforce/serialization + f64 coverage
problemreductions-cli/src/dispatch.rs CLI JSON load/serialize dispatch for BinPacking<i32> and BinPacking<f64>
problemreductions-cli/src/problem_name.rs Add BinPacking name mapping and advertise short alias BP
docs/paper/reductions.typ Add display name + #problem-def("BinPacking")
src/rules/unitdiskmapping/pathdecomposition.rs Clamp nrepeat to at least 1 in greedy pathwidth mode
src/unit_tests/rules/unitdiskmapping/pathdecomposition.rs Tests covering zero-restart clamping and non-empty layouts
problemreductions-cli/src/commands/graph.rs Simplify default-variant diff filtering logic
problemreductions-cli/src/cli.rs Box CreateArgs in Commands enum
docs/plans/2026-02-25-bin-packing.md Add implementation plan document for BinPacking
Makefile Update run-plan prompt/process handling
.gitignore Ignore .claude/worktrees/

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"paintshop" => "PaintShop".to_string(),
"bmf" => "BMF".to_string(),
"bicliquecover" => "BicliqueCover".to_string(),
"binpacking" => "BinPacking".to_string(),
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ALIASES lists "BP" for BinPacking, but resolve_alias() does not handle the lowercase input "bp" (it only matches "binpacking"). As a result, pred ... BP will not resolve to BinPacking even though it’s advertised as an alias. Add a "bp" => "BinPacking" match arm (or reuse ALIASES for resolution).

Suggested change
"binpacking" => "BinPacking".to_string(),
"bp" | "binpacking" => "BinPacking".to_string(),

Copilot uses AI. Check for mistakes.
Comment on lines 189 to +198
run-plan:
@NL=$$'\n'; \
BRANCH=$$(git branch --show-current); \
PLAN_FILE="$(PLAN_FILE)"; \
if [ "$(AGENT_TYPE)" = "claude" ]; then \
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"; \
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"; \
else \
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"; \
fi; \
PROMPT="Execute the plan in '$${PLAN_FILE}'."; \
PROMPT="Execute the plan in '$$PLAN_FILE'."; \
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is described as adding the BinPacking model, but it also changes the run-plan Makefile workflow/prompt logic. If these Makefile changes are intentional, please mention them in the PR description; otherwise consider splitting them into a separate PR to keep scope focused and make review/audit easier.

Copilot uses AI. Check for mistakes.
Comment on lines +154 to +155
BinPacking<i32> => "2^num_items",
BinPacking<f64> => "2^num_items",
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare_variants! complexity metadata is incorrect for BinPacking: the configuration space is n^n (each of n items chooses among n bins), but this is currently declared as 2^num_items. This will misreport complexity in the reduction graph/paper outputs; update the string to reflect num_items^num_items (or equivalent).

Suggested change
BinPacking<i32> => "2^num_items",
BinPacking<f64> => "2^num_items",
BinPacking<i32> => "num_items^num_items",
BinPacking<f64> => "num_items^num_items",

Copilot uses AI. Check for mistakes.
GiggleLiu and others added 3 commits February 28, 2026 23:07
- 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>
- 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>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@GiggleLiu GiggleLiu merged commit e4130e9 into main Feb 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Model] BinPacking

2 participants