Skip to content

fix(solver): place required assignments through the construction cursor - #285

Merged
blackopsrepl merged 2 commits into
mainfrom
fix/283-required-batch-direct
Nov 30, 2026
Merged

blackopsrepl merged 2 commits into
mainfrom
fix/283-required-batch-direct

Conversation

@blackopsrepl

Copy link
Copy Markdown
Collaborator

Fixes #283.

Problem

The n120w8 INRC-II instances H0_WD0-9-9-4-5-1-0-3 and H1_WD7-2-6-4-5-2-0-2 ended a 1 s solve with all 2844 / 2872 required shifts unassigned.

Required construction committed one dense batch move. That batch placed every directly placeable row outside the construction cursor and outside incremental scoring. Since 3992802 (0.20.4), its pending view scanned every pending row for each query, so the batch was quadratic. It ran past the 1 s limit, and the solve published nothing.

#284 indexed that pending view. Its gate failed sim_d1_misses on assignment_neighborhood and construction_first_fit. This PR reverts that change.

Change

  • Batch removed. Required rows are placed one move at a time by the required cursor and scored incrementally.
  • Cursor carried across placements. The placer cursor keeps the assignment generator through recycle. It refreshes only the rows the placement's candidates touched, drops newly assigned rows from the value degrees, and resumes after the placed row. When a carried generator finds nothing more, it is rebuilt from the solution once, so rows skipped earlier get another pass.
  • Completed-slot probes. Only rows that can be completed at the current solution revision are probed, instead of every row of the group on every placement.
  • Direct values first. A required row tries every value directly (depth 0) before any value with augmenting rematches. Before this, a row whose first value was taken ran a rematch search even when another value was free.
  • fix(solver): index pending assignments by key in the path overlay #284 reverted. The path-overlay index of 9ab0b17 is removed; assignment_path.rs and assignment_path_overlay.rs are back to their 0.31.4 contents.
  • Gate case. assignment_neighborhood now builds its roster directly instead of through a construction solve, so it measures only the neighborhood. It runs 4 iterations per trial (about 60 ms).

Verification

  • Both instances at 1 s (bench NRP adapter at b25039f built against this tree, 2 runs each):
    • H0: 0hard/-224820soft, 2844 required placements in 69 ms.
    • H1: 0hard/-223990soft, 2872 required placements in 75 ms.
    • Batch removed but no cursor carry-over: 2430 and 2469 shifts still unassigned.
  • New tests (tests/construction_resume.rs); each fails with its mechanism disabled:
    • domain reads stay linear in the row count (without carry-over they grow 16×, 67,072 → 1,054,720);
    • a required row takes a free value before a rematch.
  • make lint: exit 0.
  • make test: exit 0.
  • Zero-regression gate: the full gate against v0.31.4 runs on the merged commit. assignment_required constructs a different roster by design now that the batch is gone. For that case only output identity is exempt; speed, allocations and memory are graded as usual.

The neighborhood case built its starting roster with a construction solve,
so the case also ran the construction code under change and its heap layout
moved with it. Build a feasible roster directly instead: shift s of day d
goes to nurse (s + 6d) mod 24, which keeps each nurse on one shift a day and
on the same shift type from day to day.

One iteration enumerates every grouped-scalar family in about 15 ms, so the
case now measures four iterations per trial (about 60 ms) instead of the
default, which brings the full gate back to its usual length.
n120w8 rostering instances (2844 and 2872 required shifts) ended a 1 s solve
with every required shift unassigned (#283). Required construction committed
one dense batch move that placed all directly placeable rows outside the
cursor and outside incremental scoring; after 3992802 its pending view made
that batch quadratic, and it timed out before publishing anything.

Remove the batch. Required rows are placed one move at a time by the required
cursor and scored incrementally, and the cursor no longer redoes whole-problem
work per placement:

- The placer cursor keeps the assignment generator across placements
  (`recycle`), refreshes only the rows the placement's candidates touched,
  drops newly assigned rows from the value degrees and resumes after the
  placed row. A generator that finds nothing more is rebuilt from the
  solution once, so rows skipped earlier get another pass.
- Completed construction slots are probed only for rows that can be completed
  at the current revision instead of every row of the group.
- A required row tries every value directly before any value with augmenting
  rematches, so a row with a free value never pays for a rematch search.

This also reverts the path-overlay index of 9ab0b17, which only served the
batch, and keeps the scanning overlay of 0.31.4.

Both instances now finish feasible at 1 s: H0 0hard/-224820soft (2844
placements in 69 ms), H1 0hard/-223990soft (2872 in 75 ms).

Fixes #283
@blackopsrepl
blackopsrepl merged commit f4cc2fa into main Nov 30, 2026
7 checks passed
@blackopsrepl
blackopsrepl deleted the fix/283-required-batch-direct branch November 30, 2026 21:00
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.

NRP n120w8: 1-second solves leave mandatory shifts unassigned since 0.20.0

1 participant