Expand description
Zelen - Direct MiniZinc Constraint Solver
Zelen parses a subset of MiniZinc and translates it directly to the Selen constraint solver, bypassing FlatZinc compilation. This allows you to:
- Parse MiniZinc from strings or files
- Solve directly using a single function call
- Access variable information with variable name to ID mappings
- Use as a library in your Rust projects
§Quick Start
§Simple Usage
use zelen;
let source = r#"
var 1..10: x;
var 1..10: y;
constraint x + y = 15;
solve satisfy;
"#;
// Parse and solve directly
match zelen::solve(source) {
Ok(Ok(solution)) => { /* Found solution! */ },
Ok(Err(_)) => { /* No solution exists */ },
Err(e) => { /* Parse error */ },
}§With Variable Access
use zelen::Translator;
let source = "var 1..10: x; solve satisfy;";
let ast = zelen::parse(source).unwrap();
let model_data = Translator::translate_with_vars(&ast).unwrap();
// Access variables by name
for (name, var_id) in &model_data.int_vars {
// name is available here
let _ = (name, var_id);
}§Supported Features
- Integer, boolean, and float variables
- Variable arrays with initialization
- Arithmetic and comparison operators
- Boolean logic operators
- Global constraints:
all_different,element - Aggregation functions:
min,max,sum,forall,exists - Nested forall loops
- Satisfy, minimize, and maximize objectives
Re-exports§
pub use error::Error;pub use error::Result;pub use lexer::Lexer;pub use parser::Parser;pub use translator::Translator;pub use translator::TranslatedModel;pub use translator::ObjectiveType;pub use selen;pub use ast::*;
Modules§
- ast
- Abstract Syntax Tree for MiniZinc Core Subset
- error
- Error types and reporting for MiniZinc parser
- lexer
- Lexer for MiniZinc Core Subset
- parser
- Parser for MiniZinc Core Subset
- translator
- Translator for MiniZinc Core Subset to Selen
Structs§
- Model
- Solution
- Assignment for decision variables that satisfies all constraints.
- Solver
Config - Configuration for the Selen solver backend
- VarId
- Decision variable handle that is not bound to a specific memory location.
Functions§
- build_
model - Parse and translate MiniZinc source directly to a Selen model
- build_
model_ with_ config - Parse and translate MiniZinc source directly to a Selen model with custom configuration
- load_
dzn_ data - Load and parse a MiniZinc data file (.dzn format)
- parse
- Parse a MiniZinc model from source text into an AST
- solve
- Solve a MiniZinc model and return the solution
- solve_
with_ config - Solve a MiniZinc model with custom solver configuration and return solutions
- translate
- Translate a MiniZinc AST to a Selen model