UNPKG

dancing-links

Version:

Fastest JS solver for exact cover problems using Dancing Links

48 lines (47 loc) 1.82 kB
/** * Template for reusable constraint sets. * * Use this when you want to solve multiple similar problems that share * common constraint patterns. * * @template T The type of data associated with constraints * @template Mode Either 'simple' or 'complex' solver mode * * @example * ```typescript * const template = dlx.createSolverTemplate({ columns: 3 }) * template.addSparseConstraint('common', [0, 1]) * * const solver1 = template.createSolver() * solver1.addSparseConstraint('specific1', [2]) * * const solver2 = template.createSolver() * solver2.addSparseConstraint('specific2', [1, 2]) * ``` */ import { ConstraintRow, SolverMode, ConstraintHandler, SparseColumnIndices, BinaryColumnValues, SparseConstraintBatch, BinaryConstraintBatch } from '../types/interfaces.js'; import { ProblemSolver } from './solver.js'; export declare class SolverTemplate<T, Mode extends SolverMode> { private handler; constructor(handler: ConstraintHandler<T, Mode>); validateConstraints(): this; addSparseConstraint(data: T, columnIndices: SparseColumnIndices<Mode>): this; addSparseConstraints(constraints: SparseConstraintBatch<T, Mode>): this; addBinaryConstraint(data: T, columnValues: BinaryColumnValues<Mode>): this; addBinaryConstraints(constraints: BinaryConstraintBatch<T, Mode>): this; addRow(row: ConstraintRow<T>): this; addRows(rows: ConstraintRow<T>[]): this; /** * Create a new solver instance with this template's constraints pre-loaded. * * @returns New problem solver with template constraints * * @example * ```typescript * const solver = template.createSolver() * solver.addSparseConstraint('additional', [2]) * const solutions = solver.findAll() * ``` */ createSolver(): ProblemSolver<T, Mode>; }