Zelen - Direct MiniZinc Solver backed by Selen
Zelen is a MiniZinc parser and solver that directly translates MiniZinc models to the Selen constraint solver, bypassing FlatZinc compilation. It supports a core subset of MiniZinc including constraint satisfaction and optimization problems.
Features
Variable Types:
- Integer variables with domains:
var <min>..<max>: x - Boolean variables:
var bool: b - Float variables:
var float: f - Variable arrays:
array[1..n] of var int: arr - Parameter arrays with initialization:
array[1..5] of int: costs = [10, 20, 30, 40, 50]
Constraints:
- Arithmetic:
+,-,*,/,%(modulo) - Comparison:
=,!=,<,<=,>,>= - Boolean logic:
not,/\(and),\/(or),->(implication),<-> - Global:
all_different,element,min,max,sum - Aggregation:
forall,exists - Nested forall loops:
forall(i, j in 1..n)(constraint)
Solve Types:
- Satisfaction:
solve satisfy; - Minimize:
solve minimize expr; - Maximize:
solve maximize expr;
Input Formats:
- MiniZinc model files (
.mzn) - Optional data files (
.dzn) - merged with model before parsing
Dependencies
Zelen has minimal dependencies:
| Crate | Purpose | Version |
|---|---|---|
| selen | CSP solver backend | 0.14+ |
| clap | CLI argument parsing | 4.5+ |
Installation
As a Binary
Build from source:
The binary will be at target/release/zelen.
As a Library
Add to your Cargo.toml:
[]
= "0.4"
= "0.14"
Usage
Using as a Library
Parse and solve MiniZinc models from Rust:
use zelen;
Advanced: Access variable information
use Translator;
Command Line
# Solve a MiniZinc model
# Solve with data file
# With options
Command-Line Options
USAGE:
zelen [OPTIONS] <MODEL> [DATA]
ARGS:
<MODEL> MiniZinc model file (.mzn)
<DATA> Optional MiniZinc data file (.dzn)
OPTIONS:
-a, --all-solutions Find all solutions (satisfaction problems)
-n, --num-solutions <N> Stop after N solutions
-i, --intermediate Print intermediate solutions (optimization)
-s, --statistics Print solver statistics
-v, --verbose Verbose output with progress
-t, --time <MS> Time limit in milliseconds
--mem-limit <MB> Memory limit in MB
-h, --help Print help information
-V, --version Print version
Example: 4-Queens
Model file (queens.mzn):
var 1..4: q1;
var 1..4: q2;
var 1..4: q3;
var 1..4: q4;
constraint q1 != q2;
constraint q1 != q3;
constraint q1 != q4;
constraint q2 != q3;
constraint q2 != q4;
constraint q3 != q4;
constraint q1 + 1 != q2;
constraint q2 + 1 != q3;
constraint q3 + 1 != q4;
solve satisfy;
Run:
Output:
q1 = 2;
q2 = 4;
q3 = 1;
q4 = 3;
----------
Examples
The repository includes runnable examples:
# Run an example program (with --release for better performance)
# Run tests
See examples/ directory for source code and examples/models/ for test MiniZinc files.
Implementation Status
Completed Features
- ✅ Variable declarations and arrays
- ✅ Integer, boolean, and float types
- ✅ Arithmetic and comparison operators
- ✅ Boolean logic operators
- ✅ Global constraints:
all_different,element - ✅ Aggregates:
min,max,sum - ✅ Forall loops (single and nested generators)
- ✅ Array initialization with literals
- ✅ Modulo operator
- ✅ Satisfy/Minimize/Maximize
- ✅ Multiple input formats (.mzn and .dzn files)
Not Supported
- ❌ Set operations
- ❌ Complex comprehensions beyond forall
- ❌ Advanced global constraints (cumulative, circuit, etc.)
- ❌ Search annotations
- ❌ Some output predicates
Architecture
MiniZinc Source → Parser → AST → Translator → Selen Model → Selen Solver → Solution
Components:
parser.rs- MiniZinc parser (recursive descent)translator.rs- Converts AST to Selen modelmain.rs- CLI interface with verbose output
Relationship with Selen
Zelen uses Selen v0.14+ as its constraint solver backend. Selen provides the core CSP solving engine, while Zelen adds MiniZinc parsing and direct model translation.