Skip to main content

N-ary constraints

Rules over several cells checked by enumeration (lines, sums, relations). Generated from the comments in the headers by Doxygen and tools/gen_cpp_reference.py; public members only.

nary.hpp​

csrc/nary.hpp

Generic multi-cell ("n-ary") constraints and their consistency engine.

A constraint is a scope of unique cells ("vars") plus a type-specific predicate over positions (positions index vars, so a cell may appear more than once, e.g. a line crossing itself). The engine enumerates assignments consistent with the current domains respecting pairwise distinctness (shared AllDiff groups / neq links / the constraint's own distinct flag) and pair-relation tables between scope cells with bound pruning, and returns per-var supports (generalized arc consistency), the number of consistent assignments, the intersection of their digit sets ("must contain") and whether that digit set is unique.

struct NSpec​

source

input form (from Python dicts)

Fields

  • type int
  • a std::vector< int > — sum/set/table cells; arrow circle
  • segs std::vector< std::vector< int > > — arrow: {line}; equal_sum: segments
  • total int
  • distinct int — -1 auto
  • setkind int — set: 0 = consecutive
  • rows std::vector< std::vector< int > > — table
  • quota std::vector< int > — count: index = digit, -1 = unconstrained
  • line_kind int — >= 0: a line rule (LineKind)
  • def_lines std::vector< int >
  • def_regs std::vector< int > — derived leftovers: the defining lines / regions
  • totals std::vector< int > — sum with an unknown total from this set (incomplete clue); empty = total
  • named bool — table with a rule name (moves coded 6000 + index)
  • offset int — equal_sum: segment sums of (digit - offset)
  • bounds_only bool — sum: derived (BandLogic) brute force propagates bounds only
  • seg_sign std::vector< int > — bounds_only: +1 / -1 per segment (outie cells subtracted); empty = all +1

struct NConstraint​

source

NameWhat it does
nvnumber of distinct cells (variables) of the constraint

Fields

  • type int
  • index int — position in Puzzle::nary_specs (-1: derived from a cage group)
  • group int — cage group it was derived from
  • house int — derived innie/outie region: first house of the union
  • innie int — derived innie/outie region: index into Puzzle::big_innies
  • set_theory bool — derived by build_set_theory (arrows / little killers in the region)
  • outie bool
  • n_cages int
  • vars std::vector< int > — unique cells
  • pvar std::vector< int > — position -> var index
  • total int
  • totals std::vector< int > — incomplete clue: the total is one of these (empty: total)
  • distinct bool
  • arith bool
  • ncircle int — arrow: positions [0, ncircle) are circle digits
  • seg_start std::vector< int > — equal_sum: segment k = [seg_start[k], seg_start[k+1])
  • setkind int
  • arity int
  • named bool — table with a rule name
  • offset int — equal_sum: segment sums of (digit - offset)
  • bounds_only bool — derived sum: bounds propagation in brute force
  • part std::vector< int > — bounds_only: var -> part id (cells of a part are pairwise distinct)
  • parts std::vector< std::vector< int > > — bounds_only: cells per part
  • part_sign std::vector< int > — bounds_only: +1 / -1 per part (empty = all +1)
  • rows std::vector< uint8_t > — table rows over positions
  • quota std::vector< int > — count
  • line_kind int — >= 0: line rule (cells in line order = vars)
  • differ std::vector< uint8_t > — nv*nv
  • rel std::vector< const uint32_t * > — nv*nv: rel_ex(var i -> var j) or null
  • order std::vector< int > — DFS order (vars)
  • shape double

int nv() const​

source

number of distinct cells (variables) of the constraint

struct GacReq​

source

Fields

  • v int
  • varmask uint64_t — some var in mask must take v

struct GacOut​

source

Fields

  • sup uint32_t[64]
  • count pm_long — consistent assignments (capped when !complete)
  • complete bool — enumeration finished within budget
  • set_unique bool — all assignments use the same digit set
  • must uint32_t — digits in every assignment (valid if complete)
  • any bool