liveBook · Manning

Domain

As explained in Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

In a constraint-satisfaction problem, a domain is the set of possible values that may be assigned to a variable.

A domain is the set of possible values that may be assigned to a variable in a constraint-satisfaction problem. A CSP pairs variables and domains with constraints that restrict valid combinations. section 3.0

A domain can be represented concretely as an array of values. In a generic Swift CSP, a dictionary maps each variable to its domain, allowing the same search framework to handle different variable and value types. section 3.1

The meaning of a domain depends on the problem being modeled:

  • For meeting scheduling, Mary’s domain might contain 2 P.M., 3 P.M., and 4 P.M.—her available hours. section 3.0
  • For Australian map coloring, every region has the domain red, green, and blue; adjacency constraints eliminate equal neighboring colors. section 3.2
  • For word search, a word’s domain contains possible sequences of grid locations that keep the word within a row, column, or diagonal. section 3.4

Domains during backtracking search

A backtracking solver selects an unassigned variable, reads its domain, and tries each value in turn. It keeps a value when the current assignment is consistent with the relevant constraints, then recursively continues; if every value fails, it returns nil. section 3.1

Figure 3.1. Scheduling problems are a classic application of constraint-satisfaction frameworks.

Use the scheduling diagram to see domains as each participant’s available hours within a complete CSP model. section 3.0

How Classic Computer Science Problems in Swift: Essential techniques for practicing programmers covers it

How deep it goes
Defines domains and stores them in Swift dictionaries, then uses them during recursive value-by-value backtracking.
Examples
Uses meeting hours, map colors, and word-search grid locations as domain values.
What you can do after
Build a CSP by assigning each variable an explicit collection of candidate values for backtracking search.
How it connects
Connects variables and constraints through CSP modeling, backtracking search, binary constraints, and consistency checking.

Also explained in

Compare how 2 books explain domain →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Computer Science Problems in Swift: Essential techniques for practicing programmers. The section links point to the parts of the book it draws on.