_____ _
/ ____| | |
| | ___ _ __ ___| |_ _ __ __ _
| | / _ \| '_ \/ __| __| '__/ _` |
| |___| (_) | | | \__ \ |_| | | (_| |
\_____\___/|_| |_|___/\__|_| \__,_|
TypeScript constraint solver for scheduling and allocation problems.
Constra is a lightweight constraint solver for TypeScript, designed to model and solve real-world problems like scheduling, timetables, and resource allocation.
It focuses on:
- clean and readable API
- deterministic solving
- explainable results (not just answers)
import { createModel, domain, solve } from "@herojj555/constra";
import { noOverlap } from "@herojj555/constra/stdlib";
const model = createModel();
const a = model.variable("a", domain.from([1, 2]));
const b = model.variable("b", domain.from([1, 2]));
model.add(noOverlap([a, b]));
const result = solve(model);
console.log(result);- define decision variables with finite domains
- express constraints (
allDifferent,atMostOne,exactlyOne, etc.) - combine hard and soft constraints
- solve using backtracking + MRV heuristic
- return explainable results (violations, penalties, reasoning)
Constra supports basic solver controls:
const result = solve(model, {
timeoutMs: 1000,
maxSteps: 50000,
debug: true,
});Solver results can include:
statsdiagnosticsdebug
This makes it easier to inspect search behavior, understand infeasible models, and tune scheduling constraints.
Built-in constraints now include:
atMostOneexactlyOnenotInsameValueifThen
Early development - API may change.
Constra is evolving into a practical scheduling engine for TypeScript, not just a theoretical CSP tool.
Mozilla Public License Version 2.0