Repository navigation
fix(scoring): report matches for grouped and complemented constraints - #262
Merged
Merged
Conversation
Grouped and complemented constraints scored correctly but listed no matches in constraint analysis, so nothing named the entities behind a group's cost. Two defects caused it: - seven of the eight grouped builders never gave their shared terminal an explainer, and SharedOperatorTerminal::get_matches returned nothing without one; - OperatorScorer::evaluate_detailed always returned an empty match list, so every terminal on a compiler-shared grouped node (what #[solverforge_constraints] emits whenever a grouped stream has several terminals) had no matches even where an explainer existed. The shared terminal now requires its rows to implement ExplainRow, which replaces the optional per-builder explainer (SharedOperatorBuilder:: with_explainer is removed) and lets matches come from the rows themselves: - each terminal reports one match per row whose coded weight is not zero, scored at its multiplier and justified by the row's contributors: a group's entities, a complement row's target plus its group, a defaulted complement key by its target alone; - match scores sum to the terminal's score, from a full evaluation before initialization and from the retained rows afterwards; match_count still counts every row. Grouped and complemented builders therefore require Clone + Debug entities, as every ungrouped constraint already did; the projected complement target gains Clone + Debug. OperatorScorerSet::score_for had no caller left and is removed. Closes #261
blackopsrepl
force-pushed
the
fix/grouped-constraint-matches
branch
from
November 13, 2026 20:00
1f8f60f to
4d32fb3
Compare
Collaborator
Author
Zero-regression gate —
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #261.
Cause
There were two defects. The issue names the first.
SharedOperatorTerminal. Without one,get_matchesreturns nothing.OperatorScorer::evaluate_detailedalways returned an empty match list. Every terminal on a compiler-shared grouped node therefore had no matches, even in the one builder (joined_grouped_stream) that did set an explainer.#[solverforge_constraints]creates such a node whenever a grouped stream has more than one terminal.Fix
The shared terminal now requires its rows to implement
ExplainRow. This replaces the per-builder optional explainer:SharedOperatorBuilder::with_explaineris removed, and matches come from the rows themselves. Inoperator_scorer/matches.rs:OperatorTerminal.match_countstill counts every row. The existing complement, projected and weight contracts pin that.API changes:
named()now requireClone + Debugentities, which every ungrouped constraint already required. The projected complement target gains the same bound.OperatorScorerSet::score_forhad no callers left and is removed.public-api.txtis blessed with these removals.Projected streams: projected rows carry no entity, as in every projected constraint today. Projected groups report correct matches and scores, and are justified by their complement target where they have one.
Verification
constraint/tests/grouped_analysis.rs, one test per builder: grouped, grouped join, complemented, cross grouped, cross complemented grouped. Each checks expected matches and justifications, and that the match sum equals the score before initialization, after it, through a retract/insert move and after restoring.[3, 2]) and a disabled terminal.constraint/tests/projected/analysis.rs: projected grouped and projected complemented grouped.tests/group_by_joined.rs: self-join trigroup_bymatches.crates/solverforge/tests/grouped_constraint_analysis.rs: the issue's reproduction through#[solverforge_constraints]andScoreDirector::constraint_analyses(). Onmainthe grouped analysis shows score-1hardwith no matches (assertionleft: 0hard/0soft, right: -1hard/0soft).make pre-releaseandmake examplespass.trybuildpasses afterEmployeeinsolverforge_constraints_projected_complemented.rsgainedClone + Debug.docs/constraints.md(score analysis).