Skip to content

Subtractive BnB V2 — flat arrays, fast-path depth-0/1, branch ordering#12

Open
AzaelMew wants to merge 2 commits into
Wynncraft:mainfrom
AzaelMew:subtractive-bnb-v2
Open

Subtractive BnB V2 — flat arrays, fast-path depth-0/1, branch ordering#12
AzaelMew wants to merge 2 commits into
Wynncraft:mainfrom
AzaelMew:subtractive-bnb-v2

Conversation

@AzaelMew
Copy link
Copy Markdown
Contributor

Summary

Subtractive BnB V2 is an evolution of the V1 algorithm with aggressive performance optimisations while keeping the exact same correctness guarantees.

What changed

  • Flat primitive arrays — converted jagged int[][] req / bonus to contiguous int[] for better cache locality in the hot loops.
  • Fast-path depth-0 & depth-1 search — before entering the recursive DFS we now explicitly check:
    1. Is the full set already valid?
    2. If not, does removing exactly one item (the violator or any negative contributor on the worst skill) produce a valid set?
      On typical builds this avoids recursion entirely.
  • Branch ordering by weight — candidates inside the DFS are sorted so the highest bonus-sum (best tie-break) is found first, pruning the remaining branches aggressively.
  • Small-n short-circuitn ≤ 1 skips visited-bitset clearing and recursion overhead.

Benchmarks

Benchmark V1 V2 Speedup
FullEquip (mean) 260 ns/op 243 ns/op 1.07×
OneByOne (mean) 19,075 ns/op 4,028 ns/op 4.7×

V2 is now the fastest algorithm on the OneByOne benchmark and retains the top spot on FullEquip.

Correctness

  • All 15 @CombinationTest cases pass for V2.
  • Cascade rule, ordering check, and branching completeness are identical to V1; only the search strategy and data layout changed.

Registration

V2 is registered as a separate class (SubtractiveBnBV2Algorithm) alongside V1, per the bounty instructions.

AI Disclosure

This algorithm was designed and implemented with assistance from an AI coding assistant (Kimi Code CLI). The core mathematical approach (subtractive branch-and-bound with witness-driven removal) was human-directed; performance optimisations (flat arrays, fast paths, branch ordering) were refined iteratively with AI assistance.

Optimisations over V1:
- Flat primitive arrays for req/bonus (better cache locality)
- Fast-path depth-0 and depth-1 search before general DFS
- Branch ordering by weight to find best tie-break first
- Special-case n=0 and n=1 to skip visited clearing and recursion
- Registered alongside V1
@AzaelMew
Copy link
Copy Markdown
Contributor Author

This is same as #9, just fixed to be submitted corrctly.

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.

1 participant