AI Glossary / Graphs and symbolic AI / Beginner
Unary constraint
Definition
A unary constraint is a rule that restricts the allowed values of one variable in a constraint satisfaction problem. For example, if a meeting's start time must be after 10 a.m., that restriction concerns the start-time variable alone.
What it means
A constraint satisfaction problem represents choices as variables, possible choices as domains, and requirements as constraints. Unary describes the number of variables involved in a rule, not the number of values that the rule permits.
The rule X must be red is unary, and so is X must be red or blue. Both concern only X. By contrast, X must differ from Y connects two variables and is binary. A rule can contain several conditions and remain unary if all those conditions refer to the same variable and fixed information.
This distinction helps a solver remove individually impossible choices before considering interactions. It also helps people translate business requirements into a model that says exactly which decisions depend on which others.
How it works
For an explicitly listed finite domain, the solver checks each candidate value against the unary requirements and removes values that fail. If X has domain {1, 2, 3, 4} and must exceed two, its filtered domain is {3, 4}.
When several unary constraints apply to X, a value must satisfy all of them. The resulting domain is their intersection with the original domain. If no values remain, the model cannot have a solution under those requirements. If one value remains, X is forced, although other variables may still make the whole problem impossible.
After filtering, the solver must still enforce constraints between variables. Eliminating the explicit unary rule by incorporating it into a domain does not eliminate its meaning. For continuous or very large domains, restrictions may be represented symbolically rather than by enumerating every possible value.
Three practical examples
- A room-selection variable excludes rooms whose fixed capacity is below a known attendance requirement.
- A delivery-date variable permits only dates within a customer's specified window.
- A product-color variable permits only the colors available for the selected, fixed product model.
Think of it this way
Think of checking individual ingredients against a recipe's permitted-ingredient list before deciding how to combine them. An ingredient can be rejected on its own without examining a pairing.
Passing that individual check does not guarantee a successful combination. Similarly, values that survive unary filtering may conflict with each other through the remaining constraints. The analogy concerns independent eligibility, not nutritional or culinary judgment.
Worked example
Filtering before checking a relationship
In an invented scheduling model, X and Y are appointment slots with initial domains {9, 10, 11, 12}. X must be at least 10 and must not equal 11. These are two unary constraints, leaving X in {10, 12}. Y must be no later than 11, leaving Y in {9, 10, 11}.
Before filtering, the two variables have 4 × 4 = 16 candidate assignments. After filtering, they have 2 × 3 = 6. This is a count of combinations, not a measured solver speedup.
Now add the binary requirement X < Y. If X is 10, only Y = 11 works. If X is 12, no remaining Y works. The single solution is therefore X = 10 and Y = 11. Unary filtering simplified the problem, but the relationship between the appointments was essential to finding the solution.
Illustrative case study
The fictional WillowBookings team builds a room-assignment assistant. It first removes rooms that fail fixed accessibility and capacity requirements for each event. The remaining rooms become the domains of the event variables.
An early prototype then assigns every event its first eligible room. Two simultaneous events receive the same room. The team adds constraints between overlapping events, making their room assignments different.
The example shows why eligibility filtering and conflict checking solve different parts of the problem. It reports no actual deployment results. Correct unary rules improve the model, but do not replace the relationships needed to produce a valid schedule.
Common misconceptions and mistakes
- Unary means only one value is allowed. A unary rule can permit many values; it concerns one variable.
- Once unary constraints are satisfied, the problem is solved. Relationships among variables may still rule out every complete assignment.
- Removing a unary rule during preprocessing discards a requirement. Correct domain filtering preserves the requirement by removing all violating values.
Business use
Unary constraints make fixed eligibility requirements easy to inspect. They are useful in configuration, scheduling, assignment and planning systems where many candidates can be excluded independently.
Check whether information treated as fixed is actually another decision. Room capacity compared with a fixed attendance number can filter a room variable directly. If attendance is also a variable that the system chooses, the relationship involves both decisions and is no longer simply unary in that representation. Keep a clear explanation of domain reductions so users can understand why an option disappeared and whether a changed requirement should restore it.
People also ask
Can one variable have several unary constraints?
Yes. Its allowed values must satisfy all of them.
Does an empty filtered domain prove there is no solution?
Yes, for the current model and requirements, because that variable has no permitted value.
Is a preference for cheaper options a unary constraint?
It may be represented as a unary cost or soft constraint, but that differs from the hard permission rules described here.
Check your understanding
X has domain {red, green, blue}. The rules say X cannot be green and X must differ from Y. Which rule is unary?
Answer: X cannot be green is unary. X must differ from Y is binary because it connects two variables.
Related terms
- Constraint satisfaction problem
- Variable
- Domain
- Binary constraint
- Constraint propagation
- node consistency
- arc consistency
- soft constraint
Learn next
Read domains and binary constraints. Write down the variables in a small scheduling problem, then separate rules that filter one variable from rules that connect several decisions.
More in Graphs and symbolic AI
- Type signature - A type signature specifies the types of inputs and outputs associated with a function or operation.
- UCB1 - UCB1 is a multi-armed bandit algorithm that selects an action using its average observed reward plus an exploration bonus.
- UCT - UCT is a method for guiding Monte Carlo tree search by applying upper-confidence-bound ideas at decision nodes.
- Łukasiewicz logic - Łukasiewicz logic is a family of many-valued logics associated with Jan Łukasiewicz.
- Unbounded cost search - Unbounded-cost search seeks a valid solution without requiring its cost to fall below a specified threshold or within a specified factor of the best...
- Undirected graph - An undirected graph is a collection of nodes joined by edges that have no orientation.
Sources
Stuart Russell and Peter Norvig, Artificial Intelligence: A Modern Approach, author-hosted constraint satisfaction chapter, discussion of unary constraints and domain preprocessing: https://aima.cs.berkeley.edu/4th-ed/pdfs/newchap05.pdf
The relevant original explanation was read. The appointment calculation and fictional booking case are original teaching examples. Their combination counts describe this small model and do not establish a general runtime improvement.
Previous: Unary coding Next: Unavoidable Redundancy