8000 fix: search only stock assignments that keep the separations (#420) by rafatahmed · Pull Request #467 · rafatahmed/Flahax · GitHub
[go: up one dir, main page]

Skip to content

fix: search only stock assignments that keep the separations (#420) - #467

Merged
rafatahmed merged 1 commit into
mainfrom
fix/stock-assignment-pruned-search-420
Dec 3, 2026
Merged

rafatahmed merged 1 commit into
mainfrom
fix/stock-assignment-pruned-search-420

Conversation

@rafatahmed
Copy link
Copy Markdown
Owner

Closes #420

Summary

 plan_stocks
-  for count in 1..tanks
-    for every one of count^products assignments      # all charged to max_assignments
-      skip if a tank is unused or a separation is broken
+  for count in 1..min(tanks, products)
+    place products one at a time, in the same order
+      drop the branch at the first broken separation, or when a tank can no longer be used
       build, assess the mixture, return or keep as fallback

The candidates that remain come out in the same order, so the chosen layout and the mixture model calls do not change. tank_grouping keeps its own search: it orders tanks for the A/B layout, which plan_stocks must not do.

Behaviour that changes

Before After
assignments_evaluated every combination tried, valid or not only layouts that keep the separations and use every tank of the count
max_assignments bounds combinations tried bounds those layouts; products placed are bounded to max_assignments × products
More tanks than products, all layouts rejected could end in stock_search_limit no_stock_assignment

Evidence

  • Before: test_separations_do_not_use_up_the_budget raised DeliveryError: assignment search budget exhausted.
    After: it passes.
Case (one run each, local Windows, Python 3.14) main This branch
20 products, 2 tanks, 1 separation stock_search_limit plan, 1 layout evaluated
16 products, 3 tanks, 3 separations stock_search_limit plan, 1 layout evaluated
29 products, 2 tanks, 1 separation stock_search_limit plan, 1 layout evaluated
  • Old against new on 3,289 random cases (1-7 products, 1-5 tanks, with and without a mixture model, several budgets): no mismatches. 2,560 were identical in plan or error and in mixture model calls; in 729 the old code had run out of budget and the new one made the same calls first.
  • 25 affected test modules and the wheel/sdist verification pass; the tests run for stock_planning.py cover 100% of its statements and branches. The full suite and the strict docs build are left to CI.

Remaining limit

The search is still exponential in the worst case. Three mutually separated products placed last, with 27 free products and 2 tanks, still ends in stock_search_limit, after 3.15 s here (the old code gave up on 29 products in under 1 s). It is not proven infeasible within the budget.

Checked against earlier work

Searched open and closed issues and PRs for stock and tank assignment: #230, #298, #307, #308, #391 and #399 set the A/B layout, qualification and unverified reporting; none of those change. No other PR is open. Part of #437.

Merge Danger

Door: two-way.

Blast Radius: small. plan_stocks only; callers comparing assignments_evaluated with earlier saved values will see smaller numbers.

@rafatahmed rafatahmed added the enhancement New feature or request label Dec 3, 2026
@rafatahmed rafatahmed self-assigned this Dec 3, 2026
@read-the-docs-community
Copy link
Copy Markdown

📖 3 files modified


Preview · build overview · Flahax · built Dec. 3, 2026, 1:36 p.m. UTC

@codecov
codecov Bot commented Dec 3, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (954758f) to head (0587d03).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #467   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          155       155           
  Lines        18305     18327   +22     
  Branches      3706      3708    +2     
=========================================
+ Hits         18305     18327   +22     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@rafatahmed
rafatahmed marked this pull request as ready for review December 3, 2026 14:15
@rafatahmed
rafatahmed merged commit 11a9f83 into main Dec 3, 2026
28 checks passed
@rafatahmed
rafatahmed deleted the fix/stock-assignment-pruned-search-420 branch December 3, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCAL-7: Stock assignment enumerates count^n

1 participant

0