Skip to content

HeroJJ555/constra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

   _____                _             
  / ____|              | |            
 | |     ___  _ __  ___| |_ _ __ __ _ 
 | |    / _ \| '_ \/ __| __| '__/ _` |
 | |___| (_) | | | \__ \ |_| | | (_| |
  \_____\___/|_| |_|___/\__|_|  \__,_|

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)

Example

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);

What it can do

  • 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)

Solver controls

Constra supports basic solver controls:

const result = solve(model, {
  timeoutMs: 1000,
  maxSteps: 50000,
  debug: true,
});

Diagnostics

Solver results can include:

  • stats
  • diagnostics
  • debug

This makes it easier to inspect search behavior, understand infeasible models, and tune scheduling constraints.

Scheduling constraints

Built-in constraints now include:

  • atMostOne
  • exactlyOne
  • notIn
  • sameValue
  • ifThen

Project Status

Early development - API may change.

Constra is evolving into a practical scheduling engine for TypeScript, not just a theoretical CSP tool.


Author


License

Mozilla Public License Version 2.0