Assignment-selection merge algorithms and constraint models
Project description
assignment-selection
Pure Python assignment-selection merge algorithms and constraint models.
The distribution name is assignment-selection; the import package is
assignment_selection. The package owns the pure assignment-selection model:
assignments, source assignments, runtime constraints, candidate scoring, and
solver results.
What It Does
assignment-selection solves finite assignment-selection merge problems. A
problem declares concept ids, source assignments over those concepts, optional
runtime constraints, and a merge operator:
sigma: minimize total weighted distance to the sources.max: minimize the worst weighted distance to unique source assignments.gmax: lexicographically minimize the sorted worst-distance vector.
Candidate assignments are enumerated from observed source values. Constraints can filter admissible candidates, and the solver returns all tied winners plus the sorted scored candidate list.
Model
Assignment
A frozen mapping of concept id to value. Values are copied into an immutable
mapping at construction. value_for(concept_id) returns the value or None if
the concept is absent.
SourceAssignment
One weighted source: a source_id, an assignment, and a weight. The
weight field defaults to 1.0 and scales the distance from this source in
every operator. A weight that is non-finite (nan, inf) or negative is
rejected with ValueError at construction.
Constraint
A runtime filter over admissible candidates:
concept_ids: the tuple of concept ids the constraint ranges over. It must be non-empty and contain no duplicates, or construction raisesValueError.holds: a callable taking anAssignmentand returning a truthy value. A non-callableholdsis rejected withTypeError.description: an optional human-readable label (Noneby default).
When a constraint is checked, holds receives an Assignment scoped to exactly
its declared concept_ids — concepts outside that set are not visible to the
callable. A Problem also rejects constraints (and sources) that reference
concept ids not in the problem's declared concept_ids.
Problem
concept_ids, sources, constraints (default empty), and operator
(default MergeOperator.SIGMA). concept_ids must be non-empty and
duplicate-free.
Result
The value returned by solve:
winners: the tuple of all tied-best admissible assignments. Empty when the problem could not be solved (seereason).scored_candidates: every admissible candidate paired with its score, sorted best-first.admissible_count: the number of candidates that passed all constraints.total_candidate_count: the number of candidates enumerated (the partial count when a ceiling was hit).reason:Noneon success, otherwise a string explaining the empty result.
Example
from assignment_selection import Assignment, MergeOperator, Problem, SourceAssignment, solve
problem = Problem(
concept_ids=("truth_value",),
sources=(
SourceAssignment("s1", Assignment({"truth_value": 10.0})),
SourceAssignment("s2", Assignment({"truth_value": 10.0})),
SourceAssignment("s3", Assignment({"truth_value": 99.0})),
),
operator=MergeOperator.SIGMA,
)
result = solve(problem, max_candidates=1_000)
winner = result.winners[0]
assert winner.values["truth_value"] == 10.0
assert result.reason is None
Contracts
- Assignment values are copied into immutable mappings.
claim_distancenumerically coerces values: a value that can be turned into afloat(including a numeric string) is compared as that number, so"10"and10.0collapse to the same point. Values that cannot be coerced fall back to a 0/1 categorical distance. It is therefore a metric only within a homogeneous value space — all-numeric or all-categorical — not across a mixed one.- Non-finite numeric distances are rejected (
claim_distanceraisesValueError) instead of producing empty winner sets with successful-looking results. solve(..., max_candidates=N)does not raise when the candidate ceiling is breached. It returns aResultwith emptywinnersandreason="candidate enumeration exceeded ceiling of N". It also returns an empty-winnersResultwithreason="no candidate assignments to enumerate"when no candidates could be formed, andreason="no admissible assignments"when candidates exist but every one is filtered out by the constraints. On successreasonisNone.- The low-level
enumerate_candidate_assignments(problem, max_candidates=N)enforces the same ceiling but signals a breach differently: it returns anEnumerationExceededobject (partial_count,max_candidates) rather than aResult.solvetranslates that object into theResultdescribed above. - The package ships a
py.typedmarker for inline type consumers.
References
The merge operators are drawn from the integrity-constraint (IC) belief-merging
literature. Konieczny & Pino-Pérez 2002, Merging Information Under
Constraints, is the direct theoretical basis for the SIGMA / MAX / GMAX
operators (Sigma majority, Max quasi-merging, GMax arbitration). See
papers/index.md for the full reference collection and
notes.
Development
uv sync
uv run pyright
uv run pytest -vv
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file assignment_selection-0.1.0.tar.gz.
File metadata
- Download URL: assignment_selection-0.1.0.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1172ecd255b6adebdf7059346f8d524027336e53c1f189976434ed73b3479587
|
|
| MD5 |
b28bc140fef3f4adae8d8141f1237485
|
|
| BLAKE2b-256 |
33e719cee61984f4252e561443965e5e47d18f132869c5245c5ded67b829fea7
|
File details
Details for the file assignment_selection-0.1.0-py3-none-any.whl.
File metadata
- Download URL: assignment_selection-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63edba76ed2d18eeb0db754454701d8d2f2904ccb2ebe6947a1a34f7dca2da00
|
|
| MD5 |
d45f1d192e476dce8c829adb24e7904c
|
|
| BLAKE2b-256 |
1c8d64fc8b91fa92ab3b925fb0d14db49f9628cd260cebd02d4757cea37698d6
|