Cardinality: one-sided bounds are legal (min-only / max-only) - #139
Merged
Conversation
The schema required BOTH min and max, so the natural one-sided statement
("fund at least 20", "at most 24") could not be typed and agents had to
invent the missing bound. min and max are now each optional (absent =
unbounded on that side; a row with neither is rejected), resolved through
merged_cardinality as tuple[int|None, int|None] and honored end to end:
NSGA encoding keeps its defaults on the absent side (search floor
included), the exact MILP builders (HiGHS + cuOpt) add only the stated
row, validate/infeasibility/audit-negation reason per-side, binding
analytics skip an absent bound, and one shared renderer
(cardinality_range_str) keeps every prose echo free of 'None'.
problem_framing schema reference now tells agents to state only the bound
the user gave.
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.
Defect
The
cardinalityconstraint schema required BOTHminandmax, so the natural one-sided user statement — "fund at least 20", "at most 24 assets" — could not be typed as written. Agents had to invent the missing bound (a fabricated floor or an options-count cap), putting a number in the model the user never stated.Root cause
CardinalityConstraintdeclaredmin: int; max: int(both required), and every consumer downstream —merged_cardinality, the validators, the NSGA encoding, the exact MILP builders, the audit negation, the binding analytics, the prose renderers — assumed both bounds present.Fix
engine/models.py):minandmaxare each optional; an absent bound is unbounded on that side. A row with neither bound states no rule and is rejected at the schema.engine/optimizer.py):merged_cardinalityreturnstuple[int|None, int|None]— each side merged over the rows that state it._parse_constraintskeeps its defaults on an absent side, so a max-only row preserves the EA's never-propose-empty search floor exactly as no-row does.solvers/highs_backend.py,solvers/cuopt_backend.py,solvers/_scalarization.py): the MILP builders add only the stated bound row; the empty-intersection decline fires only when both sides exist.engine/metrics.py,engine/explorer.py) each guard the absent side.optimizer.cardinality_range_strserves validate's echo, the constraints-merged note, and the formulation card, so a one-sided row renders "select ≥20" / "select ≤24" and never "select None–20".skills/problem_framing/references/schemas.mdnow says each bound is optional — state only the one the user gave, never invent the other. architecture.md's model/update row notes the one-sided form.Tests
New
tests/test_cardinality_one_sided.py(25 tests), written failing against main's behavior first: schema accepts min-only/max-only and rejects a bound-less row; resolver + validation per-side; NSGA solve respects each one-sided bound; exact HiGHS overlay respects each; MILP data carries(2, None)/(None, 3); audit negation one-sided + vacuous decline; server formatting and merge note; binding analytics no longer TypeError.Full suite: 1072 passed, 2 skipped (was 1047 before the new file).